Skip to content

Instantly share code, notes, and snippets.

@anotherjesse
Created February 26, 2009 07:07

Revisions

  1. anotherjesse revised this gist Feb 26, 2009. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@

    unless sections.keys.member? name
    puts "ERROR: specify section in #{sections.keys.inspect}"
    puts "example: ln -s muninrelic.rb muninrelic_db.rb"
    puts "example: ln -s /usr/share/munin/plugins/relic.rb relic_db"
    exit 1
    end

  2. @invalid-email-address Anonymous created this gist Feb 26, 2009.
    52 changes: 52 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    #!/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'}

    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 muninrelic.rb muninrelic_db.rb"
    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, "//threshold_value") do |metric|
    if metric.attributes['name'].downcase.match(name)
    puts "#{name}.value #{metric.attributes['metric_value']}"
    end
    end
    end