RousselTMLEARNING

Observability

NRQL: querying all your New Relic data

Mastering NRQL, New Relic's query language: SELECT … FROM structure, filters, aggregation functions, FACET, TIMESERIES, COMPARE WITH, percentiles and histograms, advanced functions (filter, funnel, rate, percentage), subqueries and JOIN, dimensional metrics and queries through NerdGraph.

1. Query structure #

SQL, adapted to time series.

Clauses #

NRQL clauses
ClauseRoleExample
SELECTfunction(s) to compute, with an AS aliasSELECT average(duration) AS 'latence'
FROMone or more event typesFROM Transaction, TransactionError
WHEREfilter: =, !=, LIKE, IN, IS NULL, RLIKEWHERE appName = 'boutique' AND http.statusCode >= 500
FACETgroups (10 groups by default)FACET name LIMIT 20
SINCE / UNTILtime range (60 minutes by default)SINCE 1 day ago UNTIL 1 hour ago
TIMESERIESsplits into buckets for a chartTIMESERIES 5 minutes
COMPARE WITHoverlays a previous periodCOMPARE WITH 1 week ago
LIMITnumber of rows or groupsLIMIT MAX

First queries #

NRQL console
SELECT count(*) FROM Transaction SINCE 30 minutes ago
SELECT average(duration), percentile(duration, 95, 99) FROM Transaction WHERE appName = 'boutique' FACET name
SELECT count(*) FROM TransactionError FACET error.class SINCE 1 day ago
SELECT * FROM Log WHERE message LIKE '%timeout%' SINCE 15 minutes ago LIMIT 100
Good to know : Attribute names containing special characters are written with backticks: `http.response.status_code`. Strings go in single quotes.

2. Functions #

Aggregating and computing.

Common functions #

FunctionResult
count(*), uniqueCount(attr)event count, number of distinct values (approximate above 256)
average, sum, min, max, medianclassic statistics
percentile(attr, 95, 99)percentiles: the real perceived latency
histogram(attr, 2, 20)distribution in 20 buckets up to 2
percentage(count(*), WHERE error IS true)share of events matching a condition
filter(count(*), WHERE …)aggregate restricted to a condition, several per query
rate(count(*), 1 minute)throughput normalized per time unit
latest(attr), earliest(attr)most recent / oldest value
apdex(duration, t: 0.5)Apdex score
funnel(session, WHERE page = '/panier', WHERE page = '/paiement')conversion funnel

Analysis queries #

-- Error rate per service, compared with last week
SELECT percentage(count(*), WHERE error IS true) FROM Transaction FACET appName SINCE 1 day ago COMPARE WITH 1 week ago

-- Several indicators in one query
SELECT filter(count(*), WHERE http.statusCode >= 500) AS '5xx', filter(count(*), WHERE http.statusCode = 404) AS '404' FROM Transaction TIMESERIES

-- Group values into readable categories
SELECT count(*) FROM Transaction FACET CASES(WHERE duration < 0.2 AS 'fast', WHERE duration < 1 AS 'ok', WHERE duration >= 1 AS 'slow')

3. Advanced NRQL #

Subqueries, metrics and API.

Subqueries and nested aggregation #

-- Nested aggregation: maximum throughput per minute
SELECT max(n) FROM (SELECT count(*) AS n FROM Transaction TIMESERIES 1 minute) SINCE 1 day ago

-- Subquery: transactions of the 5 busiest hosts
SELECT average(duration) FROM Transaction WHERE host IN (SELECT hostname FROM SystemSample FACET hostname ORDER BY average(cpuPercent) LIMIT 5) FACET host

NRQL also supports JOIN between a main query and a faceted subquery, handy to enrich events with a lookup table (lookup tables imported as CSV).

Dimensional metrics #

Metric data (OpenTelemetry, Prometheus, integrations) is pre-aggregated. Query it by metric name, with functions suited to the type: SELECT rate(sum(http.server.requests), 1 minute) FROM Metric FACET service.name TIMESERIES. Events to metrics create metrics from events for long, cheap retention.

NRQL via the API #

curl -s https://api.newrelic.com/graphql \
  -H 'Content-Type: application/json' -H "API-Key: $NEW_RELIC_API_KEY" \
  -d '{"query":"{ actor { account(id: '"$NEW_RELIC_ACCOUNT_ID"') { nrql(query: \"SELECT count(*) FROM Transaction SINCE 1 hour ago FACET appName\") { results } } } }"}' | jq '.data.actor.account.nrql.results'
Best practice : Use the New Relic AI assistant to turn a question into NRQL, then review and adjust the query: a good way to learn the syntax.

Commands to know #

Commands to know
  • SELECT percentile(duration, 95) FROM Transaction FACET name : p95 latency per transaction
  • … SINCE 1 day ago COMPARE WITH 1 week ago : compare with last week
  • SELECT percentage(count(*), WHERE error IS true) FROM Transaction : error rate
  • SELECT keyset() FROM Transaction : list available attributes
  • SHOW EVENT TYPES SINCE 1 week ago : list event types

Sources #

Checked in November 2026: New Relic evolves its platform continuously (UI, plans, limits); check the documentation before relying on a detail.

Related articles

New Relic: the observability platform at a glance

Discover New Relic: history, the unified platform and NRDB, MELT data types, entities and golden signals, acc…

New Relic APM: agents, OpenTelemetry and distributed traces

Instrumenting applications with New Relic: language agents, configuration, transactions and Apdex, distribute…

Infrastructure, logs and Kubernetes with New Relic

Monitoring servers, containers and Kubernetes with New Relic: infrastructure agent, on-host integrations, clo…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!