Before using any tool, it's best to know how to use it. There's a process to creating, structuring, and writing queries with NRQL. Understanding the rules of querying with NRQL enables you to get the most from your data. Even if you've never queried anything before, just a basic understanding the rules allows you to access (almost) any data you need and visualize them in charts and dashboards.
If you're already familiar with SQL queries, you'll be happy to know that NRQL has a lot of similarities. Here's a quick breakdown of the structure of a NRQL query:
NRQL's basic rules are as follows:
Query string size
The query string must be less than 4 KB.
Syntax for strings
NRQL uses single quotes to designate strings. For example:
Non-standard custom event and attribute names
Events that we report by default have names that contain alphanumeric characters, colons (
Data type coercion
We don't support data type "coercion." For more information, see Data type conversion.
Use of math functions
NRQL supports subqueries.
You can add comments to your NRQL queries. Learn more about comments.
These are the basic rules for NRQL, and we have more information in our NRQL reference to help you build your queries.
One of the best ways to learn how to use NRQL is to access a New Relic query tool and use it to explore your data. Here's an example of exploring your data using the query builder and the suggested entries from the interface.
Don't be afraid to play with your data! You won't break anything using any of our query interfaces, so feel free to explore early and often!
The query begins with
FROM followed by space. The interface suggests available types of data, and
Transaction is chosen from that list.
Next, an attribute is chosen using
SELECT, and the query looks as follows:
FROM Transaction SELECT
Pressing space again causes the interface to suggest available attributes. In the example below,
appId is chosen.
The result is a very basic NRQL query using the required clause and statement (
SELECT), and it provides a list of transactions and the associated
appId for each, as shown below.
Another great way to explore your data is to go into any existing dashboards you have, click View query, and run your chart in the query builder.
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 of a slightly more in-depth NRQL query of
Transaction data, which is reported by APM. For this query:
Transactionis the chosen data type
Selectis used to determine the average duration
- Results are grouped by appName using
Timeseriesis used to display the data over an automated timespan.
FROM TransactionSELECT average(duration)FACET appNameTIMESERIES auto
This would generate a chart that looks like:
Here are some more query examples:
Ready to learn more? Be sure to check out our introduction to NRQL if you haven't already, or learn how to use charts and dashboards with NRQL. If you want to start using NRQL right away, jump straight into our guided NRQL tutorial.