Skip to content

Instantly share code, notes, and snippets.

@cornet
Created December 11, 2011 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cornet/1463505 to your computer and use it in GitHub Desktop.
Save cornet/1463505 to your computer and use it in GitHub Desktop.
Munin + Graphite + Bunny
#!/usr/bin/env ruby
require 'rubygems'
require 'munin-ruby'
require 'bunny'
munin = Munin::Node.new
metric_base = "servers"
all_metrics = Array.new
while true
munin.nodes.each do |node|
munin.list(node).each do |service|
munin.fetch(service).each do |metrics|
metrics[1].each do |k,v|
msg = "%s.%s.%s.%s %s %d" % [
metric_base,
node.split('.').reverse.join('.'), # Reverse hostname parts
service,
k,
v.to_s,
Time.now.utc.to_i
]
all_metrics << msg
end
end
end
end
bunny = Bunny.new(
:host => 'localhost',
:user => 'graphite',
:pass => 'gr4ph1t3',
:logging => false,
)
bunny.start
exch = bunny.exchange("graphite", :type => "topic", :durable => true)
all_metrics.each do |metric|
puts "Sending #{metric}"
exch.publish(metric)
end
bunny.stop
sleep 60
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment