Use SystemLink Grafana Dashboard Variable as an Input to a Jupyter Notebook

Updated Mar 8, 2024

Environment

Software

  • SystemLink
  • SystemLink Jupyter Notebook Add-On

This article demonstrates how to use a SystemLink Grafana dashboard variable as an input parameter to a Jupyter Notebook data source.
 

Prerequisites

  • The SystemLink Server PC must have the NI SystemLink Server - JupyterHub Module installed.
  • Grafana must be installed on the SystemLink Server PC. Refer to [External] GitHub: NI Grafana Plugins for instructions.

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:
 
  1. 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.
variable configuraion.PNG
  1. Configure the Jupyter Notebook to accept a string input parameter.
    1. In SystemLink, open Jupyter from Utilities >> Jupyter.
    2. Open the notebook that should be used as a data source in Grafana.
    3. 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.
    4. Save the notebook.
Cell Metadata.PNG
  1. Use the Jupyter Notebook as a data source in the Grafana dashboard.
  2. 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.

panel configuration.PNG