-
Notifications
You must be signed in to change notification settings - Fork 49
/
rabbitmq-throughput
executable file
·57 lines (47 loc) · 1.82 KB
/
rabbitmq-throughput
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
from munin import MuninPlugin
import mechanize
import simplejson
import sys
import os
# configuration
baseurl = 'http://localhost:55672'
usr = 'guest'
pwd = 'guest'
class RabbitMQThroughputPlugin(MuninPlugin):
title = "RabbitMQ Throughput"
args = "--base 1000 -l-500"
vlabel = "throughput"
scaled = False
category = "rabbitmq"
# what do we want?
message_fields = ['publish_details', 'ack_details', 'deliver_details', 'deliver_get_details', 'redeliver_details']
queue_fields = ['messages_details', 'messages_ready_details', 'messages_unacknowledged_details']
@property
def fields(self):
msg_warning = os.environ.get('msg_throughput_warn', 250)
msg_critical = os.environ.get('msg_throughput_crit', 300)
return [ (field.replace('details','rate'), dict(
label = field.replace('details','rate'),
info = '%s throughput (per sec)' % (field,),
type = "GAUGE",
min = "0",
warning = str(msg_warning),
critical = str(msg_critical))) for field in (self.message_fields + self.queue_fields)]
def execute(self):
global baseurl, usr, pwd
# make request
b = mechanize.Browser()
b.set_handle_robots(False)
b.add_password(baseurl, usr, pwd)
overview_url = baseurl + '/api/overview'
b.open(overview_url)
resp = b.response().read()
# get actual fields
ret = simplejson.loads(resp)
for f in self.message_fields:
print "%s.value %s" % (f.replace('details','rate'), ret['message_stats'][f]['rate'])
for f in self.queue_fields:
print "%s.value %s" % (f.replace('details','rate'), ret['queue_totals'][f]['rate'])
if __name__ == "__main__":
RabbitMQThroughputPlugin().run()