Skip to content

Instantly share code, notes, and snippets.

@vvuksan
Created September 29, 2010 13: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 vvuksan/602754 to your computer and use it in GitHub Desktop.
Save vvuksan/602754 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require "rexml/document"
require 'socket'
ganglia_hostname = 'localhost'
ganglia_port = 8649
graphite_host = "localhost"
graphite_port = "2003"
begin
# Open up a socket to gmond
file = TCPSocket.open(ganglia_hostname, ganglia_port)
# Open up a socke to graphite
graphite = TCPSocket.open(graphite_host, graphite_port)
# We need current time stamp in UNIX time
now = Time.now.to_i
# Parse the XML we got from gmond
doc = REXML::Document.new file
doc.elements.each("GANGLIA_XML/CLUSTER/HOST") { |element|
# Set metric prefix to the host name. Graphite uses dots to separate subtrees
# therefore we have to change dots in hostnames to _
metric_prefix=element.attributes["NAME"].gsub(".", "_")
element.elements.each("METRIC") { |metric|
if metric.attributes["TYPE"] != "string"
graphite.puts "#{metric_prefix}.#{metric.attributes["NAME"]} #{metric.attributes["VAL"]} #{now}\n"
end
}
}
graphite.close()
file.close()
rescue
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment