Skip to content

Instantly share code, notes, and snippets.

@assimovt
Last active June 8, 2018 22:12
Show Gist options
  • Save assimovt/5181244 to your computer and use it in GitHub Desktop.
Save assimovt/5181244 to your computer and use it in GitHub Desktop.
Adds Newrelic RPMs metrics to your dashboard.

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.

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="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_name = 'ENTER YOUR APPLICATION NAME'
# 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|
app = NewRelicApi::Account.find(:first).applications(:params =>
{:conditions => {:name => app_name}}
).first
app.threshold_values.each do |v|
send_event("rpm_" + v.name.downcase.gsub(/ /, '_'), { value: v.metric_value })
end
end
@munish1
Copy link

munish1 commented Mar 23, 2018

I know very old, wanted to add a data point. New Relic has deprecated the gem and is no longer work with new API.

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