Create templates with global variables
To create templates to build interactive dashboards you can use variables via the $variable
or [[variable]]
syntax. You can learn more about templates and variables in the Grafana documentation.
To add variables for assets to a dashboard in Grafana:
Navigate to your dashboard's settings, and then select Variables from the left side.
Make sure the Type is set to Query, and then set your Cognite Data Source as the Data Source.
Specify the query to fetch and filter assets from CDF. For example:
assets{parentIds=[123], name=~"test-.*"}
The query above requests assets with the parameter
parentIds=[123]
and filters the results byname
that matches thetest-.*
regular expression.For a full list of valid parameters see the API documentation.
Learn more about how you can filter the results, for example by using regular expressions.
Click Update.
You can format variables to fit into the query, for instance if you have a multi-value variable:
ts{assetIds=[${variable:csv}]}
The variable will be serialized to comma-separated values in case several assets are selected from the dropdown. Learn more about formatting of variables in the Grafana documentation.
Nested (chained) variables
With nested variables, you can create a template to visualize time series related to a branch of the asset subtree and let users navigate the subtree.
Create the necessary nested variables.
Use the variable as the asset filter on the dashboard.
On the dashboard, users can choose assets on each level of the hierarchy.