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
This commit is contained in:
Jerry Zhao 2014-10-08 09:28:07 -07:00
parent a519da6974
commit 7099464c5a
1 changed files with 9 additions and 8 deletions

View File

@ -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)