Skip to content

Latest commit

 

History

History
338 lines (288 loc) · 19.4 KB

introduction-nrql-new-relics-query-language.mdx

File metadata and controls

338 lines (288 loc) · 19.4 KB
title tags translate metaDescription redirects freshnessValidatedDate
Get started with NRQL: the language of data
Query your data
NRQL: New Relic query language
Get started
jp
kr
Learn how to query your New Relic data with NRQL, our SQL-like query language.
/docs/insights/new-relic-insights/using-new-relic-query-language/using-nrql
/docs/insights/new-relic-insights/using-new-relic-query-language/get-started-nrql
/docs/insights/nrql-new-relic-query-language/using-nrql/introduction-nrql
/docs/insights/insights-data-sources/default-events-attributes/view-default-data-other-new-relic-products-insights
/docs/query-data/nrql-new-relic-query-language/getting-started/introduction-nrql
/docs/query-your-data/explore-query-data/nrql/nrql
/docs/query-data/nrql-new-relic-query-language/getting-started/introduction-nrql
/docs/query-your-data/explore-query-data/nrql/nrql
/docs/insights/
/docs/rubicon/known-limitations
/docs/insights/known-limitations
/docs/insights/new-relic-insights/troubleshooting/known-limitations
/docs/insights/new-relic-insights
/docs/apis/server-api-v2
/docs/apm/apis/api-v2-examples/server-examples-api-v2
/docs/apm/apis/server-examples-v2/obtaining-available-used-disk-space-api-v2
/docs/apm/apis/server-examples-v2/obtaining-disk-io-rates-api-v2
/docs/apm/apis/server-examples-v2/obtaining-disk-io-data-api-v2
/docs/apm/apis/server-examples-v2/listing-your-server-id-metric-data-api-v2
/docs/apm/apis/server-examples-v2/calculating-average-available-server-memory-api-v2
/docs/apis/server-examples-v2/calculating-average-available-server-memory-v2
/docs/apm/apis/server-examples-v2/getting-average-cpu-percentages-api-v2
/docs/apm/apis/server-examples-v2/listing-cpu-load-data-api-v2
/docs/apm/apis/server-examples-v2/obtaining-load-average-values-server
/docs/apm/apis/server-examples-v2/obtaining-server-networking-data-api-v2
/docs/apm/apis/server-examples-v2/removing-server-dashboard-api-v2
/docs/apis/server-examples-v2/obtaining-available-used-disk-space-v2
/docs/apis/server-examples-v2/obtaining-disk-io-data-v2
/docs/apis/server-examples-v2/listing-your-server-id-metric-data-v2
/docs/apis/server-examples-v2/obtaining-load-average-values-server-v2
/docs/apis/server-examples-v2/obtaining-server-networking-data-v2
/docs/apis/rest-api-v2/server-examples-v2/removing-server-dashboard-v2
/docs/apis/rest-api-v2/server-examples-v2/obtaining-available-used-disk-space-v2
/docs/apis/rest-api-v2/server-examples-v2/listing-your-server-id-metric-data-v2
/docs/apis/rest-api-v2/server-examples-v2/calculating-average-available-server-memory-v2
/docs/apis/server-examples-v2/getting-average-cpu-percentages-v2
/docs/apis/rest-api-v2/server-examples-v2/obtaining-server-networking-data-v2
/docs/servers/rest-api-examples-v2/server-api-examples/obtaining-server-networking-data-v2
/docs/apis/rest-api-v2/server-examples-v2/obtaining-disk-io-data-v2
/docs/apis/rest-api-v2/server-examples-v2/list-your-server-id-metric-data-v2
/docs/apis/rest-api-v2/server-examples-v2/calculate-average-available-server-memory-v2
/docs/apis/server-examples-v2/get-average-cpu-percentages-v2
/docs/apis/rest-api-v2/server-examples-v2/listing-cpu-load-data-v2
/docs/apis/rest-api-v2/server-examples-v2/obtaining-load-average-values-server-v2
/docs/apis/rest-api-v2/server-examples-v2/removing-server-index-v2
/docs/apis/rest-api-v2/server-examples-v2/get-available-used-disk-space-v2
/docs/servers/rest-api-examples-v2/server-api-examples/calculate-average-available-server-memory-v2
/docs/servers/rest-api-examples-v2/server-api-examples/delete-server-index-v2
/docs/servers/rest-api-examples-v2/server-api-examples/get-server-networking-data-v2
/docs/servers/rest-api-examples-v2/server-api-examples/get-load-average-values-server-v2
/docs/intro-new-relic-apis
/docs/servers/rest-api-examples-v2/server-api-examples/get-host-networking-data-v2
/docs/servers/rest-api-examples-v2/server-api-examples/list-your-server-id-metric-data-v2
/docs/servers/rest-api-examples-v2/server-api-examples/calculate-average-available-host-memory-v2
/docs/servers/rest-api-examples-v2/server-api-examples/get-average-cpu-percentages-v2
/docs/servers/rest-api-examples-v2/server-api-examples/get-load-average-values-host-v2
/docs/servers/rest-api-examples-v2/server-api-examples/delete-host-index-v2
/docs/servers/rest-api-examples-v2
/docs/servers/rest-api-examples-v2/server-api-examples
/docs/rubicon/query-history
/docs/insights/query-history
/docs/insights/new-relic-insights/managing-dashboards-and-data/query-history
/docs/insights/new-relic-insights/using-insights-interface/query-history
/docs/insights/new-relic-insights/using-insights-interface/query-history-creating-editing-nrql-queries
/docs/insights/new-relic-insights/using-insights-interface/query-page-creating-editing-nrql-queries
/docs/insights/using-insights-ui/basic-ui-tasks/query-page-create-edit-nrql-queries
/docs/insights/use-insights-ui/basic-ui-tasks/query-page-create-edit-nrql-queries
/docs/insights/nrql-new-relic-query-language/using-nrql/query-page-create-edit-nrql-queries
/docs/insights/use-insights-ui/manage-account-data/query-page-create-edit-nrql-queries
/docs/insights/use-insights-ui/getting-started/introduction-new-relic-insights/
/docs/insights/use-insights-ui/explore-data/query-page-create-edit-nrql-queries/
/docs/insights/use-insights-ui/manage-dashboards/add-customize-nrql-charts/
/docs/insights/use-insights-ui/manage-dashboards/add-customize-metric-charts/
/docs/insights/new-relic-insights/managing-dashboards-data/add-edit-agent-metric-widgets
/docs/insights/new-relic-insights/managing-dashboards-data/add-customize-agent-metric-widgets
/docs/insights/new-relic-insights/managing-dashboards-data/add-customize-metric-widgets
/docs/insights/using-insights-ui/advanced-ui-tasks/add-customize-metric-widgets
/docs/insights/use-insights-ui/manage-dashboards/add-customize-metric-widgets
/docs/insights/nrql-reference
/docs/query-your-data/nrql-new-relic-query-language
/docs/query-your-data/nrql
/docs/query-your-data/nrql-new-relic-query-language/get-started/introduction-nrql-new-relics-query-language
2024-03-19

