To use a Grafana dashboard variable as an input to a SystemLink Jupyter Notebook, the notebook must be configured to accept a string input parameter. The Grafana dashboard variable can be referenced by using the syntax described in
[External] Grafana Labs: Variable Syntax.
Follow the steps below to pass a Grafana dashboard variable into a Jupyter Notebook:
- Add a variable to the Grafana dashboard.
- Instructions can be found at [External] Grafana Labs: Add and Manage Variables.
- For the purposes of this tutorial, a Custom variable called points has been configured, which can hold a value of 10, 100, 1000 or 10000. This variable will be used to determine how many output data points are generated from the Jupyter Notebook.
- Configure the Jupyter Notebook to accept a string input parameter.
- In SystemLink, open Jupyter from Utilities >> Jupyter.
- Open the notebook that should be used as a data source in Grafana.
- In the Code Cell that defines the input parameters, modify the Cell Metadata to ensure that a string input will be accepted.
- The image below shows Cell Metadata that defines an input variable called num_elements with a value of "50".
- The input id matches with the variable name from the Code Cell, the default value is "50", and the type is string.
- Note: if your input parameter should be treated as a number in the notebook, remember to convert it to an integer using the [External] Python int() function.
- Save the notebook.
- Use the Jupyter Notebook as a data source in the Grafana dashboard.
- Link the Jupyter Notebook parameter with the Grafana Dashboard variable.
- On the Query tab of the Grafana dashboard panel, set the parameter value to $<variable name>.
- In the example below, the Grafana dashboard variable is called points, so the notebook parameter value is set to $points.
- To refresh the panel data, click the Refresh dashboard button at the top.