Révision b7d577ce
Renamed plugins to their actual names
| plugins/celery/celery_tasks | ||
|---|---|---|
| 1 | 1 |
#!/usr/bin/env python |
| 2 |
|
|
| 2 | 3 |
"""=cut |
| 3 | 4 |
=head1 NAME |
| 4 | 5 |
|
| 5 |
celery_tasks_states - Munin plugin to monitor the number of Celery tasks in each state.
|
|
| 6 |
celery_tasks - Munin plugin to monitor the number of Celery tasks with specified names.
|
|
| 6 | 7 |
|
| 7 | 8 |
=head1 REQUIREMENTS |
| 8 | 9 |
|
| ... | ... | |
| 16 | 17 |
|
| 17 | 18 |
Default configuration: |
| 18 | 19 |
|
| 19 |
[celery_tasks_states] |
|
| 20 |
env.api_url http://localhost:8989 |
|
| 21 |
env.workers all |
|
| 22 |
|
|
| 23 |
If workers variable is not set or set to "all", task number for all the workers is monitored. |
|
| 20 |
None |
|
| 24 | 21 |
|
| 25 |
You can optionally set the workers variable to the string of hostnames you want to monitor separated by a comma.
|
|
| 22 |
You must set the name of at least one task you want to monitor (multiple names are separated by a comma).
|
|
| 26 | 23 |
|
| 27 | 24 |
For example: |
| 28 | 25 |
|
| 29 | 26 |
[celery_tasks] |
| 30 |
env.workers localhost,foo.bar.net,bar.foo.net
|
|
| 27 |
env.tasks myapp.tasks.SendEmailTask,myapp2.tasks.FetchUserDataTask
|
|
| 31 | 28 |
|
| 32 |
This would only monitor the number of tasks for the workers with the hostnames "localhost", "foo.bar.net" and "bar.foo.net"
|
|
| 29 |
This would monitor the number of task for a task with name "myapp.tasks.SendEmailTask" and "myapp2.tasks.FetchUserDataTask".
|
|
| 33 | 30 |
|
| 34 | 31 |
=head1 MAGIC MARKERS |
| 35 | 32 |
|
| ... | ... | |
| 91 | 88 |
print 'Could not connect to the celerymon webserver' |
| 92 | 89 |
sys.exit(-1) |
| 93 | 90 |
|
| 94 |
def clean_state_name(state_name):
|
|
| 95 |
return state_name.lower()
|
|
| 91 |
def clean_task_name(task_name):
|
|
| 92 |
return task_name.replace('.', '_')
|
|
| 96 | 93 |
|
| 97 | 94 |
# Config |
| 98 |
def print_config(workers = None): |
|
| 99 |
if workers: |
|
| 100 |
print 'graph_title Celery tasks in each state [workers = %s]' % (', ' . join(workers))
|
|
| 101 |
else: |
|
| 102 |
print 'graph_title Celery tasks in each state' |
|
| 95 |
def print_config(task_names): |
|
| 96 |
print 'graph_title Celery tasks' |
|
| 103 | 97 |
print 'graph_args --lower-limit 0' |
| 104 | 98 |
print 'graph_scale no' |
| 105 | 99 |
print 'graph_vlabel tasks per ${graph_period}'
|
| 106 | 100 |
print 'graph_category celery' |
| 107 | 101 |
|
| 108 |
for name in TASK_STATES: |
|
| 109 |
name = clean_state_name(name) |
|
| 110 |
print '%s.label %s' % (name, name) |
|
| 111 |
print '%s.type DERIVE' % (name) |
|
| 112 |
print '%s.min 0' % (name) |
|
| 113 |
print '%s.info number of %s tasks' % (name, name) |
|
| 114 |
|
|
| 115 |
# Values |
|
| 116 |
def print_values(workers = None, api_url = None): |
|
| 117 |
data = get_data('tasks', api_url)
|
|
| 118 |
|
|
| 119 |
counters = dict([(key, 0) for key in TASK_STATES]) |
|
| 120 |
for task_name, task_data in data: |
|
| 121 |
state = task_data['state'] |
|
| 122 |
hostname = task_data['worker']['hostname'] |
|
| 123 |
|
|
| 124 |
if workers and hostname not in workers: |
|
| 125 |
continue |
|
| 102 |
for name in task_names: |
|
| 103 |
print '%s.label %s' % (clean_task_name(name), name) |
|
| 104 |
print '%s.type DERIVE' % (clean_task_name(name)) |
|
| 105 |
print '%s.min 0' % (clean_task_name(name)) |
|
| 106 |
print '%s.info number of %s tasks' % (clean_task_name(name), name) |
|
| 126 | 107 |
|
| 127 |
counters[state] += 1 |
|
| 128 |
|
|
| 129 |
for name in TASK_STATES: |
|
| 130 |
name_cleaned = clean_state_name(name) |
|
| 131 |
value = counters[name] |
|
| 132 |
print '%s.value %d' % (name_cleaned, value) |
|
| 108 |
# Values |
|
| 109 |
def print_values(task_names = None, api_url = None): |
|
| 110 |
for task_name in task_names: |
|
| 111 |
count = len(get_data('task_details', api_url, task_name))
|
|
| 112 |
print '%s.value %d' % (clean_task_name(task_name), count) |
|
| 133 | 113 |
|
| 134 | 114 |
if __name__ == '__main__': |
| 135 |
workers = os.environ.get('workers', 'all')
|
|
| 115 |
task_names = os.environ.get('tasks', None)
|
|
| 136 | 116 |
api_url = os.environ.get('api_url', API_URL)
|
| 137 | 117 |
|
| 138 | 118 |
check_web_server_status(api_url) |
| 139 | 119 |
|
| 140 |
if workers in [None, '', 'all']: |
|
| 141 |
workers = None |
|
| 142 |
else: |
|
| 143 |
workers = workers.split(',')
|
|
| 120 |
if not task_names: |
|
| 121 |
print 'You need to define at least one task name' |
|
| 122 |
sys.exit(-1) |
|
| 123 |
|
|
| 124 |
task_names = task_names.split(',')
|
|
| 144 | 125 |
|
| 145 | 126 |
if len(sys.argv) > 1: |
| 146 | 127 |
if sys.argv[1] == 'config': |
| 147 |
print_config(workers)
|
|
| 128 |
print_config(task_names)
|
|
| 148 | 129 |
elif sys.argv[1] == 'autoconf': |
| 149 | 130 |
print 'yes' |
| 150 | 131 |
else: |
| 151 |
print_values(workers, api_url) |
|
| 152 |
|
|
| 132 |
print_values(task_names, api_url) |
|
| 133 |
|
|
| plugins/celery/celery_tasks_states | ||
|---|---|---|
| 1 | 1 |
#!/usr/bin/env python |
| 2 |
|
|
| 3 | 2 |
"""=cut |
| 4 | 3 |
=head1 NAME |
| 5 | 4 |
|
| 6 |
celery_tasks - Munin plugin to monitor the number of Celery tasks with specified names.
|
|
| 5 |
celery_tasks_states - Munin plugin to monitor the number of Celery tasks in each state.
|
|
| 7 | 6 |
|
| 8 | 7 |
=head1 REQUIREMENTS |
| 9 | 8 |
|
| ... | ... | |
| 17 | 16 |
|
| 18 | 17 |
Default configuration: |
| 19 | 18 |
|
| 20 |
None |
|
| 19 |
[celery_tasks_states] |
|
| 20 |
env.api_url http://localhost:8989 |
|
| 21 |
env.workers all |
|
| 22 |
|
|
| 23 |
If workers variable is not set or set to "all", task number for all the workers is monitored. |
|
| 21 | 24 |
|
| 22 |
You must set the name of at least one task you want to monitor (multiple names are separated by a comma).
|
|
| 25 |
You can optionally set the workers variable to the string of hostnames you want to monitor separated by a comma.
|
|
| 23 | 26 |
|
| 24 | 27 |
For example: |
| 25 | 28 |
|
| 26 | 29 |
[celery_tasks] |
| 27 |
env.tasks myapp.tasks.SendEmailTask,myapp2.tasks.FetchUserDataTask
|
|
| 30 |
env.workers localhost,foo.bar.net,bar.foo.net
|
|
| 28 | 31 |
|
| 29 |
This would monitor the number of task for a task with name "myapp.tasks.SendEmailTask" and "myapp2.tasks.FetchUserDataTask".
|
|
| 32 |
This would only monitor the number of tasks for the workers with the hostnames "localhost", "foo.bar.net" and "bar.foo.net"
|
|
| 30 | 33 |
|
| 31 | 34 |
=head1 MAGIC MARKERS |
| 32 | 35 |
|
| ... | ... | |
| 88 | 91 |
print 'Could not connect to the celerymon webserver' |
| 89 | 92 |
sys.exit(-1) |
| 90 | 93 |
|
| 91 |
def clean_task_name(task_name):
|
|
| 92 |
return task_name.replace('.', '_')
|
|
| 94 |
def clean_state_name(state_name):
|
|
| 95 |
return state_name.lower()
|
|
| 93 | 96 |
|
| 94 | 97 |
# Config |
| 95 |
def print_config(task_names): |
|
| 96 |
print 'graph_title Celery tasks' |
|
| 98 |
def print_config(workers = None): |
|
| 99 |
if workers: |
|
| 100 |
print 'graph_title Celery tasks in each state [workers = %s]' % (', ' . join(workers))
|
|
| 101 |
else: |
|
| 102 |
print 'graph_title Celery tasks in each state' |
|
| 97 | 103 |
print 'graph_args --lower-limit 0' |
| 98 | 104 |
print 'graph_scale no' |
| 99 | 105 |
print 'graph_vlabel tasks per ${graph_period}'
|
| 100 | 106 |
print 'graph_category celery' |
| 101 | 107 |
|
| 102 |
for name in task_names: |
|
| 103 |
print '%s.label %s' % (clean_task_name(name), name) |
|
| 104 |
print '%s.type DERIVE' % (clean_task_name(name)) |
|
| 105 |
print '%s.min 0' % (clean_task_name(name)) |
|
| 106 |
print '%s.info number of %s tasks' % (clean_task_name(name), name) |
|
| 107 |
|
|
| 108 |
for name in TASK_STATES: |
|
| 109 |
name = clean_state_name(name) |
|
| 110 |
print '%s.label %s' % (name, name) |
|
| 111 |
print '%s.type DERIVE' % (name) |
|
| 112 |
print '%s.min 0' % (name) |
|
| 113 |
print '%s.info number of %s tasks' % (name, name) |
|
| 114 |
|
|
| 108 | 115 |
# Values |
| 109 |
def print_values(task_names = None, api_url = None): |
|
| 110 |
for task_name in task_names: |
|
| 111 |
count = len(get_data('task_details', api_url, task_name))
|
|
| 112 |
print '%s.value %d' % (clean_task_name(task_name), count) |
|
| 116 |
def print_values(workers = None, api_url = None): |
|
| 117 |
data = get_data('tasks', api_url)
|
|
| 118 |
|
|
| 119 |
counters = dict([(key, 0) for key in TASK_STATES]) |
|
| 120 |
for task_name, task_data in data: |
|
| 121 |
state = task_data['state'] |
|
| 122 |
hostname = task_data['worker']['hostname'] |
|
| 123 |
|
|
| 124 |
if workers and hostname not in workers: |
|
| 125 |
continue |
|
| 126 |
|
|
| 127 |
counters[state] += 1 |
|
| 128 |
|
|
| 129 |
for name in TASK_STATES: |
|
| 130 |
name_cleaned = clean_state_name(name) |
|
| 131 |
value = counters[name] |
|
| 132 |
print '%s.value %d' % (name_cleaned, value) |
|
| 113 | 133 |
|
| 114 | 134 |
if __name__ == '__main__': |
| 115 |
task_names = os.environ.get('tasks', None)
|
|
| 135 |
workers = os.environ.get('workers', 'all')
|
|
| 116 | 136 |
api_url = os.environ.get('api_url', API_URL)
|
| 117 | 137 |
|
| 118 | 138 |
check_web_server_status(api_url) |
| 119 | 139 |
|
| 120 |
if not task_names: |
|
| 121 |
print 'You need to define at least one task name' |
|
| 122 |
sys.exit(-1) |
|
| 123 |
|
|
| 124 |
task_names = task_names.split(',')
|
|
| 140 |
if workers in [None, '', 'all']: |
|
| 141 |
workers = None |
|
| 142 |
else: |
|
| 143 |
workers = workers.split(',')
|
|
| 125 | 144 |
|
| 126 | 145 |
if len(sys.argv) > 1: |
| 127 | 146 |
if sys.argv[1] == 'config': |
| 128 |
print_config(task_names)
|
|
| 147 |
print_config(workers)
|
|
| 129 | 148 |
elif sys.argv[1] == 'autoconf': |
| 130 | 149 |
print 'yes' |
| 131 | 150 |
else: |
| 132 |
print_values(task_names, api_url) |
|
| 133 |
|
|
| 151 |
print_values(workers, api_url) |
|
| 152 |
|
|
Formats disponibles : Unified diff