Application error rate example (v2)

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:

Using a Personal API key with the REST API

To use a Personal API key in any of the examples below, replace X-Api-Key:${APIKEY} with Api-Key:${PERSONALAPIKEY}.

Formula

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)

Here is an example of the Error rate chart that appears on your app's APM Summary page.

New Relic APM Overview page: Error rate percentage
APM > (selected app) > Monitoring > Summary: You can use the New Relic REST API v2 to return the average error rate percentage that appears on your app's APM Summary page.

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/${APPID}/metrics/data.xml" \
    -H "X-Api-Key:${APIKEY}" -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
{
    "metric_data": {
        "from": "2014-04-01T00:00:00+00:00",
        "metrics": [
            {
                "name": "Errors/all",
                "timeslices": [
                    {
                        "from": "2014-04-01T00:35:00+00:00",
                        "to": "2014-04-01T23:35:00+00:00",
                        "values": {
                            "error_count": 5
                        }
                    }
                ]
            }
        ],
        "metrics_found": [
            "Errors/all"
        ],
        "metrics_not_found": [],
        "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/${APPID}/metrics/data.xml" \
    -H "X-Api-Key:${APIKEY}" -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
{
    "metric_data": {
        "from": "2014-04-01T00:00:00+00:00",
        "metrics": [
            {
                "name": "HttpDispatcher",
                "timeslices": [
                    {
                        "from": "2014-04-01T00:35:00+00:00",
                        "to": "2014-04-01T23:35:00+00:00",
                        "values": {
                            "call_count": 19608
                        }
                    }
                ]
            }
        ],
        "metrics_found": [
            "HttpDispatcher"
        ],
        "metrics_not_found": [],
        "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/${APPID}/metrics/data.xml" \
    -H "X-Api-Key:${APIKEY}" -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
{
    "metric_data": {
        "from": "2014-04-01T00:00:00+00:00",
        "metrics": [
            {
                "name": "OtherTransaction/all",
                "timeslices": [
                    {
                        "from": "2014-04-01T00:35:00+00:00",
                        "to": "2014-04-01T23:35:00+00:00",
                        "values": {
                            "call_count": 4
                        }
                    }
                ]
            }
        ],
        "metrics_found": [
            "OtherTransaction/all"
        ],
        "metrics_not_found": [],
        "to": "2014-04-01T23:35:00+00:00"
    }
}

For more help

If you need more help, check out these support and learning resources: