• EnglishEspañol日本語한국어Português
  • Log inStart now

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 doc explains:

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.


You cannot query timeslice metrics in conjunction with dimensional metrics or event data. Any query involving newrelic.timeslice.value or an apm.* metric can only return APM metrics.

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, you can use the following query format:

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

For information about what functions are supported for what metric data types, see Metric data structure.

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 individual fields using getField()

There are multiple types of Metric data (for example, gauge and count) and each type has several associated fields. For details on the types of fields available, see getField().

You can use getField() to extract those fields. 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 the shorthand syntax 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 © 2024 New Relic Inc.

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