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 New Relic APM Overview page.

To use the API, you need:

  • Your New Relic REST API key or Admin's API key.
  • Your New Relic application ID (from the URL that your browser shows from the New Relic APM user interface, or from the API Explorer user interface)

Formula

The average percentage appears above the Error rate chart on your app's New Relic APM Overview 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 New Relic APM Overview page.

New Relic APM Overview page: Error rate percentage
APM > (selected app) > Monitoring > Overview: You can use the New Relic REST API v2 to return the average error rate percentage that appears on your app's New Relic APM Overview 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

Recommendations for learning more: