Skip to content

Instantly share code, notes, and snippets.

Forked from erikwennerberg/
Last active February 10, 2017 17:53
Show Gist options
  • Save mjc/7836009 to your computer and use it in GitHub Desktop.
Save mjc/7836009 to your computer and use it in GitHub Desktop.


Add the following gems to your Gemfile:

gem 'activeresource'
gem 'newrelic_api'

Update your 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 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>
require 'newrelic_api'
# Newrelic API key
key = nil
# Array of monitored application ids
app_ids = nil
# Emitted metrics:
# - rpm_apdex
# - rpm_error_rate
# - rpm_throughput
# - rpm_errors
# - rpm_response_time
# - rpm_db
# - rpm_cpu
# - rpm_memory
NewRelicApi.api_key = key
newrelic_account = NewRelicApi::Account.find(:first)
newrelic_apps = do |app|
app_ids.include? if app_ids
SCHEDULER.every '10s', first_in: 0 do |job|
newrelic_apps.each do |newrelicapp|
newrelicapp.threshold_values.each do |v|
underscored_name =' ', '_')
event_name = sprintf('%s_rpm_%s',, underscored_name)
send_event(event_name, value: v.metric_value)
end if app_ids
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment