Skip to content

Instantly share code, notes, and snippets.

@ssplatt
Last active August 29, 2015 14:25
Show Gist options
  • Save ssplatt/8ba50b6dcdaec5969d2b to your computer and use it in GitHub Desktop.
Save ssplatt/8ba50b6dcdaec5969d2b to your computer and use it in GitHub Desktop.
ganglia cpu user graph in dashing
require 'httparty'
require 'addressable/uri'
# cpu_user url
uri_cpu = Addressable::URI.escape "http://localhost/ganglia/graph.php?r=hour&title=&vl=&x=&n=&hreg[]=compute&mreg[]=cpu_user&gtype=stack&glegend=hide&aggregate=1&embed=1&_=1410463742829&json=1"
SCHEDULER.every '15s', :first_in => 0 do |job|
points = []
response = HTTParty.get(uri_cpu)
response.each do |host|
step = 0
host["datapoints"].each do |val,secs|
if val == "NaN"
next
end
if points[step] == nil
# -14400 for EST
points << { x: secs-14400, y: val.round }
else
points[step][:y] += val.round
end
step += 1
end
end
send_event('ganglia_cpu', { points: points })
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment