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

Dynatrace metrics: Data Explorer, metric selectors, API and dashboards

Use metrics in Dynatrace: built-in and custom metrics, Data Explorer, metric selector syntax, Met...

Digital experience: Browser, mobile and Synthetics

Measuring what users experience with New Relic: browser agent (page load, Core Web Vitals, AJAX, ...

Advanced Grail and DQL: performance, parse, joins, time series, entities and correlation

Writing fast, low-cost DQL queries, parsing text with DPL and JSON, combining sources with lookup...

The HCL language: resources, variables, outputs, data and expressions

Writing Terraform: terraform, provider, resource and data blocks, typed variables with validation...

Using Faro data: queries, dashboards, alerts and GDPR

Query Faro data in Loki (Web Vitals, errors, events), build dashboards and alerts, and comply wit...

Dashboards, reports and alerts in Splunk

Making the most of Splunk searches: reports and scheduling, Dashboard Studio dashboards (data sou...

Automating Grafana: HTTP API, Terraform and dashboard lifecycle

Industrializing Grafana: HTTP API (folders, dashboards, users, data sources), Terraform provider,...

Logs with OpenTelemetry: data model, appenders, correlation and collection

Master the log signal: the LogRecord data model, the Logs Bridge API and appenders (Logback, Log4...

Service-Level Objectives (new platform) in Dynatrace

Defining and steering SLOs in the Dynatrace Service-Level Objectives app: templates and custom DQ...

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!