From adb1560bc588d6013338e3190635a63650c97bac Mon Sep 17 00:00:00 2001 From: Stephen Holiday Date: Sun, 12 Dec 2010 03:37:03 +0800 Subject: [PATCH] Add metrics for individual tubes --- beanstalk/README.mkdn | 12 ++- beanstalk/conf.d/beanstalk.conf | 104 ++++++++++++++++---------- beanstalk/python_modules/beanstalk.py | 65 +++++++++++++++- 3 files changed, 138 insertions(+), 43 deletions(-) diff --git a/beanstalk/README.mkdn b/beanstalk/README.mkdn index 88fb766d..f42015b7 100644 --- a/beanstalk/README.mkdn +++ b/beanstalk/README.mkdn @@ -15,7 +15,17 @@ This module connects to a [beanstalkd](http://kr.github.com/beanstalkd/) instanc * current-waiting * job-timeouts * cmd-bury + + In addition is grabs the following metrics about individual tubes: + + * total-jobs + * current-watching + * current-jobs-buried + * current-jobs-ready + * current-waiting + + It should be fairly easy to add a custom metric ## AUTHOR -Stephen Holiday \ No newline at end of file +[Stephen Holiday](http://stephenholiday.com) \ No newline at end of file diff --git a/beanstalk/conf.d/beanstalk.conf b/beanstalk/conf.d/beanstalk.conf index 67e57306..658b8e45 100644 --- a/beanstalk/conf.d/beanstalk.conf +++ b/beanstalk/conf.d/beanstalk.conf @@ -5,48 +5,72 @@ modules { } } collection_group { - collect_every = 20 - time_threshold = 90 - metric { + collect_every = 20 + time_threshold = 90 + metric { name = "current-connections" title = "Number of Current Connections to Beanstalkd" value_threshold = 0 - } - metric { - name = "total-jobs" - title = "Number of Beanstalkd Jobs" - value_threshold = 0 - } - metric { - name = "current-jobs-ready" - title = "Number of Beanstalkd Jobs 'ready'" - value_threshold = 0 - } - metric { - name = "current-jobs-buried" - title = "Number of Beanstalkd Jobs 'buried'" - value_threshold = 0 - } - - metric { - name = "current-jobs-delayed" - title = "Number of Beanstalkd Jobs 'delayed'" - value_threshold = 0 - } - metric { - name = "current-waiting" - title = "Number of Beanstalkd Jobs 'waiting'" - value_threshold = 0 - } + } + metric { + name = "total-jobs" + title = "Number of Beanstalkd Jobs" + value_threshold = 0 + } + metric { + name = "current-jobs-ready" + title = "Number of Beanstalkd Jobs 'ready'" + value_threshold = 0 + } + metric { + name = "current-jobs-buried" + title = "Number of Beanstalkd Jobs 'buried'" + value_threshold = 0 + } + metric { + name = "current-jobs-delayed" + title = "Number of Beanstalkd Jobs 'delayed'" + value_threshold = 0 + } + metric { + name = "current-waiting" + title = "Number of Beanstalkd Jobs 'waiting'" + value_threshold = 0 + } + metric { + name = "job-timeouts" + title = "Number of Beanstalkd Jobs Timeouts" + value_threshold = 0 + } + metric { + name = "cmd-bury" + title = "Number of Beanstalkd Burries" + value_threshold = 0 + } + metric { + name = "default_total-jobs" + title = "default Number of Beanstalkd Jobs" + value_threshold = 0 + } + metric { + name = "default_current-watching" + title = "default Current Watchers" + value_threshold = 0 + } + metric { + name = "default_current-jobs-buried" + title = "default Current Number of Jobs Burried" + value_threshold = 0 + } - metric { - name = "job-timeouts" - title = "Number of Beanstalkd Jobs Timeouts" - value_threshold = 0 - } - metric { - name = "cmd-bury" - title = "Number of Beanstalkd Burries" - value_threshold = 0 - } + metric { + name = "default_current-jobs-ready" + title = "default Current Jobs Ready" + value_threshold = 0 + } + metric { + name = "default_current-waiting" + title = "default Current Number of Jobs Waiting" + value_threshold = 0 + } } diff --git a/beanstalk/python_modules/beanstalk.py b/beanstalk/python_modules/beanstalk.py index 3e5aec21..b0b1ebc7 100644 --- a/beanstalk/python_modules/beanstalk.py +++ b/beanstalk/python_modules/beanstalk.py @@ -2,10 +2,16 @@ # -*- coding: utf-8 -*- import beanstalkc +HOST='localhost' +PORT=14711 def stat_handler(name): - bean=beanstalkc.Connection(host='localhost',port=14711) + bean=beanstalkc.Connection(host=HOST,port=PORT) return bean.stats()[name] +def tube_stat_handler(name): + bean=beanstalkc.Connection(host=HOST,port=PORT) + return bean.stats_tube(name.split('_')[0])[name.split('_')[1]] + def metric_init(params): global descriptors @@ -82,7 +88,62 @@ def metric_init(params): 'description': 'Number of Beanstalkd Burries', 'groups': 'beanstalkd'} ] - + + #now get all the tubes + bean=beanstalkc.Connection(host=HOST,port=PORT) + tubes=bean.tubes() + for tube in tubes: + descriptors.append( + {'name': tube+'_total-jobs', + 'call_back': tube_stat_handler, + 'time_max': 90, + 'value_type': 'uint', + 'units': 'total jobs', + 'slope': 'both', + 'format': '%u', + 'description': 'Number of Beanstalkd Jobs ('+tube+')', + 'groups': 'beanstalkd'}) + descriptors.append( + {'name': tube+'_current-watching', + 'call_back': tube_stat_handler, + 'time_max': 90, + 'value_type': 'uint', + 'units': 'clients', + 'slope': 'both', + 'format': '%u', + 'description': 'Number Watchers ('+tube+')', + 'groups': 'beanstalkd'}) + descriptors.append( + {'name': tube+'_current-jobs-buried', + 'call_back': tube_stat_handler, + 'time_max': 90, + 'value_type': 'uint', + 'units': 'jobs', + 'slope': 'both', + 'format': '%u', + 'description': 'Current Number of Jobs Burried ('+tube+')', + 'groups': 'beanstalkd'}) + descriptors.append( + {'name': tube+'_current-jobs-ready', + 'call_back': tube_stat_handler, + 'time_max': 90, + 'value_type': 'uint', + 'units': 'clients', + 'slope': 'both', + 'format': '%u', + 'description': 'Current Jobs Ready ('+tube+')', + 'groups': 'beanstalkd'}) + descriptors.append( + {'name': tube+'_current-waiting', + 'call_back': tube_stat_handler, + 'time_max': 90, + 'value_type': 'uint', + 'units': 'jobs', + 'slope': 'both', + 'format': '%u', + 'description': 'Current Number of Jobs Waiting ('+tube+')', + 'groups': 'beanstalkd'}) + return descriptors def metric_cleanup():