API examples for SLA reports

New Relic stores SLA data forever for eligible accounts, so you can use the New Relic REST API to generate service level agreement reports over any time period. For example, you can create SLA reports going back more than 12 days, weeks, or months.

Access to this feature depends on your subscription level.

Browser metrics for SLAs

Browser metrics for the End user tier are available only if you have enabled New Relic Browser.

Browser (End user tier) SLA metric name:value (and formula)
Page Views thousands EndUser : call_count
Load time sec EndUser : average_response_time
Apdex EndUser/Apdex : score
% Satisfied EndUser/Apdex : s divided by EndUser : call_count
% Tolerating EndUser/Apdex : t divided by Enduser : call_count
% Frustrated EndUser/Apdex : f divided by Enduser : call_count

App server metrics for SLAs

Here are the SLA metrics for application servers.

App server SLA metric name:value (and formula)
Requests millions HttpDispatcher : call_count (scaled appropriately)
Resp. time ms HttpDispatcher : average_response_time (multiplied by 1000)
Apdex Apdex : score
% Satisfied Apdex : s divided by Apdex : count
% Tolerating Apdex : t divided by Apdex : count
% Frustrated Apdex : f divided by Apdex : count

Tips for collecting metrics

Here are some tips for planning which metrics to collect.

SLA tips Comments
Requirements When using the cURL command examples, be sure to replace the placeholder text with your account ID, the corresponding New Relic REST API key or Admin's API key, and the application ID.
Time ranges You are not limited to standard day, week, or month time ranges. For example, you can extract metric data for a "holiday weekend" from 12/23 to 12/26 or "the 20 minutes after our site had problems" or whatever other period interests you.
UTC XML time format You must specify the time in UTC XML format, so be sure to adjust for your time zone compared to UTC. For example, New Relic starts at 16:00:00 on the day before the selected data, since New Relic headquarters are in UTC-8.
Summary reports When requesting metrics to use with summary reports, include the query string parameter summarize=true (v2) or summary=1 (v1) as shown in the examples.
Scaled statistics

Your report has some statistics that are scaled in the SLA reports in New Relic's user interface. New Relic changes the scale of page views in your report to show small numbers. Depending on your traffic, typically it might be displayed in thousands, millions, or billions.

Recommendation: To avoid a string of zeroes, divide this number appropriately for your own purposes.

End user statistics

