Query APM metric timeslice data with NRQL

New Relic APM reports metric data in the form of metric timeslice data. In New Relic One, you can use NRQL to query and facet this type of data.

Why query APM metric timeslice data?

Metrics are a general and broad category of data, and New Relic reports metrics in several ways. One variety of metric data we refer to as metric timeslice data; this is the type of data used to generate many of the charts in New Relic APM, Mobile, and Browser (for more details, see metric timeslice data).

Historically in New Relic, the only way to query metric timeslice data was to use the Insights metric explorer, which offered limited charting capabilities. Now you can use NRQL to query your APM metric timeslice data and build more powerful queries and charts. This includes being able to query your custom metrics.

For example, you might want to facet your results using a wildcarded segment of a multi-segment metric:

New Relic One chart builder - metric timeslice NRQL query
one.newrelic.com > Chart builder: This shows a NRQL query of metric timeslice data that facets the rate of Flask functions by the wildcarded process name. For the best querying experience, use New Relic One.

Where to query?

We recommend querying APM metric timeslice data using New Relic One chart builder in advanced mode. This query experience offers helpful auto-complete suggestions and gives feedback on query errors.

Once you build a metric timeslice query, you can add it to a custom dashboard.

How to form a query of metric timeslice data

Below is an example query of throughput (metric name HttpDispatcher) faceted by host. After the query is a line-by-line explanation of what this query does.

FROM Metric
  SELECT count(newrelic.timeslice.value)
  WHERE appName = 'MY_APPLICATION'
  AND metricTimesliceName = 'HttpDispatcher'
  FACET host
  TIMESERIES
Query segment What does it do?
FROM Metric

Metric is one of our core data types, and metric timeslice data is attached to this data type. For more about querying Metric data, see Metric query examples.

SELECT count(newrelic.timeslice.value)

newrelic.timeslice.value is a required attribute. This is what specifies a query of metric timeslice data. Here, we use count, but you can use other aggregator functions.

WHERE appName = 'MY_APPLICATION'

You must specify at least one data source. You can select a single application, as shown here, or you can select multiple sources. This query used appName to specify the data source, but you can also use appId or entity.guid.

AND metricTimesliceName = 'HttpDispatcher'

Because Metric is a general data object that can have a large subset of metric names, it's recommended you indicate a specific metricTimesliceName. Alternatively, you can use wildcards to query a segment of a metric name.

FACET host

This optional clause facets the query results by the name of the host. You can facet by any available attribute.

TIMESERIES

This optional clause displays the results in a time-based chart.

For general information on NRQL syntax, including FROM, FACET, and TIMESERIES, see Intro to NRQL.

For more queries, see Query examples.

Facet on a wildcarded metric name segment

Some metric timeslice names include attribute values as segments of the metric name. For example, our APM agents report metrics by tracking the duration of external calls using this format:

External/{externalHost}/all

Here, {externalHost} represents the host name for the outbound network call.

Here's an example of a query that facets on a wildcarded metric timeslice segment:

FROM Metric
  SELECT count(newrelic.timeslice.value)
  WHERE appName = 'My Application'
  WITH METRIC_FORMAT 'External/{externalHost}/all'
  FACET externalHost
  TIMESERIES

In this query, {externalHost} creates a temporary attribute, externalHost, which is then used by FACET externalHost. You can use any name you want, because it's only an attribute that exists for the duration of the query. You should choose a name that does not conflict with an existing attribute name.

For a screenshot of this type of query, see Wildcard query image.

See another wildcard example query.

Recommended aggregator functions

Recommended NRQL aggregator functions include:

  • apdex
  • average
  • sum
  • count
  • rate
  • uniques

Query examples

Some example queries of metric timeslice data:

Explore available attributes

Use the keyset() clause to see what attributes are available for a specific metric timeslice datapoint:

From Metric 
  SELECT keyset() 
  WHERE metricTimesliceName IS NOT NULL
Facet by multiple app names

This query uses WHERE… IN to specify two applications and then facet by them:

FROM Metric
  SELECT count(newrelic.timeslice.value)
  WHERE appName IN ('MY_APPLICATION', 'MY_OTHER_APPLICATION')
  AND metricTimesliceName = 'HttpDispatcher'
  FACET appName
  TIMESERIES
Throughput-per-minute rate

This query displays requests-per-minute chart using the rate function:

FROM Metric 
  SELECT rate(count(newrelic.timeslice.value), 1 minute) as 'HttpDispatcher requests_per_minute' 
  WHERE appName = 'MY_APPLICATION' 
  AND metricTimesliceName = 'HttpDispatcher' 
  TIMESERIES SINCE 3 days ago
Throughput-per-minute rate faceted by wildcarded metric name segment

This query displays a requests-per-minute chart faceted by a wildcarded metric name segment:

FROM Metric 
  SELECT rate(count(newrelic.timeslice.value), 1 minute) 
  WHERE appName = 'MY_APPLICATION' 
  WITH METRIC_FORMAT 'OtherTransaction/ResqueJob/{job}/perform' 
  TIMESERIES 1 minute 
  FACET job 
  SINCE 3 hour ago
Facet by host-related attributes

This query displays a requests-per-minute chart faceted by host name:

FROM Metric 
  SELECT count(newrelic.timeslice.value) as 'HttpDispatcher requests_per_minute' 
  WHERE appName = 'MY_APPLICATION' 
  AND metricTimesliceName = 'HttpDispatcher' 
  TIMESERIES SINCE 3 hours ago 
  FACET host 
  LIMIT 20

Instead of using host, you can facet by other host-related attributes, like host.bootId.

Query of average duration of a metric

This queries the average duration for a metric using average:

FROM Metric 
  SELECT average(newrelic.timeslice.value) as 'HttpDispatcher average duration' 
  WHERE appName = 'MY_APPLICATION' 
  AND metricTimesliceName = 'HttpDispatcher' 
  TIMESERIES SINCE 3 days ago
Query custom metrics

You can query custom metrics as you would query any other metric timeslice data. Here's an example of using the wildcard feature to facet on one segment of a custom metric name:

FROM Metric 
  SELECT count(newrelic.timeslice.value) 
  WHERE appName = 'MY APP' 
  WITH METRIC_FORMAT 'Custom/Labels/{action}' 
  TIMESERIES FACET action

For more help

Recommendations for learning more: