Listing metric timeslice data for plugin components (v2)

You can use New Relic's REST API to obtain a list of metric timeslice data about your plugin's components (instances), including metric names and values, for the account associated with your API key.

When using these examples, be sure to replace each placeholder (for example, ${COMPONENT_ID}) with its specific ID.

Listing a component's metric names

To obtain a list of the metric names for a single component by its ${COMPONENT_ID}, use this API call:


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

The output (JSON format) lists the metric name and values:


{
  "metrics": [
    {
      "name": "Agent/MetricsReported/count",    <---<<< METRIC_NAME
      "values": [
        "average_response_time",    <---<<< METRIC_VALUES listing
        "calls_per_minute",
        "call_count",
        "min_response_time",
        "max_response_time",
        "average_exclusive_time",
        "average_value",
        "requests_per_minute",
        "standard_deviation"
      ]
    },
    {
      "name": "Component/Client SSL Profiles/Current Cache Entries//Common/clientssl-insecure-compatible[entries]",
      "values": [
        "average_value",
        "total_value",
        "max_value",
        "min_value",
        "standard_deviation",
        "rate",
        "count"
      ]
    },
    ...
  }
}

Listing a specific metric name and values

To obtain a single metric name and the available metric values for a specific plugin component, replace the ${COMPONENT_ID} and ${METRIC_NAME} placeholders with the actual values in the following API call:


curl -X GET "https://api.newrelic.com/v2/components/${COMPONENT_ID}/metrics.json" \
     -H "X-Api-Key:${APIKEY}" -i  \
     -d "name=${METRIC_NAME}"

The output will be similar to what appears when you create an API call for multiple metric names.

Specifying the metric data values

To obtain the metric timeslice data for a specific component, use any of the following API calls. Be sure to replace the ${COMPONENT_ID}, ${APIKEY}, ${METRIC_NAME} and ${METRIC_VALUE} placeholders with the actual values.

If you want to... Use this API call...
Obtain all metric values

Use the metric name to acquire all the metric values:


curl -X GET "https://api.newrelic.com/v2/components/${COMPONENT_ID}/metrics/data.json" \
     -H "X-Api-Key:${APIKEY}" -i \
     -d "names[]=${METRIC_NAME}" 
Obtain a single metric value

Specify the metric name and the metric value:


curl -X GET "https://api.newrelic.com/v2/components/${COMPONENT_ID}/metrics/data.json" \
     -H "X-Api-Key:${APIKEY}" -i \
     -d "names[]=${METRIC_NAME}&values[]=${METRIC_VALUE}" 
Change the default time period and UTC

Specify from and to values, and adjust for your time zone as applicable. For example:


curl -X GET "https://api.newrelic.com/v2/components/${COMPONENT_ID}/metrics/data.xml" \
     -H "X-Api-Key:${APIKEY}" -i \
     -d "names[]=${METRIC_NAME}&values[]=${METRIC_VALUE}&from=2014-03-01T20:59:00+00:00&to=2014-03-01T21:59:00+00:00&summarize=true"
Return average metric data

Include &summarize=true in the API call; for example:


curl -X GET "https://api.newrelic.com/v2/components/${COMPONENT_ID}/metrics/data.xml" \
     -H "X-Api-Key:${APIKEY}" -i \
     -d "names[]=${METRIC_NAME}&values[]=${METRIC_VALUE}&from=2014-03-01T20:59:00+00:00&to=2014-03-01T21:59:00+00:00&summarize=true"

For more help

Additional documentation resources include:

  • Getting a list of plugins (API v2) (using New Relic's REST API to obtain a list of plugins, including each plugin ID, plugin name, and GUID, plus a list of summary metrics available for each of the components or instances)
  • Using the API Explorer (using the API Explorer's user interface to get data in and data out of New Relic)
  • Parts of the API Explorer (a quick reference for how to use each section of the API Explorer)

Recommendations for learning more: