New Relic template variables
Use template variables to create dynamic, reusable dashboards. Instead of hard-coding values like application names or metric namespaces, you can use variables that users can change from a drop-down at the top of the dashboard.
Before you begin
- Configure the New Relic data source.
- Familiarize yourself with Grafana template variables.
Supported variable query types
The New Relic data source supports the following variable query types:
Create a query variable
To create a query variable:
- Navigate to your dashboard and click Dashboard settings (gear icon).
- Click Variables in the left-side menu.
- Click Add variable.
- Select Query as the variable type.
- Select the New Relic data source.
- Choose a Query type and configure the query.
- Click Apply.
Query type examples
The following sections describe each query type with examples.
Insights / NRQL
Use a NRQL query to populate variable values. This is the default query type.
The default query returns a list of unique application names:
SELECT uniques(appName) FROM TransactionOther examples:
List unique hostnames:
SELECT uniques(host) FROM SystemSampleList unique container names:
SELECT uniques(containerName) FROM ProcessSampleList transaction names for a specific application:
SELECT uniques(name) FROM Transaction WHERE appName = 'my-app'List event types that have data in the current time range:
SELECT uniques(eventType) FROM NrdbQuery $__timeFilterNote
The
$__timeFiltermacro is supported in variable queries. Add it to filter variable values by the dashboard time range.
Applications (IDs)
Returns a list of New Relic application IDs.
Use this query type when you need application IDs for the Metrics query editor or deployment annotations.
Applications (Names)
Returns a list of New Relic application names. Use this query type when you need human-readable names for use in NRQL WHERE clauses.
Metrics
Returns a list of available metric names for a specific application. Select the application from the Application drop-down.
You can use another variable as the application selection, enabling cascading variables where the metric list updates based on the selected application.
Use variables in queries
After creating a variable, reference it in your queries using standard Grafana variable syntax.
Single-value variables
Use ${variable} or $variable syntax. Wrap in single quotes when used in string comparisons:
SELECT average(duration) FROM Transaction WHERE appName = '${app}' $__timeFilter TIMESERIESMulti-value variables
The New Relic data source supports multi-value variables. When a variable allows multiple selections, the plugin automatically formats the values for use in NRQL IN clauses:
SELECT average(duration) FROM Transaction WHERE appName IN (${app}) $__timeFilter TIMESERIESFor quoted contexts, use the :singlequote formatting option:
SELECT count(*) FROM Transaction WHERE appName IN (${app:singlequote}) $__timeFilterVariable usage examples
Filter by application and host:
SELECT average(duration) FROM Transaction WHERE appName = '${app}' AND host = '${host}' $__timeFilter TIMESERIESUse a variable as an event type in Data Explorer’s Where field:
appName = '${app}' AND serverName IN (${servers:singlequote})For more information about variables, refer to Templates and variables.


