Skip to content

Instantly share code, notes, and snippets.

@rqbanerjee
Created August 17, 2017 20:04
Show Gist options
  • Save rqbanerjee/1690b9ed186b99c202d64cd990f437b5 to your computer and use it in GitHub Desktop.
Save rqbanerjee/1690b9ed186b99c202d64cd990f437b5 to your computer and use it in GitHub Desktop.
Post metrics to New Relic
def collect_rabbit_data
queues = {}
regex = "/#{INTERESTING_QUEUES.join('|')}/"
raw_output = `/sbin/rabbitmqctl list_queues`
lines = raw_output.split("\n")
lines.each do |l|
if l.match(regex)
parts = l.split("\t")
queues[parts[0]] = parts[1].to_i
end
end
queues
end
def process_and_post_metrics(queues)
queues.each_pair do |queue_name, messages|
name = "Custom/queue_messages_#{queue_name}"
::NewRelic::Agent.record_metric(name, messages)
puts "Posting #{name} -> #{messages}"
end
end
::NewRelic::Agent.manual_start
queues = collect_rabbit_data
process_and_post_metrics(queues)
::NewRelic::Agent.shutdown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment