From 577fb4b3190792b08cfec2d1f01675a02010dae8 Mon Sep 17 00:00:00 2001 From: Jan Szumiec Date: Thu, 3 Mar 2011 23:20:07 +0100 Subject: [PATCH] Initial version --- plugins/other/beanstalkd | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 plugins/other/beanstalkd diff --git a/plugins/other/beanstalkd b/plugins/other/beanstalkd new file mode 100755 index 00000000..d1f9a669 --- /dev/null +++ b/plugins/other/beanstalkd @@ -0,0 +1,52 @@ +#!/usr/bin/python + +import sys, re +from beanstalk import serverconn, protohandler + +# Temporary workaround until my patch is merged. +if not protohandler._namematch.match('ABZDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+/;.$_()'): + protohandler._namematch = re.compile(r'^[a-zA-Z0-9+\(\)/;.$_][a-zA-Z0-9+\(\)/;.$_-]{0,199}$') + +STATES = ['ready', 'reserved', 'urgent', 'delayed', 'buried'] + +def connect(host='localhost', port=11300): + return serverconn.ServerConn(host, port) + +def config(): + c = connect() + tubes = c.list_tubes()['data'] + print_config(tubes) + +def print_config(tubes, graph_title='Beanstalkd jobs', graph_vlabel='count'): + for tube in tubes: + print 'multigraph job_count_' + tube + print 'graph_title %s (%s)' % (graph_title, tube,) + print 'graph_order ' + ' '.join(STATES) + print 'graph_vlabel ' + graph_vlabel + for state in STATES: + print '%s.label %s' % (state, state,) + print + +def run(): + c = connect() + tubes = c.list_tubes()['data'] + print_values(tubes, c) + +def print_values(tubes, c): + for tube in tubes: + print 'multigraph job_count_' + tube + stats = c.stats_tube(tube)['data'] + for state in STATES: + key = 'current-jobs-' + state + value = stats[key] + print '%s.value %d' % (state, value,) + print + +def main(): + if len(sys.argv) > 1 and sys.argv[1] == "config": + config() + else: + run() + +if __name__ == "__main__": + main()