-
Notifications
You must be signed in to change notification settings - Fork 812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RabbitMQ Management Plugin Check #330
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do
from util import json
instead it will support more version of python because we handle simplejson, stdlib json, etc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I also noticed there is
checks.libs.httplib2
is this preferred overurllib2
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
urllib2
here is fine. We usedhttplib2
for one check so that timeouts would be compatible with versions >= 2.4, but that's not needed in this case, as far as I can tell.