• Log inStart now

NerdGraph tutorial: Query your data using NRQL

You can use our NerdGraph API to make NRQL queries.

Overview of querying with NerdGraph

You can run NRQL queries in the New Relic platform query builder or with NerdGraph. NerdGraph gives you the ability to do some things you can't do from the UI, such as query across multiple accounts, and run asyncronous queries.

Requirements

Basic NRQL queries with NerdGraph

To make basic NRQL queries using NerdGraph:

  1. Go to the NerdGraph explorer.
  2. Pass the NRQL query as a string argument to the NRQL object, and include the results field in your NerdGraph query.

For example, to get a count of all transaction events in the last hour, use the following query:

{
   actor {
      account(id: YOUR_ACCOUNT_ID) {
         nrql(query: "SELECT count(*) FROM Transaction SINCE 1 HOUR AGO") {
            results
         }
      }
   }
}

This query example would return a result like this:

{
   "data": {
      "actor": {
         "account": {
            "nrql": {
               "results": [
                 {
                  "count": 1000
                 }
                ]
            }
         }
      }
   }
}

Cross-account queries

With NerdGraph, you can run a query across more than one account, which you can't do in the query builder. You'll need the account IDs for the accounts you want to query.

Here's an example of running a cross-account NRQL query:

{ 
   actor {
      nrql(accounts: [ACCOUNT_ID_1, ACCOUNT_ID_2, ACCOUNT_ID_3], 
      options: {}, 
      query: "NRQL_QUERY", 
      timeout: 70) 
         {   results}  
   }  
}

For how to create a dashboard with data from multiple accounts, see the NerdGraph dashboard tutorial.

Create embeddable charts

In addition to returning raw data, you can fetch embeddable chart links for the data to use in an application. For example, instead of a single count of transaction, you can create a chart that illustrates a timeseries of bucketed counts over time. Add TIMESERIES to your query with embeddedChartUrl:

{
   actor {
      account(id: YOUR_ACCOUNT_ID) {
         nrql(query: "SELECT count(*) from Transaction TIMESERIES") {
            embeddedChartUrl
         }
      }
   }
}

This NerdGraph query example returns the URL for the chart in the following response:

{
   "data": {
      "actor": {
         "account": {
            "nrql": {
               "embeddedChartUrl": "https://chart-embed.service.newrelic.com/charts/EMBEDDABLE-CHART-ID"
            }
         }
      }
   }
}

If you view the embedded chart URL using any standard HTTP client, it returns an image showing a visualization of the response to the query you submitted. These charts follow the same embedded chart rules as embedded charts that are created elsewhere. To change the style of the data visualization, pass a chartType argument to embeddedChartUrl.

Suggested facets

When using NerdGraph to explore your data, you can use the suggestedFacets field to return suggested attributes for use in faceted NRQL queries.

Longer-running queries

If you need to run longer-running NRQL queries, see Asynchronous queries.

Other querying options

NerdGraph gives you other querying options, such as:

Copyright © 2022 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.