Skip to content
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

Add 'LocalQueuesOnly' option #67

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ This plugin supports a small amount of configuration options:
* `ValidateCerts`: You can ignore verifying the SSL certificate if you set it to `false`. Defaults to `true`
* `VHostPrefix`: Arbitrary string to prefix the vhost name with. Defaults to None
* `Ignore`: The queue to ignore, matching by Regex. See example.
* `LocalQueuesOnly`: For clustered rabbitmq nodes report only queues resident on the node being queried. Defaults to `false`

See `this example`_ for further details.
.. _this example: config/collectd.conf
Expand Down
6 changes: 5 additions & 1 deletion collectd_rabbitmq/collectd_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def configure(config_values):
scheme = 'http'
validate_certs = True
vhost_prefix = None
local_queues_only = False

for config_value in config_values.children:
collectd.debug("%s = %s" % (config_value.key, config_value.values))
Expand All @@ -59,6 +60,8 @@ def configure(config_values):
vhost_prefix = config_value.values[0]
elif config_value.key == 'ValidateCerts':
validate_certs = config_value.values[0]
elif config_value.key == 'LocalQueuesOnly':
local_queues_only = config_value.values[0]
elif config_value.key == 'Ignore':
type_rmq = config_value.values[0]
data_to_ignore[type_rmq] = list()
Expand All @@ -70,7 +73,8 @@ def configure(config_values):
auth = utils.Auth(username, password, realm)
conn = utils.ConnectionInfo(host, port, scheme,
validate_certs=validate_certs)
config = utils.Config(auth, conn, data_to_ignore, vhost_prefix)
config = utils.Config(auth, conn, data_to_ignore, vhost_prefix,
local_queues_only)
CONFIGS.append(config)


Expand Down
11 changes: 9 additions & 2 deletions collectd_rabbitmq/rabbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,15 @@ def get_queues(self, vhost_name=None):
"""
Returns raw queue data.
"""
collectd.debug("Getting queues for %s" % vhost_name)
return self.get_info("queues", vhost_name)
if self.config.local_queues_only:
node = self.get_info("overview")["node"]
collectd.debug("Getting local queues for %s:%s" %
(node, vhost_name))
nodes = self.get_info("queues", vhost_name)
return [x for x in nodes if x["node"] == node]
else:
collectd.debug("Getting queues for %s" % vhost_name)
return self.get_info("queues", vhost_name)

def get_queue_names(self, vhost_name=None):
"""
Expand Down
3 changes: 2 additions & 1 deletion collectd_rabbitmq/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ class Config(object):
"""

def __init__(self, auth, connection, data_to_ignore=None,
vhost_prefix=None):
vhost_prefix=None, local_queues_only=False):
self.auth = auth
self.connection = connection
self.data_to_ignore = dict()
self.vhost_prefix = vhost_prefix
self.local_queues_only = local_queues_only

if data_to_ignore:
for key, values in data_to_ignore.items():
Expand Down