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
hostNameortransactionIdto 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
errorThresholdorlatencyTargetto 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:
- From an open notebook, locate the variables bar at the top of the interface.
- Click + Add variable.
- 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 variabletargetApp, 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,
failingHostrather thanvar1).
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}} TIMESERIESSELECT latest(cpuPercent) FROM ProcessSample WHERE hostname = {{failingHost}} FACET processDisplayNameWhen 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: |
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: |
What's next?
- Get started with notebooks for an overview of the notebooks feature
- Blocks in notebook to learn more about query and text blocks
- Blob Storage API for notebooks to manage notebooks programmatically
- Template variables: dynamically filter dashboards for the equivalent dashboard feature