Skip to content

Instantly share code, notes, and snippets.

@doodlemoonch
Forked from assimovt/README.md
Last active December 16, 2015 05:59
Show Gist options
  • Select an option

  • Save doodlemoonch/5388368 to your computer and use it in GitHub Desktop.

Select an option

Save doodlemoonch/5388368 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.

<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'
# 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 '1m', :first_in => 0 do |job|
NewRelicApi::Account.find(:first).applications().each do |app|
app.threshold_values.each do |v|
send_event("rpm_" + app.name.gsub(/\./, '_') + "_" + v.name.downcase.gsub(/ /, '_'), { value: v.metric_value })
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment