• /
  • EnglishEspañolFrançais日本語한국어Português
  • Inicia sesiónComenzar ahora

Variables in notebooks: build dynamic, repeatable runbooks

With notebook variables, you can set up dynamic parameters that cascade through multiple queries across query blocks. Unlike dashboard template variables, which filter a static view, notebook variables act as injected parameters that drive the underlying logic of your entire document.

Go to one.newrelic.com > All capabilities > Notebooks.

Why use variables in notebooks?

Notebook variables let you build interactive experiences such as:

  • Parameterized runbooks where an engineer inputs a specific hostName or transactionId to instantly generate a targeted system health report.
  • Post-mortem templates that can be updated with specific timestamps, regions, or application names to analyze an incident.
  • Interactive thresholds where users can tweak variables like errorThreshold or latencyTarget to see how different parameters affect the visualized data.

The key benefits include:

  • Creating executable runbooks: Variables turn your notebooks from static pages into interactive tools. You can build adaptable workflows for alert event investigations, performance analysis, and team collaboration.
  • Standardizing knowledge sharing: As a saved document, you can share analytical workflows with colleagues. Users don't need to rewrite complex NRQL queries — they simply change to a new variable value from your pre-defined variables and execute the workflow.

Define a notebook variable

Define a variable that you'll inject into your NRQL query blocks to parameterize your data retrieval and visualizations.

To define a variable:

  1. From an open notebook, locate the variables bar at the top of the interface.
  2. Click + Add variable.
  3. Configure your variable type (for example, text input, dropdown, or numeric) and provide a default value.

Variable naming rules

When naming your variable, keep the following in mind:

  • The name is the exact string you will use in your notebook blocks, surrounded by {{...}}. For example, if you name the variable targetApp, you reference it in your query blocks as {{targetApp}}.
  • Variable names are case-sensitive and must be unique within a notebook.
  • Choose descriptive names that make your runbook self-explanatory to other users (for example, failingHost rather than var1).

Use a variable in a query block

Once defined, reference your variable anywhere in a NRQL query using the {{variableName}} syntax:

SELECT average(cpuPercent) FROM SystemSample WHERE hostname = {{failingHost}} TIMESERIES
SELECT latest(cpuPercent) FROM ProcessSample WHERE hostname = {{failingHost}} FACET processDisplayName

When you run the query, the variable value you have set in the variables bar is substituted into the query at runtime. Changing the variable value and re-running the query instantly updates all blocks that reference that variable.

Automate incident response with runbooks

The most powerful application for notebook variables is creating executable runbooks for incident response. By combining notebook variables with New Relic Workflows, you can automate the handoff between an alert triggering and the investigation beginning.

Structure your runbook

A well-structured parameterized runbook typically follows this pattern:

Block

Type

Purpose

1

Markdown

Instructions on how to use the runbook and architectural context of the service

2

NRQL

High-level system check using the injected variable — for example: SELECT average(cpuPercent) FROM SystemSample WHERE hostname = {{failingHost}} TIMESERIES

3

Markdown

Conditional guidance — for example: "If the chart above shows CPU > 90%, run the next query to identify the top processes."

4

NRQL

Deeper investigative query — for example: SELECT latest(cpuPercent) FROM ProcessSample WHERE hostname = {{failingHost}} FACET processDisplayName

What's next?

Copyright © 2026 New Relic Inc.

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