RousselTMLEARNING

Article · New Relic: from discovery to expertise

The NRQL language

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.

📄 NRQL: querying all your New Relic data →

My progress

  • ⏱ Estimated time : ≈ 6 min

Sign in to track your progress and take notes. Sign in

⭐ Rate this lesson

5.0 initial rating from the teaching team

Sign in to rate this lesson →

💬 Questions about this lesson

No questions yet: be the first to ask for help or share your configuration.

Ask a question about this lesson →

Recommended Articles

New Relic dashboards: building, sharing and analysing

Building useful dashboards in New Relic: NRQL widgets, chart choice, template variables, facet li...

Alerts, service levels and incidents in New Relic

Setting up useful alerting in New Relic: policies and NRQL conditions, static and anomaly thresho...

Automating New Relic and controlling costs

Managing New Relic as code and keeping the bill under control: NerdGraph API, newrelic CLI, newre...

New Relic APM: agents, OpenTelemetry and distributed traces

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

New Relic: the observability platform at a glance

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

New Relic best practices

Best practices to succeed with New Relic: adoption approach, account organization, naming and tag...

Grail: the Dynatrace data lakehouse and the DQL language

Grail stores all Dynatrace SaaS observability data (logs, metrics, traces, events, entities) with...

Infrastructure, logs and Kubernetes with New Relic

Monitoring servers, containers and Kubernetes with New Relic: infrastructure agent, on-host integ...

DQL in practice: exploring logs and events, notebooks, dashboards and performance

Use the Dynatrace Query Language day to day: explore logs and events, chain commands, parse field...

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!