Skip to content

Instantly share code, notes, and snippets.

@erikwennerberg
Forked from assimovt/README.md
Last active November 1, 2017 12:12
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save erikwennerberg/6875943 to your computer and use it in GitHub Desktop.
Save erikwennerberg/6875943 to your computer and use it in GitHub Desktop.

Setup

Add the following gems to your Gemfile:

gem 'activeresource'
gem 'newrelic_api'

Update your bundle:

bundle

Put the newrelic_rpm.rb to jobs/newrelic_rpm.rb and configure your API key and Application name.

Finally, choose a metric (see "Emitted metrics" jobs/newrelic_rpm.rb) you want to show on the dashboard and add corresponding HTML code. For example, the code below shows Newrelic Throughput (requests/minute) on the scale of 100. Adjust the scale based on your application usage. Specify your app IDs (found in the New Relic URL of an application), and define the corresponding metrics in the .erb.

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="YOURAPPID1_rpm_throughput" data-view="Meter" data-title="RPM" data-min="0" data-max="100"></div>
</li>
<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="YOURAPPID2_rpm_throughput" data-view="Meter" data-title="RPM" data-min="0" data-max="100"></div>
</li>
require 'newrelic_api'
# Newrelic API key
key = 'ENTER YOUR KEY'
# Monitored application
app_id = ['YOURAPPID1' ,'YOURAPPID2']
# Emitted metrics:
# - rpm_apdex
# - rpm_error_rate
# - rpm_throughput
# - rpm_errors
# - rpm_response_time
# - rpm_db
# - rpm_cpu
# - rpm_memory
NewRelicApi.api_key = key
SCHEDULER.every '10s', :first_in => 0 do |job|
newrelicapp = NewRelicApi::Account.find(:first).applications.select{|app| app.id.to_s == app_id }.first
newrelicapp.threshold_values.each do |v|
puts v.metric_value
send_event(newrelicapp.id + "_rpm_" + v.name.downcase.gsub(/ /, '_'), { value: v.metric_value })
end
end
@nicovs
Copy link

nicovs commented Nov 1, 2013

Hi Erik,

I get this error when using your NR dash:
scheduler caught exception:
undefined method threshold_values' for nil:NilClass /var/www/dashboard_publicdash1/jobs/newrelic_rpm.rb:26:inblock in <top (required)>'

Tnx
Nico

@mjc
Copy link

mjc commented Dec 7, 2013

My fork contains a fix for that error as well as a bit of a refactor: newrelic_rpm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment