Skip to content

Commit

Permalink
Merge pull request #330 from brettlangdon/master
Browse files Browse the repository at this point in the history
RabbitMQ Management Plugin Check
  • Loading branch information
conorbranagan committed Jan 8, 2013
2 parents ab14fde + 250dc1f commit fe2de39
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ before_script:
- sudo apt-get install python-mysqldb
- curl -L https://raw.github.com/DataDog/dd-agent/check-haproxy/tests/haproxy.cfg > /tmp/haproxy.cfg
- curl -L http://mirror.sdunix.com/apache/tomcat/tomcat-6/v6.0.36/bin/apache-tomcat-6.0.36.tar.gz | tar -C /tmp -xzf - && mv /tmp/apache-tomcat-6.0.36 /tmp/apache-tomcat-6 && echo 'export CATALINA_OPTS="-Dcom.sun.management.jmxremote.port=8090 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false" export CATALINA_OUT="/tmp/apache-tomcat-6/catalina.out"' > /tmp/apache-tomcat-6/bin/setenv.sh
- curl -L http://www.reverse.net/pub/apache/tomcat/tomcat-7/v7.0.34/bin/apache-tomcat-7.0.34.tar.gz | tar -C /tmp -xzf - && mv /tmp/apache-tomcat-7.0.34/ /tmp/apache-tomcat-7 && echo 'export CATALINA_OPTS="-Dcom.sun.management.jmxremote.port=8091 -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file=/tmp/apache-tomcat-7/conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=/tmp/apache-tomcat-7/conf/jmxremote.access -Dcom.sun.management.jmxremote.ssl=false" export CATALINA_OUT="/tmp/apache-tomcat-7/catalina.out"' > /tmp/apache-tomcat-7/bin/setenv.sh && echo 'monitorRole readonly' > /tmp/apache-tomcat-7/conf/jmxremote.access && echo 'monitorRole tomcat' > /tmp/apache-tomcat-7/conf/jmxremote.password && chmod 400 /tmp/apache-tomcat-7/conf/jmxremote.password
- curl -L http://mirrors.ibiblio.org/apache/tomcat/tomcat-7/v7.0.34/bin/apache-tomcat-7.0.34.tar.gz | tar -C /tmp -xzf - && mv /tmp/apache-tomcat-7.0.34/ /tmp/apache-tomcat-7 && echo 'export CATALINA_OPTS="-Dcom.sun.management.jmxremote.port=8091 -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file=/tmp/apache-tomcat-7/conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=/tmp/apache-tomcat-7/conf/jmxremote.access -Dcom.sun.management.jmxremote.ssl=false" export CATALINA_OUT="/tmp/apache-tomcat-7/catalina.out"' > /tmp/apache-tomcat-7/bin/setenv.sh && echo 'monitorRole readonly' > /tmp/apache-tomcat-7/conf/jmxremote.access && echo 'monitorRole tomcat' > /tmp/apache-tomcat-7/conf/jmxremote.password && chmod 400 /tmp/apache-tomcat-7/conf/jmxremote.password
- curl -L https://raw.github.com/DataDog/dd-agent/jmx_multiple_checks/tests/tomcat_cfg.xml > /tmp/apache-tomcat-6/conf/server.xml
- curl -L http://mirror.cc.columbia.edu/pub/software/apache/lucene/solr/3.6.1/apache-solr-3.6.1.tgz > /tmp/solr.tgz && tar -C /tmp -xzf /tmp/solr.tgz && mv /tmp/apache-solr-3.6.1 /tmp/apache-solr-3 && echo 'monitorRole readonly' > /tmp/apache-solr-3/example/jmxremote.access && echo 'monitorRole solr' > /tmp/apache-solr-3/example/jmxremote.password && chmod 400 /tmp/apache-solr-3/example/jmxremote.password
- sudo apt-get install nginx
Expand Down
81 changes: 81 additions & 0 deletions checks.d/rabbitmq.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import urllib2
import urlparse

from checks import AgentCheck
from util import json


