• Log in

Query the Metric data type

When metrics are reported to New Relic via the Metric API (including from integrations that use that API), the data is reported as the Metric data type and is available for querying.

This document contains:

Query APM metric timeslice data

APM reports a specific type of data that we call metric timeslice data. For how to query that, see Query metric timeslice data.

For information about other types of metrics, see Metric data types.

View and query your metrics

You can use NRQL to query your metric data in the query builder or using our NerdGraph API.

To query a metric, use the following query format:

FROM Metric SELECT function(metric_name) WHERE attribute=value FACET attribute TIMESERIES

Below are the functions supported for each metric type:

Metric type

Supported functions


count, sum, min, max, and average




count, sum, min, max, average, and latest

Add the names of the metrics you want to chart with the appropriate value functions in the SELECT clause. The WHERE and FACET clauses can be used with attribute values. Remember to include the keyword TIMESERIES if you want to chart the data.

This example demonstrates how you could chart the CPU usage in seconds for cluster foo . This query breaks down CPU usage by container, given a count metric named container_cpu_usage_seconds_total with the attributes containerName and clusterName:

FROM Metric select sum(container_cpu_usage_seconds_total)
WHERE clusterName = 'foo'
FACET containerName

If you want the CPU usage per minute (the rate of change), then you can add the rate function to the query above.

FROM Metric select rate(sum(container_cpu_usage_seconds_total), 1 minute)
WHERE clusterName = 'foo'
FACET containerName

View example metric queries

The previous examples demonstrate basic forms of metric queries, but NRQL can also be used to chart, explore, and analyze metric data.

Query multiple metrics with wildcards

Wildcards are represented in NRQL by the % character. If you want to query multiple metrics that use a standard naming convention, you can use the wildcard feature to return results for all of them without having to specify each metric name individually.

Wildcards can help you:

  • Aggregate metrics together and chart the results
  • FACET results by metric name in a chart
  • Find and chart all metrics matching a given naming convention

Wildcards are particularly helpful if you later add new metrics matching an existing naming convention. By using % instead of writing out each metric name in your query, you won't have to rewrite the query when you add new metrics.

Let's say you have multiple algorithms that perform a similar task. You can define the following metrics, which show the duration of the different algorithms:

  • myNeatProcess.algorithm1.duration
  • myNeatProcess.algorithm2.duration
  • myNeatProcess.algorithm3.duration

If used in a query, myNeatProcess.%.duration will return results for all three of the algorithms above. If you later create new algorithms named algorithm4, algorithm5, and algorithm6, the same query will return results for all six algorithms.

Return results for invidual fields using getField()

Metrics have multiple fields associated with them, and each field contains its own unique values. If you would like to extract one of those values using a query, you can do that with getField().

For example, if you want to use a single value within a metric to do a comparison in a WHERE clause, you can use getField(metricName, field) or metricName[field].

Explore metric data

The NRQL keyset and uniques functions can be used together with the metricName attribute (available on all metrics) to perform tasks like listing all the available metrics in your account or discovering the attributes available on a particular metric.

Copyright © 2022 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.