---
title: "New Relic data source for Grafana | Grafana Enterprise Plugins documentation"
description: "New Relic data source for Grafana The New Relic data source plugin allows you to query and visualize New Relic APM (Application Performance Monitoring) and Insights from within Grafana."
---

# New Relic data source for Grafana

The New Relic data source plugin allows you to query and visualize New Relic APM (Application Performance Monitoring) and Insights from within Grafana.

## Requirements

This plugin has the following requirements:

- A New Relic account
- One of the following account types:
  
  - Available for users with a [Grafana Cloud](/products/cloud/) Free, Advanced or Trial account or with an [activated Grafana Enterprise license](/docs/grafana/latest/enterprise/license/activate-license/).

## Known limitations

- Ad-hoc filters are not currently supported.
- NRQL queries with multiple `FACET` fields are not supported.

## Install the New Relic data source plugin

To install the data source, refer to [Installation](/grafana/plugins/grafana-newrelic-datasource/?tab=installation).

## Get an API key and account ID from New Relic

You will need your personal API key/user API key, refer to [New Relic API Key](https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys#personal-api-key). You will also need your account ID from New Relic, refer to [Account ID](https://docs.newrelic.com/docs/accounts/install-new-relic/account-setup/account-id).

## Configure the data source in Grafana

[Add a data source](/docs/grafana/latest/datasources/add-a-data-source/) by filling in the following fields:

Expand table

| Field names                     | Descriptions                                                                                                                                                                                   |
|---------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Name                            | Enter a name for this particular New Relic data source.                                                                                                                                        |
| Personal API Key / User API key | To find your New Relic API key, refer to [Get an API key and account ID from New Relic](#get-an-api-key-and-account-id-from-new-relic).Enter a name for this particular New Relic data source. |
| Account ID                      | Enter your New Relic Account ID. To find your New Relic Account ID, refer to [Get an API key and account ID from New Relic](#get-an-api-key-and-account-id-from-new-relic).                    |
| Region                          | Enter your region hosting your service.                                                                                                                                                        |

### Configure the data source with provisioning

Data sources can be configured with Grafana’s provisioning system. You can read more about how it works and all the settings you can set for data sources on [Provisioning Grafana](/docs/grafana/latest/administration/provisioning/#datasources).

Here is an example for provisioning this data source

YAML ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```yaml
apiVersion: 1
datasources:
  - name: New Relic
    type: grafana-newrelic-datasource
    jsonData:
      region: EU
    secureJsonData:
      accountId: 1111111
      personalApiKey: Personal API Key
```

## Query the data source

The service can be `Metrics`, `Data Explorer`, `NRQL Editor`, `Logs` or `Traces`. To learn more about NRQL Editor/Insights, refer to [Insights](https://docs.newrelic.com/docs/insights/).

### Metrics

If you do not find an option in these dropdown boxes you can still select the option by selecting `Create: (your text)`.

Expand table

| Field names | Descriptions                                                                                                                                                                    |
|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Application | Select the source application. Start typing in the dropdown box to find your source.                                                                                            |
| Metric      | Select the metric namespace you wish to view from the expanding lists.                                                                                                          |
| Value       | Enter the metric value you want returned.                                                                                                                                       |
| Alias By    | You can combine plain text with the following variables: `$__nr_metric` is the metric name e.g. `CPU/User time`. `$__nr_metric_value` is the metric value e.g. `average_value`. |

> There is a little search icon next to Application/Metric selectors. When you have lots of applications or metrics, you can use them to search those. Search icon wil result relevant 1000 results at any time. You can use name filter to filter out the results if you have more than 1000 applications/metrics. Note: Search is case-sensitive.

### Data Explorer

Data explorer allows you to query [New Relic Insights data](https://docs.newrelic.com/docs/insights/) without writing raw NRQL.

Once you switch to **Data Explorer** mode, the query editor will be pre-configured with a default query. You can make your own data explorer query by customizing the following fields:

Expand table

| Field names | Descriptions                                                                                                                                                                                                                                                                                                                                                     |
|-------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| From        | Use this field to specify the data type you wish to query. If this field is updated, the remaining part of the query will be reset to default.                                                                                                                                                                                                                   |
| Select      | You can specify one or more aggregation. in the SELECT section. This can be also used to perform arithmetic operation over two aggregated fields. Optionally, Each item in the `SELECT` can be filtered using NRQL `FILTER` queries.                                                                                                                             |
| Where       | *(optional)* Specify the raw condition of NRQL filter. Example `appName = 'something' AND serverName in ('server1','server2') AND city in (${cities:singlequote})`. This field accepts grafana variables.                                                                                                                                                        |
| Facet       | *(optional)* Use this field to separate and group your results by attribute values. Use `FACET BY CASES` to break out your data by more complex conditions than possible with `FACET`                                                                                                                                                                            |
| Time Filter | *(optional)* Configure this field to filter the data based on time range. Select `Dashboard time` to filter the data based on Grafana’s selected time range. By default, Grafana’s time range is used.                                                                                                                                                           |
| Format      | This can be one of `TimeSeries` or `Table`. The default is `TimeSeries`. If TimeSeries is chosen, then the `TIMESERIES` keyword is added to the query and your data will be in time series format broken out by a specified period of time. If the `Table` is chosen, then data will not be aggregated by time. Use `Table` mode, in case if you want a summary. |
| Interval    | *(optional)* When selecting the `timeseries` format above, you can optionally configure the interval of your time series aggregation.                                                                                                                                                                                                                            |
| Slide By    | *(optional)* When selecting `timeseries` format and `custom` interval, optionally use `slide by` field to specify the sliding time window range.                                                                                                                                                                                                                 |

You can preview the NRQL query based on your options in the Preview section. If you want to further customize the query, you can switch to the raw NRQL editor by clicking **Switch to NRQL Editor**.

Read more about NRQL syntax in the [New Relic documentation](https://docs.newrelic.com/docs/query-your-data/nrql-new-relic-query-language/get-started/nrql-syntax-clauses-functions/) page.

### NRQL editor *(Insights)*

For a New Relic Query Language intro, refer to [Introduction to NRQL](https://docs.newrelic.com/docs/query-your-data/nrql-new-relic-query-language/get-started/introduction-nrql-new-relics-query-language/).

Code completion will be displayed once typing begins. To select a completion option, highlight the desired option with the arrow keys and press *Tab* to select.

The editor supports the following macros.

Expand table

| Macro syntax                                                              | Descriptions                                                                                                                                                                                                                                                                          |
|---------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `$__timeFilter`                                                           | This will use your Grafana dashboard’s time range in the query by interpolating `$__timeFilter` to `SINCE <from> UNTIL <to>` .                                                                                                                                                        |
| `$__timeSeries(time range,corresponding aggregation,default aggregation)` | This macro can be used to set the aggregation dynamically based on timerange. Example: `$__timeSeries(60m,1 MINUTE,MAX)`. This macro will expand to `TIMESERIES 1 MINUTE` when the dashboard interval is less than or equal to 60 mins. Otherwise it will expand to `TIMESERIES MAX`. |

Example:

SQL ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```sql
SELECT average(value) FROM $event_template_variable $__timeFilter TIMESERIES
```

> Make sure to include `$__timeFilter` macro in your NRQL query. Otherwise your results will not sync to grafana dashboards’ timerange.

### Synthetics Queries

New Relic Synthetics data can be queried from the `SyntheticCheck` and `SyntheticRequest` tables using NRQL Editor/Insights.

For example, the query below returns the count of all requests by response status.

SQL ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```sql
SELECT count(*) FROM SyntheticRequest FACET responseStatus $__timeFilter
```

The query below returns the success rate of all the monitors.

SQL ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```sql
SELECT (
    filter(count(*),WHERE result = 'SUCCESS')
    / filter(count(*), WHERE result IN ('SUCCESS','FAILED'))
    * 100
) as 'Success Rate' FROM SyntheticCheck
FACET monitorName $__timeFilter TIMESERIES
```

For more details about the Synthetic monitoring querying, refer to [Events reported by synthetic monitoring](https://docs.newrelic.com/docs/telemetry-data-platform/understand-data/event-data/events-reported-synthetic-monitoring/)

### Logs

The logs service of the plugin allows you to query and view the logs stored in New Relic `Log` table. The plugin uses NerdGraph NRQL queries to perform the search. Plugin uses `SELECT * FROM Log WHERE <xxxx> SINCE <xxxxx> UNTIL <xxxxx> ORDER BY <xxxxx> LIMIT MAX` query to perform the logs search and presents the results in grafana log format. Logs are filtered automatically the dashboard time range. You can optionally configure the following fields to filter the data

Expand table

| Field    | Description                                                                                                      |
|----------|------------------------------------------------------------------------------------------------------------------|
| Query    | Provide NRQL filter query when searching for logs. Ex: `message LIKE '%ERROR%' AND container_name = 'petclinic'` |
| order By | By default results will be ordered by timestamp descending. You can optionally change this to ascending.         |

Maximum of 2000 records will be returned in the logs search query (NRQL API limitations). But logs volume panel in the explore can give you hints about the existence of more logs in the entire time range and then you can narrow down the explore’s timerange to specific period.

If a log row find a field such as `traceId`/`traceid`/`trace.id`, logs panel will give you a link to corresponding trace view.

### Traces

The traces service of the plugin allows you to query and view the traces stored in New Relic. This can be done by searching for traces individually, or through a list.

Expand table

| Field    | Description                                                                                                               |
|----------|---------------------------------------------------------------------------------------------------------------------------|
| Trace ID | Provide the trace id here when using the Trace view. Ex: `951ae3313c093aa3278cbc27c0714c94`                               |
| Query    | Provide NRQL filter query when searching for traces. Ex: `parentId IS NULL AND duration > 0.05 AND appName = 'petclinic'` |

You can find more about the New Relic tracing API at the [New Relic documentation site](https://docs.newrelic.com/docs/distributed-tracing/ui-data/query-distributed-trace-data/).

### Templates and variables

To add a new New Relic query variable, refer to [Add a query variable](/docs/grafana/latest/variables/variable-types/add-query-variable/). Use your New Relic data source as your data source for the following available queries.

Expand table

| Endpoints                              | Description                                  |
|----------------------------------------|----------------------------------------------|
| applications                           | List of available applications               |
| applicationNames                       | List of available applications names         |
| applications/{application\_id}/metrics | List of available metrics for an application |

New Relic query can return relative endpoints (excluding file extensions). For more information, refer to [New Relic REST API](https://docs.newrelic.com/docs/apis/rest-api-v2)

After creating a variable you can use it in your New Relic queries by using variable syntax. For more information refer to [Variable syntax](/docs/grafana/latest/variables/syntax/). For more information about variables, refer to [Templates and variables](/docs/grafana/latest/variables/).

### Import a dashboard for New Relic

Follow these [instructions](/docs/grafana/latest/dashboards/export-import/#importing-a-dashboard) for importing a dashboard.

Imported dashboards can be found in Configuration &gt; Data Sources &gt; select your New Relic data source &gt; select the Dashboards tab to see available pre-made dashboards.

## Get the most out of the plugin

- Add [Annotations](/docs/grafana/latest/dashboards/annotations/).
- Configure and use [Templates and variables](/docs/grafana/latest/variables/).
- Add [Transformations](/docs/grafana/latest/panels/transformations/).
- Set up alerting; refer to [Alerts overview](/docs/grafana/latest/alerting/).
