One way to query your New Relic data is with the New Relic Query Language (NRQL). This resource explains what NRQL is, when and how you can use it, and basic syntax rules. For more detailed information on querying, including a listing of clauses and functions and example queries, see NRQL syntax, clauses, and functions.
We've included a NRQL Lessons application on our opensource.newrelic.com site to help you quickly see NRQL's value and power by using your own data. To learn how to install and use the NRQL Lessons app, watch this short YouTube video (approx. 2:45 minutes).
Ready to get started? If you haven't already, be sure to sign up for a New Relic account. It's free, forever.
NRQL is an acronym of New Relic query language. It's a query language similar to ANSI SQL (see the syntax). You can use NRQL to retrieve detailed New Relic data and get insight into your applications, hosts, and business-important activity.
Reasons to use NRQL include:
- To answer a question for the purpose of troubleshooting or business analysis
- To create a new chart
- To make API queries of New Relic data (for example, using our NerdGraph API)
NRQL queries can be as simple as fetching rows of data in a raw tabular form to inspect individual events. NRQL can also be used to run powerful calculations on the data before it's presented to you, such as crafting funnels based on how end users are using your site or application.
NRQL is used behind the scenes to generate many of the charts and dashboards in our curated UI experiences:
Some New Relic charts are built using NRQL. One way to start using NRQL is to view a chart's query and then edit it to make your own custom chart.
You can use NRQL in these places:
- New Relic query builder
- NerdGraph: our GraphQL-format API, which includes options for making NRQL queries
NRQL is one of several ways to query New Relic data. For more on all query options, see Query your data.
With NRQL, you can query these New Relic data types:
- Event data from all New Relic products. Examples include:
- Metric timeslice data (metrics reported by APM, browser, and mobile)
Metricdata type (metrics reported by the Metric API and data sources that use that API)
Spandata type (distributed tracing data)
Logdata type (data from New Relic's log management capabilities)
Some data, like relationships between monitored entities, is not available via NRQL but is available using our NerdGraph API.
One way to start using NRQL and to understand what data you have available is to go to a NRQL interface (for example, our query builder), type
FROM, and press space. The interface will suggest available types of data:
To see the attributes available for a specific data type, type:
FROM DATA_TYPE SELECT
and then press space. The interface will suggest available attributes. For example:
To see the complete JSON associated with a data type, including all of its attributes, use the
keyset() attribute. For example:
FROM Transaction SELECT keyset()
NRQL is used behind the scenes to build some New Relic charts and dashboards. One way to learn NRQL is to find one of these NRQL-generated charts and start playing with the NRQL to create new, customized queries and charts:
Charts built with NRQL will have View query as an option. You can then edit and customize that query to see how your changes affect the resulting visualization.
Here's an example NRQL query of
Transaction data, which is reported by APM.
FROM Transaction SELECT average(duration)FACET appName TIMESERIES auto
This would generate a chart that looks like:
Here are some more query examples:
See more NRQL query examples.
The syntax of a NRQL query is similar to standard SQL queries. Here is a breakdown of the structure of a NRQL query:
Basic rules include:
Query string size
The query string must be less than 4 KB.
Syntax for strings
NRQL uses single quotes to designate strings. For example:
Attribute names with spaces
Data type coercion
We don't support data type "coercion." For more information, see Data type conversion.
Use of math functions
NRQL supports subqueries.
NRQL does not have the equivalent of the SQL JOIN function, but you can simulate a JOIN with custom attributes.
Read more about NRQL syntax and functions.