Skip to content

Commit

Permalink
Merge pull request #2468 from DataDog/olivielpeau/rabbitmq-family-tag…
Browse files Browse the repository at this point in the history
…ging

[rabbitmq] add a way to tag multiple queues in the same "family"
  • Loading branch information
olivielpeau committed May 5, 2016
2 parents 48b9ff2 + bd95717 commit 09b6fb6
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 27 deletions.
12 changes: 10 additions & 2 deletions checks.d/rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

# project
from checks import AgentCheck
from config import _is_affirmative

EVENT_TYPE = SOURCE_TYPE_NAME = 'rabbitmq'
QUEUE_TYPE = 'queues'
Expand Down Expand Up @@ -75,6 +76,7 @@
'name': 'queue',
'vhost': 'vhost',
'policy': 'policy',
'queue_family': 'queue_family',
},
NODE_TYPE: {
'name': 'node',
Expand Down Expand Up @@ -203,7 +205,10 @@ def get_stats(self, instance, base_url, object_type, max_detailed, filters, auth

match_found = False
for p in regex_filters:
if re.search(p, name):
match = re.search(p, name)
if match:
if _is_affirmative(instance.get("tag_families", False)) and match.groups():
data_line["queue_family"] = match.groups()[0]
matching_lines.append(data_line)
match_found = True
break
Expand All @@ -221,7 +226,10 @@ def get_stats(self, instance, base_url, object_type, max_detailed, filters, auth
continue

for p in regex_filters:
if re.search(p, absolute_name):
match = re.search(p, absolute_name)
if match:
if _is_affirmative(instance.get("tag_families", False)) and match.groups():
data_line["queue_family"] = match.groups()[0]
matching_lines.append(data_line)
match_found = True
break
Expand Down
8 changes: 7 additions & 1 deletion conf.d/rabbitmq.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ 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)
# optional: 'rabbitmq_user' (default: guest), 'rabbitmq_pass' (default: guest),
# and 'tag_families' (default: false) to tag queue "families" based off of regex
# matching.
- rabbitmq_api_url: http://localhost:15672/api/
rabbitmq_user: guest
rabbitmq_pass: guest
# tag_families: true
# Use the `nodes` or `nodes_regexes` parameters to specify the nodes you'd like to
# collect metrics on (up to 100 nodes).
# If you have less than 100 nodes, you don't have to set this parameter,
Expand All @@ -23,13 +26,16 @@ instances:
# If you have less than 200 queues, you don't have to set this parameter,
# the metrics will be collected on all the queues by default.
# If you have set up vhosts, set the queue names as `vhost_name/queue_name`.
# If you have `tag_families` enabled, the first captured group in the regex
# will be used as the queue_family tag
#
# queues:
# - queue1
# - queue2
# queues_regexes:
# - thisqueue-.*
# - another_\d+queue
# - (lepidorae)-\d+ # to tag queues in the lepidorae queue_family

# Service checks:
# By default a list of all vhosts is fetched and each one will be checked
Expand Down
65 changes: 41 additions & 24 deletions tests/checks/integration/test_rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@
]
}

CONFIG_WITH_FAMILY = {
'init_config': {},
'instances': [
{
'rabbitmq_api_url': 'http://localhost:15672/api/',
'rabbitmq_user': 'guest',
'rabbitmq_pass': 'guest',
'tag_families': True,
'queues_regexes': ['(test)\d+'],
}
]
}

COMMON_METRICS = [
'rabbitmq.node.fd_used',
'rabbitmq.node.mem_used',
Expand All @@ -36,6 +49,19 @@
'rabbitmq.node.partitions'
]

Q_METRICS = [
'consumers',
'memory',
'messages',
'messages.rate',
'messages_ready',
'messages_ready.rate',
'messages_unacknowledged',
'messages_unacknowledged.rate',
'messages.publish.count',
'messages.publish.rate',
]


@attr(requires='rabbitmq')
class RabbitMQCheckTest(AgentCheckTest):
Expand All @@ -53,18 +79,6 @@ def test_check(self):
# Queue attributes, should be only one queue fetched
# TODO: create a 'fake consumer' and get missing metrics
# active_consumers, acks, delivers, redelivers
Q_METRICS = [
'consumers',
'memory',
'messages',
'messages.rate',
'messages_ready',
'messages_ready.rate',
'messages_unacknowledged',
'messages_unacknowledged.rate',
'messages.publish.count',
'messages.publish.rate',
]
for mname in Q_METRICS:
self.assertMetricTag('rabbitmq.queue.%s' %
mname, 'rabbitmq_queue:test1', count=1)
Expand All @@ -80,18 +94,6 @@ def test_queue_regex(self):
for mname in COMMON_METRICS:
self.assertMetricTagPrefix(mname, 'rabbitmq_node', count=1)

Q_METRICS = [
'consumers',
'memory',
'messages',
'messages.rate',
'messages_ready',
'messages_ready.rate',
'messages_unacknowledged',
'messages_unacknowledged.rate',
'messages.publish.count',
'messages.publish.rate',
]
for mname in Q_METRICS:
self.assertMetricTag('rabbitmq.queue.%s' %
mname, 'rabbitmq_queue:test1', count=1)
Expand All @@ -103,3 +105,18 @@ def test_queue_regex(self):
self.assertServiceCheckOK('rabbitmq.aliveness', tags=['vhost:/'])

self.coverage_report()

def test_family_tagging(self):
self.run_check(CONFIG_WITH_FAMILY)

# Node attributes
for mname in COMMON_METRICS:
self.assertMetricTagPrefix(mname, 'rabbitmq_node', count=1)

for mname in Q_METRICS:
self.assertMetricTag('rabbitmq.queue.%s' %
mname, 'rabbitmq_queue_family:test', count=2)

self.assertServiceCheckOK('rabbitmq.aliveness', tags=['vhost:/'])

self.coverage_report()

0 comments on commit 09b6fb6

Please sign in to comment.