import queriesnrqlViewQueryforChart from 'images/queries-nrql_screenshot-crop_view-query-for-chart.webp'

import queriesnrqlNrqlExampleTimeseries from 'images/queries-nrql_screenshot-crop_nrql-example-timeseries.webp'

import queriesnrqlEventDefinitionsQueryBuilder from 'images/queries-nrql_screenshot-crop_event-definitions-query-builder.webp'

import queriesnrqlAttributeDefinitionsQueryBuilder from 'images/queries-nrql_screenshot-crop_attribute-definitions-query-builder.webp'

import queriesnrqlconsole from 'images/queriesNrql_screenshot-full_nrql-console.webp'

import nr1NrqlAlertConditions from 'images/nr1_nrql_alert_conditions.webp'

import NerdGraphscreenshot from 'images/apis-and-data_screenshot-crop_NerdGraph-internal-docs.webp'

The New Relic Query Language (NRQL) is a powerful tool you can use to query and understand nearly any type of data, but it can seem overwhelming at first glance. Don't worry! Here's some information to give you a foundational understanding of NRQL, including what it is, how to use it, and some tips and tricks that will help you get the most out of your queries. Once you've learned about NRQL, you can capture and interpret your data, letting you break down the big picture into easily understandable pieces and helping you identify problems as they occur.

