This document contains:
- How to view and query your metrics
- Example metric queries
- How to query multiple metrics with wildcards
- How to explore metric 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.
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:
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
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
FROM Metric select sum(container_cpu_usage_seconds_total)WHERE clusterName = 'foo'FACET containerNameTIMESERIES
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 containerNameTIMESERIES
The previous examples demonstrate basic forms of metric queries, but NRQL can also be used to chart, explore, and analyze metric data.
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
FACETresults 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:
If used in a query,
myNeatProcess.%.duration will return results for all three of the algorithms above. If you later create new algorithms named
algorithm6, the same query will return results for all six algorithms.
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
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.