public
Last active — forked from anotherjesse/gist:70718

  • Download Gist
gistfile1.builder
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#!/usr/bin/env ruby
 
require 'open-uri'
require 'rexml/document'
require 'rexml/xpath'
 
url = 'http://rpm.newrelic.com/accounts.xml?include=application_health'
 
headers = {'x-license-key' => 'YOUR LICENSE KEY'}
 
app_name = 'YOUR APPLICATION NAME' # the application for which you want to collect data
 
name = $0.split('_').last.split('.').first.downcase
 
sections = {
'cpu' => {:title => 'CPU', :metric => '%'},
'memory' => {:title => 'Memory', :metric => 'MB'},
'errors' => {:title => 'Errors', :metric => 'errors per minute'},
'response' => {:title => 'Response Time', :metric => 'ms'},
'throughput' => {:title => 'Throughput', :metric => 'calls per minute'},
'db' => {:title => 'DB', :metric => '%'}
}
 
unless sections.keys.member? name
puts "ERROR: specify section in #{sections.keys.inspect}"
puts "example: ln -s /usr/share/munin/plugins/relic.rb relic_db"
exit 1
end
 
section = sections[name]
 
if ARGV.first == 'autoconf'
puts 'yes'
exit 0
end
 
if ARGV.first == 'config'
puts "graph_category New Relic"
puts "graph_title #{section[:title]}"
puts "graph_vlabel #{section[:metric]}"
 
puts "#{name}.label #{name}"
exit 0
end
 
 
open(url, headers) do |f|
doc = REXML::Document.new(f.read)
REXML::XPath.each(doc, "//application[name='#{app_name}']//threshold_value") do |metric|
if metric.attributes['name'].downcase.match(name)
puts "#{name}.value #{metric.attributes['metric_value']}"
end
end
end

Added support for having multiple applications under one account. Still works when you have only one application as long as you still specify the name of that application in the script.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.