This is an example of how to use the New Relic Data API (v2) to get your application's average error rate over a specific time period. This value appears as a percentage above the Error rate chart on your APM Summary page .
To use the API, you need:
The average percentage appears above the Error rate chart on your app's Summary page . New Relic uses this formula to calculate it:
Application Error Rate = 100 * Errors/all:error_count / (HttpDispatcher:call_count + OtherTransaction/all:call_count)
API commands To obtain the metric timeslice values, use the following three commands. This example uses the same time period for each command, and they are all summarized.
To obtain the error count:
Call to obtain error count $ curl -X GET "https://api.newrelic.com/v2/applications/ $APP_ID /metrics/data.xml" \
> -H "Api-Key: $API_KEY " -i \
> -d 'names[]=Errors/all&values[]=error_count&from=2014-04-01T00:00:00+00:00&to=2014-04-01T23:35:00+00:00&summarize=true'
Example output from error count call "from" : "2014-04-01T00:00:00+00:00" ,
"from" : "2014-04-01T00:35:00+00:00" ,
"to" : "2014-04-01T23:35:00+00:00" ,
"metrics_found" : [ "Errors/all" ] ,
"to" : "2014-04-01T23:35:00+00:00"
To get the HttpDispatcher call count (web application):
Call to obtain HttpDispatcher call count $ curl -X GET "https://api.newrelic.com/v2/applications/ $APP_ID /metrics/data.xml" \
> -H "Api-Key: $API_KEY " -i \
> -d 'names[]=HttpDispatcher&values[]=call_count&from=2014-04-01T00:00:00+00:00&to=2014-04-01T23:35:00+00:00&summarize=true'
Example output from HttpDispatcher call count call "from" : "2014-04-01T00:00:00+00:00" ,
"name" : "HttpDispatcher" ,
"from" : "2014-04-01T00:35:00+00:00" ,
"to" : "2014-04-01T23:35:00+00:00" ,
"metrics_found" : [ "HttpDispatcher" ] ,
"to" : "2014-04-01T23:35:00+00:00"
To get the OtherTransaction call count (non-web app):
Call to obtain OtherTransaction call count $ curl -X GET "https://api.newrelic.com/v2/applications/ $APP_ID /metrics/data.xml" \
> -H "Api-Key: $API_KEY " -i \
> -d 'names[]=OtherTransaction/all&values[]=call_count&from=2014-04-01T00:00:00+00:00&to=2014-04-01T23:35:00+00:00&summarize=true'
Example output from OtherTransaction call count call "from" : "2014-04-01T00:00:00+00:00" ,
"name" : "OtherTransaction/all" ,
"from" : "2014-04-01T00:35:00+00:00" ,
"to" : "2014-04-01T23:35:00+00:00" ,
"metrics_found" : [ "OtherTransaction/all" ] ,
"to" : "2014-04-01T23:35:00+00:00"