class RabbitMQ(AgentCheck):
"""This check is for gathering statistics from the RabbitMQ
Management Plugin (http://www.rabbitmq.com/management.html)
"""
def check(self, instance):
# make sure 'rabbitmq_api_url; is present
if 'rabbitmq_api_url' not in instance:
self.log.info('Skipping instance "rabbitmq_api_url" not found')
return

# get parameters
base_url = instance['rabbitmq_api_url']
username = instance.get('rabbitmq_user', 'guest')
password = instance.get('rabbitmq_pass', 'guest')

# setup urllib2 for Basic Auth
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password(realm='RabbitMQ Management', uri=base_url, user=username, passwd=password)
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)

self.get_queue_stats(base_url)
self.get_node_stats(base_url)

def get_queue_stats(self, base_url):
url = urlparse.urljoin(base_url, 'queues')
stats = []
try:
stats = json.loads(urllib2.urlopen(url).read())
except urllib2.URLError, e:
self.log.info('Cannot open RabbitMQ API url: %s', url)
except ValueError, e:
self.log.info('Cannot parse JSON response from API url: %s', url)

for node in stats:
tags = []
tags.append('rabbitmq_node:%s' % node['node'])
tags.append('rabbitmq_queue:%s' % node['name'])
tags.append('rabbitmq_vhost:%s' % node['vhost'])
tags.append('rabbitmq_policy:%s' % node['policy'])

self.gauge('rabbitmq.queue.active_consumers', int(node['active_consumers']), tags=tags)
self.gauge('rabbitmq.queue.consumers', int(node['consumers']), tags=tags)
self.gauge('rabbitmq.queue.memory', int(node['memory']), tags=tags)
self.gauge('rabbitmq.queue.messages', int(node['messages']), tags=tags)
self.gauge('rabbitmq.queue.messages_ready', int(node['messages_ready']), tags=tags)
self.gauge('rabbitmq.queue.messages_unacknowledged', int(node['messages_unacknowledged']), tags=tags)

def get_node_stats(self, base_url):
url = urlparse.urljoin(base_url, 'nodes')
stats = []
try:
stats = json.loads(urllib2.urlopen(url).read())
except urllib2.URLError, e:
self.log.info('Cannot open RabbitMQ API url: %s', url)
except ValueError, e:
self.log.info('Cannot parse JSON response from API url: %s', url)

for node in stats:
tags = []
tags.append('rabbitmq_node:%s' % node['name'])

self.gauge('rabbitmq.node.disk_free', int(node['disk_free']), tags=tags)
self.gauge('rabbitmq.node.disk_free_limit', int(node['disk_free_limit']), tags=tags)
self.gauge('rabbitmq.node.fd_total', int(node['fd_total']), tags=tags)
self.gauge('rabbitmq.node.fd_used', int(node['fd_used']), tags=tags)
self.gauge('rabbitmq.node.mem_limit', int(node['mem_limit']), tags=tags)
self.gauge('rabbitmq.node.mem_used', int(node['mem_used']), tags=tags)
self.gauge('rabbitmq.node.proc_total', int(node['proc_total']), tags=tags)
self.gauge('rabbitmq.node.proc_used', int(node['proc_used']), tags=tags)
self.gauge('rabbitmq.node.processors', int(node['processors']), tags=tags)
self.gauge('rabbitmq.node.run_queue', int(node['run_queue']), tags=tags)
self.gauge('rabbitmq.node.sockets_total', int(node['sockets_total']), tags=tags)
self.gauge('rabbitmq.node.sockets_used', int(node['sockets_used']), tags=tags)
10 changes: 10 additions & 0 deletions conf.d/rabbitmq.yaml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
init_config:

instances:
# for every instance a 'rabbitmq_api_url' must be provided, pointing to the api
# url of the RabbitMQ Managment Plugin (http://www.rabbitmq.com/management.html)
# optional: 'rabbitmq_user' (default: guest) and 'rabbitmq_pass' (default: guest)

- rabbitmq_api_url: http://localhost:15672/api/
rabbitmq_user: guest
rabbitmq_pass: guest

0 comments on commit fe2de39

Please sign in to comment.