Skip to content

Instantly share code, notes, and snippets.

@clarkdave
Last active November 24, 2020 16:45
Show Gist options
  • Save clarkdave/2f8c86ed836046498f9545e51a6122dc to your computer and use it in GitHub Desktop.
Save clarkdave/2f8c86ed836046498f9545e51a6122dc to your computer and use it in GitHub Desktop.
Monitoring thousands of queues with Datadog
#!/usr/bin/env ruby
require 'datadog/statsd'
require 'json'
statsd = Datadog::Statsd.new('localhost', 8125)
queue_fields = %w(
consumer_utilisation
consumers
memory
messages_ready
name
)
vhosts = JSON.parse(
`rabbitmqctl list_vhosts --formatter json`,
).map { |x| x['name'] }
vhosts.each do |vhost|
queues = JSON.parse(
`rabbitmqctl list_queues -p #{vhost} --local --formatter json #{queue_fields.join(' ')}`,
)
queues.each do |queue|
tags = [
"vhost:#{vhost}",
"queue:#{queue['name']}",
]
statsd.gauge(
'rabbitmq.queue.messages_ready',
queue['messages_ready'],
tags: tags,
)
statsd.gauge(
'rabbitmq.queue.memory',
queue['memory'],
tags: tags,
)
statsd.gauge(
'rabbitmq.queue.consumers',
queue['consumers'],
tags: tags,
)
statsd.gauge(
'rabbitmq.queue.consumer_utilisation',
queue['consumer_utilisation'],
tags: tags,
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment