From e2abe2fb6e8f779f517629f12a560769d1511afe Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Mon, 7 Jan 2013 19:39:04 -0500 Subject: [PATCH 1/3] add RabbitMQ check to dd-agent this check is used to gather statistics from RabbitMQ's managment plugin --- checks.d/rabbitmq.py | 81 ++++++++++++++++++++++++++++++++++++ conf.d/rabbitmq.yaml.example | 10 +++++ 2 files changed, 91 insertions(+) create mode 100644 checks.d/rabbitmq.py create mode 100644 conf.d/rabbitmq.yaml.example diff --git a/checks.d/rabbitmq.py b/checks.d/rabbitmq.py new file mode 100644 index 0000000000..199cd0408e --- /dev/null +++ b/checks.d/rabbitmq.py @@ -0,0 +1,81 @@ +import json +import urllib2 +import urlparse + +from checks import AgentCheck + + +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) diff --git a/conf.d/rabbitmq.yaml.example b/conf.d/rabbitmq.yaml.example new file mode 100644 index 0000000000..4695bc1c87 --- /dev/null +++ b/conf.d/rabbitmq.yaml.example @@ -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 \ No newline at end of file From 1126083a0884e0c7325d7e5922c3a9d54a9bfa0b Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Tue, 8 Jan 2013 07:37:35 -0500 Subject: [PATCH 2/3] use active tomcat-7.0.34 mirror --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 626c66fbd1..e2735e6087 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 From 250dc1f1165d01203307cac1f5e89c6b0bf54a3c Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Tue, 8 Jan 2013 10:19:19 -0500 Subject: [PATCH 3/3] use dd-agent util.json --- checks.d/rabbitmq.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checks.d/rabbitmq.py b/checks.d/rabbitmq.py index 199cd0408e..7e7e1c85f9 100644 --- a/checks.d/rabbitmq.py +++ b/checks.d/rabbitmq.py @@ -1,8 +1,8 @@ -import json import urllib2 import urlparse from checks import AgentCheck +from util import json class RabbitMQ(AgentCheck):