End user statistics will reflect only the calls in which New Relic Browser data was gathered. For example, end user stats may not appear in situations such as:

  • Browsers types
  • Clients (they might have disabled the JavaScript agent, or blocked traffic to New Relic sites for JavaScript code's location
  • Transactions not in one of those categories, in case the page load did not complete for any reason

This is why there are fewer (sometimes many fewer) page views in the End User (Browser) data section than in the App server data section.

Examples

The following sections contain code examples to acquire the data for values described above for the Daily (24hr) SLA statistics in the default GMT/UTC time zone. Adjust the from= and to= for your time range as desired.

There are syntactical differences between New Relic's REST API v2 and v1. The examples show how to use each.

REST API v2 commands

Browser load time and page view count (v2)

To obtain the Browser (EndUser/RUM) load time and page view count for v2, from the command line, type:

curl -X GET "https://api.newrelic.com/v2/applications/REPLACE_WITH_YOUR_APPLICATION_ID/metrics/data.xml"\
    -H "X-Api-Key:REPLACE_WITH_YOUR_API_KEY" -i  \
    -d 'names[]=EndUser&values[]=call_count&values[]=average_response_time&from=2014-06-09T00:00:00+00:00&to=2014-06-09T23:00:00+00:00&summarize=true' 

In Ruby:

require 'rubygems'
require 'curb'

response = Curl::Easy.http_get("https://api.newrelic.com/v2/applications/REPLACE_WITH_YOUR_APPLICATION_ID/metrics/data.xml?names[]=EndUser&values[]=call_count&values[]=average_response_time&from=2012-01-01T00:00:00+00:00&to=2012-01-08T00:00:00+00:00&summarize=true") do |curl|
  curl.headers["x-api-key"] = "REPLACE_WITH_YOUR_API_KEY"
  curl.header_in_body=true
end
puts response.body_str
App response time and request count (v2)

To obtain the Application response time and request count for v2, from the command line, type:

curl -X GET "https://api.newrelic.com/v2/applications/REPLACE_WITH_YOUR_APPLICATION_ID/metrics/data.xml" \
     -H "X-Api-Key:REPLACE_WITH_YOUR_API_KEY" -i \
     -d 'names[]=HttpDispatcher&values[]=average_response_time&values[]=call_count&from=2014-06-09T00:00:00+00:00&to=2014-06-09T23:00:00+00:00&summarize=true'

In Ruby:

require 'rubygems'
require 'curb'

response = Curl::Easy.http_get("https://api.newrelic.com/v2/applications/REPLACE_WITH_YOUR_APPLICATION_ID/metrics/data.xml?names[]=HttpDispatcher&values[]=average_response_time&values[]=call_count&from=2012-01-01T00:00:00+00:00&to=2012-01-08T00:00:00+00:00&summarize=true") do |curl|
  curl.headers["x-api-key"] = "REPLACE_WITH_YOUR_API_KEY"
  curl.header_in_body=true
end
puts response.body_str
Apdex SLA data (v2)

To obtain the Apdex related data for v2, from the command line, type:

curl -X GET "https://api.newrelic.com/v2/applications/REPLACE_WITH_YOUR_APPLICATION_ID/metrics/data.xml" \
     -H "X-Api-Key:REPLACE_WITH_YOUR_API_KEY" -i \
     -d 'names[]=Apdex&names[]=EndUser/Apdex&from=2014-06-09T00:00:00+00:00&to=2014-06-09T23:00:00+00:00&summarize=true' 

In Ruby:

require 'rubygems'
require 'curb'

response = Curl::Easy.http_get("https://api.newrelic.com/v2/applications/REPLACE_WITH_YOUR_APPLICATION_ID/metrics/data.xml?names[]=EndUser/Apdex&from=2012-01-01T00:00:00+00:00&to=2012-01-08T00:00:00+00:00&summarize=true") do |curl|
  curl.headers["x-api-key"] = "REPLACE_WITH_YOUR_API_KEY"
  curl.header_in_body=true
end
puts response.body_str

REST API v1 commands (deprecated)

REST API v1 is deprecated.

Browser load time and page view count (v1)

To obtain the Browser (EndUser/RUM) load time and page view count for v1, from the command line, type:

curl -gH "x-api-key:REPLACE_WITH_YOUR_API_KEY" "https://api.newrelic.com/api/v1/accounts/REPLACE_WITH_YOUR_ACCOUNT_ID/applications/REPLACE_WITH_YOUR_APPLICATION_ID/data.xml?metrics[]=EndUser&field=call_count&field=average_response_time&summary=1&begin=2012-01-01T00:00:00Z&end=2012-01-08T00:00:00Z"

In Ruby:

require 'rubygems'
require 'curb'

response = Curl::Easy.perform("https://api.newrelic.com/api/v1/accounts/REPLACE_WITH_YOUR_ACCOUNT_ID/applications/REPLACE_WITH_YOUR_APPLICATION_ID/data.xml?metrics[]=EndUser&field=call_count&field=average_response_time&summary=1&begin=2012-01-01T00:00:00Z&end=2012-01-08T00:00:00Z") do |curl|
  curl.headers["x-api-key"] = "REPLACE_WITH_YOUR_API_KEY"
end
puts response.body_str
App response time and request count (v1)

To obtain the Application response time and request count for v1, from the command line, type:

curl -gH "x-api-key:REPLACE_WITH_YOUR_API_KEY" "https://api.newrelic.com/api/v1/accounts/REPLACE_WITH_YOUR_ACCOUNT_ID/applications/REPLACE_WITH_YOUR_APPLICATION_ID/data.xml?metrics[]=HttpDispatcher&field=average_response_time&field=call_count&summary=1&begin=2012-01-01T00:00:00Z&end=2012-01-08T00:00:00Z"

In Ruby:

require 'rubygems'
require 'curb'

response = Curl::Easy.perform("https://api.newrelic.com/api/v1/accounts/REPLACE_WITH_YOUR_ACCOUNT_ID/applications/REPLACE_WITH_YOUR_APPLICATION_ID/data.xml?metrics[]=HttpDispatcher&field=average_response_time&field=call_count&summary=1&begin=2012-01-01T00:00:00Z&end=2012-01-08T00:00:00Z") do |curl|
  curl.headers["x-api-key"] = "REPLACE_WITH_YOUR_API_KEY"
end
puts response.body_str
Apdex SLA data (v1)

To obtain the Apdex related data for v1, from the command line, type:

curl -gH "x-api-key:REPLACE_WITH_YOUR_API_KEY" "https://api.newrelic.com/api/v1/accounts/REPLACE_WITH_YOUR_ACCOUNT_ID/applications/REPLACE_WITH_YOUR_APPLICATION_ID/data.xml?metrics[]=Apdex&metrics[]=EndUser/Apdex&summary=1&begin=2012-01-01T00:00:00Z&end=2012-01-08T00:00:00Z"

In Ruby:

require 'rubygems'
require 'curb'

response = Curl::Easy.perform("https://api.newrelic.com/api/v1/accounts/REPLACE_WITH_YOUR_ACCOUNT_ID/applications/REPLACE_WITH_YOUR_APPLICATION_ID/data.xml?metrics[]=Apdex&metrics[]=EndUser/Apdex&summary=1&begin=2012-01-01T00:00:00Z&end=2012-01-08T00:00:00Z") do |curl|
  curl.headers["x-api-key"] = "REPLACE_WITH_YOUR_API_KEY"
end
puts response.body_str

Analyze your data

New Relic APM includes several reports in the user interface. To gather, analyze, and visualize data about your software in other formats, use New Relic Insights.

For more help

Additional documentation resources include:

Join the discussion about New Relic APM in the New Relic Online Technical Community! The Technical Community is a public platform to discuss and troubleshoot your New Relic toolset.

If you need additional help, get support at support.newrelic.com.