From 7099464c5ac4716cff88c111d6fc009c99b063e7 Mon Sep 17 00:00:00 2001 From: Jerry Zhao Date: Wed, 8 Oct 2014 09:28:07 -0700 Subject: [PATCH] change the way to filter stats for vhost from http api response. Somehow, some times, rabbitmq http api fails to get a valid response with vhost specified, works without vhost, so we filter the stats for the monitored vhost from the response for all vhosts or api/queues/wq. Change-Id: I95dbc9b0fca2af88bd6a46c4c112264c37b636c0 --- .../collectd/files/default/rabbitmq_info.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/chef/cookbooks/collectd/files/default/rabbitmq_info.py b/chef/cookbooks/collectd/files/default/rabbitmq_info.py index e8ce83e..0d9ecdd 100644 --- a/chef/cookbooks/collectd/files/default/rabbitmq_info.py +++ b/chef/cookbooks/collectd/files/default/rabbitmq_info.py @@ -53,7 +53,7 @@ def get_stats(): # call http api instead of rabbitmqctl to collect statistics due to issue: # https://github.com/phrawzty/rabbitmq-collectd-plugin/issues/5 try: - r = requests.get('%s/%s' % (RABBITMQ_API, VHOST), + r = requests.get('%s' % RABBITMQ_API, auth=('%s' % USER, '%s' % PASS)) # p = subprocess.Popen([RABBITMQCTL_BIN, '-q', '-p', VHOST, # 'list_queues', 'name', 'messages', 'memory', 'consumers'], @@ -83,14 +83,15 @@ def get_stats(): logger('err', 'No result found for this vhost') return None for i in resp: - if "messages" in i: - stats['ctl_messages'] += i['messages'] + if i['vhost'] == VHOST: + if "messages" in i: + stats['ctl_messages'] += i['messages'] + stats['ctl_messages_%s' % i['name']] = i['messages'] + stats['ctl_memory'] += i['memory'] + stats['ctl_consumers'] += i['consumers'] stats['ctl_messages_%s' % i['name']] = i['messages'] - stats['ctl_memory'] += i['memory'] - stats['ctl_consumers'] += i['consumers'] - stats['ctl_messages_%s' % i['name']] = i['messages'] - stats['ctl_memory_%s' % i['name']] = i['memory'] - stats['ctl_consumers_%s' % i['name']] = i['consumers'] + stats['ctl_memory_%s' % i['name']] = i['memory'] + stats['ctl_consumers_%s' % i['name']] = i['consumers'] if not stats['ctl_memory'] > 0: logger('warn', '%s reports 0 memory usage. This is probably incorrect.' % RABBITMQ_API)