Created
September 13, 2016 20:10
-
-
Save BradWhittington/034c29340a79c3a14f82e92a53f6cb6c to your computer and use it in GitHub Desktop.
Generate stackdriver/collectd config file for all queues on localhost
This file contains hidden or 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
#!/usr/bin/python | |
# Usage: curl http://guest:guest@localhost:15672/api/queues | ./generate_config.py > /opt/stackdriver/collectd/etc/collectd.d/rabbitmq.conf | |
import sys, json; | |
queues = json.load(sys.stdin) | |
output = """ | |
# This is the monitoring configuration for RabbitMQ. | |
# Look for RABBITMQ_HOST and RABBITMQ_PORT to adjust your configuration file. | |
LoadPlugin curl_json | |
<Plugin "curl_json"> | |
# Each queue needs a separate URL section that points to | |
# http://localhost:15672/api/queues/vhost/QUEUE_NAME . | |
# Replace QUEUE_NAME in the URL section with the name of the queue. | |
# | |
# NOTE: The vhost and queue name must be URL-encoded. | |
# Being that the default vhost is a forward slash "/", | |
# we encode this as "%2F". | |
# When using non-standard RabbitMQ configurations, replace the below with | |
#<URL "http://RABBITMQ_HOST:RABBITMQ_PORT/api/queues/%2F/QUEUE_NAME"> | |
""" | |
for queue in queues: | |
output+=""" | |
<URL "http://localhost:15672/api/queues/%2F/QUEUE_NAME"> | |
User "guest" | |
Password "guest" | |
Instance "rabbitmq-QUEUE_NAME" | |
<Key "messages"> | |
Type "gauge" | |
</Key> | |
<Key "messages_unacknowledged"> | |
Type "gauge" | |
</Key> | |
<Key "messages_ready"> | |
Type "gauge" | |
</Key> | |
<Key "consumers"> | |
Type "gauge" | |
</Key> | |
<Key "message_stats/publish_details/rate"> | |
Type "gauge" | |
</Key> | |
<Key "message_stats/deliver_details/rate"> | |
Type "gauge" | |
</Key> | |
</URL>""".replace("QUEUE_NAME",queue['name']) | |
output+=""" | |
</Plugin> | |
LoadPlugin match_regex | |
LoadPlugin target_set | |
LoadPlugin target_replace | |
<Chain "curl_json_rabbitmq"> | |
<Rule "rewrite_curl_json_to_rabbitmq"> | |
<Match regex> | |
Plugin "^curl_json$" | |
PluginInstance "^rabbitmq-.*$" | |
</Match> | |
<Target "replace"> | |
PluginInstance "^rabbitmq-" "" | |
</Target> | |
<Target "set"> | |
Plugin "rabbitmq" | |
</Target> | |
</Rule> | |
<Rule "rewrite_empty_plugininstance"> | |
<Match regex> | |
PluginInstance "^$" | |
</Match> | |
<Target "set"> | |
PluginInstance "localhost" | |
</Target> | |
</Rule> | |
<Rule "go_back"> | |
Target "return" | |
</Rule> | |
</Chain> | |
<Chain "PreCache"> | |
<Rule "jump_to_curl_json_rabbitmq"> | |
<Target "jump"> | |
Chain "curl_json_rabbitmq" | |
</Target> | |
</Rule> | |
</Chain> | |
PreCacheChain "PreCache" | |
""" | |
print(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment