List your app ID and metric timeslice data (v2)

Here are examples of how to use the New Relic REST API (v2) to get metric names and average values for a specific application ID and API key. The examples also show different time ranges.

When acquiring data, the values returned may be affected by the time period you specify and the way the data is stored. For more information, see Extracting metric timeslice data.

List all application IDs

You can also use New Relic's REST API Explorer to get the same metric timeslice data for your app information as this example.

To view all of your apps' IDs, use the following command.

curl -X GET 'https://api.newrelic.com/v2/applications.json' \
     -H "Api-Key:$API_KEY" -i 

The output will be an array of data where the element is an application and the data associated with it. For example, here are the first two elements for app ID 96785 ("GreatTimes Staging") and 1622 ("GreatTimes Prod"):

{
  "applications": [
    {
      "id": 96785,
      "name": "GreatTimes Staging",
      "language": "ruby",
      "health_status": "gray",
      ...
    },
    {
      "id": 1622,
      "name": "GreatTimes Prod",
      "language": "ruby",
      "health_status": "green",
      ...

List app ID by name

To view a specific app's ID if you know the name, substitute the name for $NAME in the following command:

curl -X GET 'https://api.newrelic.com/v2/applications.json' \
     -H "Api-Key:$API_KEY" -i \
     -d "filter[name]=$NAME"

The output will be the same as shown in the list all app IDs example but only for the specific application.

Metric name listing guidelines

Listing the available metric names for your application can be a very intensive operation and should only be used as necessary. Listing a large number of metric names may have a detrimental effect on your responsiveness, as well as that of other uses and may lead to invoking overload protection.

Follow these guidelines to optimize your use:

Listing metric names Guidelines
Metric names

Carefully consider the metric names you need. If you know any part of the metric name, use the name= filter to limit the amount of data returned. This filter is a simple character match (no regular expression is available), but it can significantly reduce the amount of data retrieved.

Cache

Once you get your metric names, consider caching this list for future use. In most cases the metric names are not volatile and can be reused, saving processing time.

List metric names for your app

To view the metric names available for your application:

     curl -X GET "https://api.newrelic.com/v2/applications/$APP_ID/metrics.json" \
     -H "Api-Key:$API_KEY' -i "

The output will be similar to the following. This shows two of the many metric names available and their values. These lists may be long. Please consider the guidelines for listing your metric names.

{
  "metrics": [
    {
      "name": "ActiveRecord/Account/create",
      "values": [
        "average_response_time",
        "calls_per_minute",
        "call_count",
        "min_response_time",
        "max_response_time",
        "average_exclusive_time",
        "average_value",
        "requests_per_minute",
        "standard_deviation"
      ]
    },
    ...
    {
      "name": "Apdex/members/destroy",
      "values": [
        "s",
        "t",
        "f",
        "count",
        "score",
        "value",
        "threshold",
        "threshold_min"
      ]
    },
    ...

Filter your metric name output, to return a smaller list, by specifying the name= filter like this:

     curl -X GET "https://api.newrelic.com/v2/applications/$APP_ID/metrics.json" \
     -H "Api-Key:$API_KEY" -i \
     -d 'name=Controller/welcome/index' 

Get your app's metric timeslice data values

To view the metric timeslice data for your application:

curl -X GET 'https://api.newrelic.com/v2/applications/$APP_ID/metrics/data.json' \
     -H 'Api-Key:$API_KEY' -i \
     -d 'names[]=EndUser&values[]=call_count&values[]=average_response_time&summarize=true'
One metric name, multiple values

You can get multiple values from the same metric name in a single call, as shown in this example.

"metric_data": {
    "from": "2014-05-20T23:41:15+00:00",
    "to": "2014-05-21T00:11:15+00:00",
    "metrics": [
      {
        "name": "EndUser",
        "timeslices": [
          {
            "from": "2014-05-20T23:39:00+00:00",
            "to": "2014-05-21T00:08:59+00:00",
            "values": {
              "call_count": 724,
              "average_response_time": 2110
            }
          }
        ]
      }
    ]
  }
Multiple metric names, individual values

If you request values from multiple metrics that don't share all requested value fields, you can only get the values from one metric name at a time.

For example, if you change the command so it contains two metric names (using two "names[]=" conditions and corresponding "values[]=" conditions), only the associated values for the first metric name (EndUser) will be returned.

curl -X GET 'https://api.newrelic.com/v2/applications/$APP_ID/metrics/data.json' \
     -H 'Api-Key:$API_KEY' -i \
     -d 'names[]=EndUser&names[]=EndUser/Apdex&values[]=call_count&values[]=average_response_time&values[]=score&summarize=true'

The EndUser name in this example has call_count and average_response_time values associated with it, but not score.

"metric_data": {
    "from": "2014-05-20T23:41:15+00:00",
    "to": "2014-05-21T00:11:15+00:00",
    "metrics": [
      {
        "name": "EndUser",
        "timeslices": [
          {
            "from": "2014-05-20T23:39:00+00:00",
            "to": "2014-05-21T00:08:59+00:00",
            "values": {
              "call_count": 724,
              "average_response_time": 2110
            }
          }
        ]
      },
      {
        "name": "EndUser/Apdex",
        "timeslices": [
          {
            "from": "2015-03-31T20:33:00+00:00",
            "to": "2015-03-31T21:02:59+00:00",
            "values": {}
          }
        ]
      }
    ]
  }

For more help

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