Here's a quick video to help introduce you to using NRQL by showing you how to find a query from a dashboard and modify it in the query builder. For more detailed information on querying, including a listing of clauses, functions, and example queries, see our NRQL reference.

If you haven't already, create your free New Relic account below to start monitoring your data today!

What is NRQL?

NRQL is an acronym of New Relic query language. It's a query language similar to ANSI SQL (see the syntax), and you can use it to retrieve detailed New Relic data to get insight into your applications, hosts, and business-important activity. NRQL can help you:

  • Create a new chart
  • Answer a specific question for the purpose of troubleshooting or business analysis
  • Set up NRQL-based alerts (our primary and most powerful type of alert)
  • Make API queries of New Relic data (for example, using our NerdGraph API)

You can use NRQL to create simple queries, such as fetching rows of data in a raw tabular form that gives insight on individual events. You can also use NRQL to run powerful calculations on the data before it's presented to you, such as crafting funnels based on how end users interact with your site or application.

We use NRQL behind the scenes to generate many of the charts and dashboards in our curated UI experiences:

A screenshot of a NRQL query chart

We build many of the charts and visualizations within New Relic using NRQL. You can view a chart's query and then edit it to make your own custom chart as a quick way to get started using NRQL.

Where can you use NRQL? [#where]

You can use NRQL across the platform to access your data. Those places include:

A screenshot showing the query builder

**[one.newrelic.com > All capabilities](https://one.newrelic.com/all-capabilities) > Query your data** You can run a NRQL query in the [query builder](/docs/chart-builder/use-chart-builder/get-started/introduction-chart-builder) within [the platform](/docs/new-relic-one/use-new-relic-one/get-started/introduction-new-relic-one). This NRQL query shows a count of [distributed tracing](/docs/understand-dependencies/distributed-tracing/get-started/introduction-distributed-tracing) spans faceted by their entity names.

A screenshot showing the NRQL console

**[one.newrelic.com](https://one.newrelic.com/) > User profile > NRQL console > Show** You can run a NRQL query from anywhere within New Relic using the [NRQL console](/docs/query-your-data/explore-query-data/query-builder/introduction-query-builder/#query-from-anywhere). This allows you to quickly query your data without leaving your current screen.

A screenshot of a NRQL condition alert

**[one.newrelic.com > All capabilities](https://one.newrelic.com/all-capabilities) > Alerts & AI > Alert conditions (Policies) > (select a policy) > Add a condition**. Click **NRQL**, and then **Next, define thresholds**. You can use NRQL to build [NRQL-based alerts](/docs/alerts-applied-intelligence/new-relic-alerts/alert-conditions/create-nrql-alert-conditions/), our primary and most powerful alert type. This will help to notify you of issues and help you address them in a timely fashion.

A screenshot of the Nerdgraph API

You can also use NRQL with our [NerdGraph API](/docs/apis/graphql-api/tutorials/nerdgraph-graphiql-nrql-tutorial). This gives you more powerful features than querying in the UI (for example, [cross-account querying](/docs/apis/nerdgraph/examples/nerdgraph-nrql-tutorial#cross-account-query), and [asynchronous queries](/docs/apis/nerdgraph/examples/async-queries-nrql-tutorial)). NRQL is one of several ways to query New Relic data. For more on all query options, see [Query your data](/docs/using-new-relic/data/understand-data/query-new-relic-data).

How is NRQL structured? [#nrql-rules]

If you're already familiar with writing 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:

<a href="/docs/insights/new-relic-insights/using-new-relic-query-language/nrql-reference#state-select">SELECT</a> <a href="/docs/insights/new-relic-insights/using-new-relic-query-language/nrql-reference#functions">function(attribute)</a> [<a href="/docs/insights/new-relic-insights/using-new-relic-query-language/nrql-reference#sel-as">AS</a> 'label'][, ...] 
  <a href="/docs/insights/new-relic-insights/using-new-relic-query-language/nrql-reference#sel-from">FROM</a> data type
  [<a href="/docs/insights/new-relic-insights/using-new-relic-query-language/nrql-reference#sel-where">WHERE</a> attribute [comparison] [AND|OR ...]][AS 'label'][, ...]
  [<a href="/docs/insights/new-relic-insights/using-new-relic-query-language/nrql-reference#sel-facet">FACET</a> attribute | function(attribute)]
  [<a href="/docs/insights/new-relic-insights/using-new-relic-query-language/nrql-reference#sel-limit">LIMIT</a> number]
  [<a href="/docs/insights/new-relic-insights/using-new-relic-query-language/nrql-reference#sel-since">SINCE</a> time]
  [<a href="/docs/insights/new-relic-insights/using-new-relic-query-language/nrql-reference#sel-until">UNTIL</a> time]
  [<a href="/docs/insights/new-relic-insights/using-new-relic-query-language/nrql-reference#sel-timezone">WITH TIMEZONE</a> timezone]
  [<a href="/docs/insights/new-relic-insights/using-new-relic-query-language/nrql-reference#sel-compare">COMPARE WITH</a> time]
  [<a href="/docs/insights/new-relic-insights/using-new-relic-query-language/nrql-reference#sel-timeseries">TIMESERIES</a> time]

Here are the rules that NRQL follows:

  <th>
    Details
  </th>
</tr>
  <td>
    The [`SELECT`](#state-select) clause and [`FROM`](#sel-from) clause are required. All other clauses are optional. You can start your query with either `SELECT` or `FROM`.
  </td>
</tr>

<tr>
  <td>
    Query string size
  </td>

  <td>
    The query string must be less than 4 KB.
  </td>
</tr>

<tr>
  <td>
    Case sensitivity
  </td>

  <td>
    * The data type names and attribute names are case sensitive.
    * [NRQL clauses](/docs/insights/new-relic-insights/using-new-relic-query-language/nrql-reference#clauses) and [functions](/docs/insights/new-relic-insights/using-new-relic-query-language/nrql-reference#functions) are not case sensitive.
  </td>
</tr>

<tr>
  <td>
    Syntax for strings
  </td>

  <td>
    NRQL uses single quotes to designate strings. For example:

    ```sql
    ... where traceId = '030a573f0df02c57'
    ```
  </td>
</tr>

<tr>
  <td>
    Non-standard custom event and attribute names
  </td>

  <td>
    Events that we report by default have names that contain alphanumeric characters, colons (`:`), and underscores (`_`). Attribute names can have those characters and periods (`.`). Default-reported names start with a letter. Custom names that don't follow these guidelines must be enclosed with backticks in NRQL queries. For example:

    ```sql
    ... FACET `Logged-in user`
    ```
  </td>
</tr>

<tr>
  <td>
    Data type coercion
  </td>

  <td>
    We don't support data type "coercion." For more information, see [Data type conversion](/docs/insights/nrql-new-relic-query-language/nrql-reference/nrql-syntax-components-functions#type-conversion).
  </td>
</tr>
**NRQL rule**
Required values

If you need any more information, you can check out our NRQL reference to help you build your queries.

What data can you query with NRQL? [#what-you-can-query]

NRQL lets you query nearly every type of our telemetry data, including:

Some data, like relationships between monitored entities, is not available via NRQL but is available using our [NerdGraph API](/docs/apis/nerdgraph/get-started/introduction-new-relic-nerdgraph).

Ready to learn more? We have information on how to use NRQL and how to use charts and dashboards with NRQL. If you want to start using NRQL instead, jump straight into our guided NRQL tutorial.