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.

Viewing all application IDs

If you want to use New Relic's REST API Explorer to obtain the same information as this example, see Retrieving metric timeslice data for your app (Explorer).

To view all of your apps' IDs:

     curl -X GET 'https://api.newrelic.com/v2/applications.json' \
     -H "X-Api-Key:${APIKEY}" -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",
      ...

Finding an 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 "X-Api-Key:${APIKEY}" -i \
     -d "filter[name]=${NAME}"

The output will be the same as shown in the previous example but for the selected application.

Metric name listing guidelines

Listing the available metric names for your application can be a very compute 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:

  • 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 can significantly reduce the amount of data retrieved.
  • If multiple pages of output are required, request the pages and process them serially, obtaining a single page and processing the results before requesting another. Utilize the Cursor pagination feature available for all the List > Metric name endpoints.
  • Do NOT make parallel requests for multiple pages using the page= option. This will result in multiple database queries against the same data. These requests will then be in contention with one another, slowing the response time further.
  • Once you have acquired your metric name list, consider caching this list for future use. In most cases the metric names are not volatile and can be reused, saving processing time.

Listing metric names for your app

To view the metric names available for your application:

     curl -X GET "https://api.newrelic.com/v2/applications/${APPID}/metrics.json" \
     -H "X-Api-Key:${APIKEY}' -i "

The output will be similar to the following. This shows two of the many metric names available and their values. These lists can be long, so the output is paginated. You may need to look at several pages before locating your metric name. 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/${APPID}/metrics.json" \
     -H "X-Api-Key:${APIKEY}" -i \
     -d 'name=Controller/welcome/index' 

Retrieving your app's metric timeslice data values

To view the metric timeslice data available for your application:

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

You can acquire 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
            }
          }
        ]
      }
    ]
  }

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

For example, if you change the above command so it contains two metric names (this is, 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/${APPID}/metrics/data.json' \
     -H 'X-Api-Key:${APIKEY}' -i \
     -d 'names[]=EndUser&names[]=EndUser/Apdex&values[]=call_count&values[]=average_response_time&values[]=score&summarize=true'
 "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": {}
          }
        ]
      }
    ]
  }

EndUser has call_count and average_response_time values associated with it, but not score.

For more help

Additional documentation resources include:

Recommendations for learning more: