root / plugins / other / beanstalkd @ a7139bca
Historique | Voir | Annoter | Télécharger (1,49 ko)
| 1 |
#!/usr/bin/env python |
|---|---|
| 2 |
|
| 3 |
import sys, re |
| 4 |
from beanstalk import serverconn, protohandler |
| 5 |
|
| 6 |
# Temporary workaround until my patch is merged. |
| 7 |
if not protohandler._namematch.match('ABZDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+/;.$_()'):
|
| 8 |
protohandler._namematch = re.compile(r'^[a-zA-Z0-9+\(\)/;.$_][a-zA-Z0-9+\(\)/;.$_-]{0,199}$')
|
| 9 |
|
| 10 |
STATES = ['ready', 'reserved', 'urgent', 'delayed', 'buried'] |
| 11 |
|
| 12 |
def connect(host='localhost', port=11300): |
| 13 |
return serverconn.ServerConn(host, port) |
| 14 |
|
| 15 |
def config(): |
| 16 |
c = connect() |
| 17 |
tubes = c.list_tubes()['data'] |
| 18 |
print_config(tubes) |
| 19 |
|
| 20 |
def print_config(tubes, graph_title='Beanstalkd jobs', graph_vlabel='count'): |
| 21 |
for tube in tubes: |
| 22 |
print 'multigraph job_count_' + tube |
| 23 |
print 'graph_title %s (%s)' % (graph_title, tube,) |
| 24 |
print 'graph_order ' + ' '.join(STATES) |
| 25 |
print 'graph_vlabel ' + graph_vlabel |
| 26 |
for state in STATES: |
| 27 |
print '%s.label %s' % (state, state,) |
| 28 |
|
| 29 |
|
| 30 |
def run(): |
| 31 |
c = connect() |
| 32 |
tubes = c.list_tubes()['data'] |
| 33 |
print_values(tubes, c) |
| 34 |
|
| 35 |
def print_values(tubes, c): |
| 36 |
for tube in tubes: |
| 37 |
print 'multigraph job_count_' + tube |
| 38 |
stats = c.stats_tube(tube)['data'] |
| 39 |
for state in STATES: |
| 40 |
key = 'current-jobs-' + state |
| 41 |
value = stats[key] |
| 42 |
print '%s.value %d' % (state, value,) |
| 43 |
|
| 44 |
|
| 45 |
def main(): |
| 46 |
if len(sys.argv) > 1 and sys.argv[1] == "config": |
| 47 |
config() |
| 48 |
else: |
| 49 |
run() |
| 50 |
|
| 51 |
if __name__ == "__main__": |
| 52 |
main() |
