Using CSV in Grafana to generate per Value Graphs

Using a CSV list in Grafana, so you can generate graphs for different tables of a database.

Setting Grafana Variable

On the open dashboard:

  1. Click cog wheel icon in top right
  2. Select Variables in the list on the left
  3. Click + New variable

In the variable menu:

  • Select variable type: custom
  • Name: the name you want to use, pick a unique name
  • Description: an optional description
  • Show on dashboard: Value
  • Custom options, Value separated by comma: your CSV list here, values separated by commas, no spaces, no " or '
  • Multi-value: check
  • Include All option: check might be optional

You can see a list of found values under Preview of values

Click Apply to save it.

Using the Variable in Queries

variableName refers to the name you gave the variable!

Create a New Row

First, create a new row,

  1. Top right, click the bar with a plus symbol icon
  2. Click on Add a new row
  3. Click the cog wheel icon next to the title of the new row. You might need to hover over the row name
  4. In the Repeat for drop down menu, choose the variableName

I recommended to put $variableName into the Title option of the row.

Alternative: Generating Graphs and Gauges in Single Row

You can also create a new row, and add a graph to that. In the graph settings, under Panel options, open the Repeat options setting. Here you can also choose the variableName. Click Apply

Using the Variable in Graphs

To use every value in the variable, use ${variable}. This can be useful in text fields, to display all values.

To use a single value in a query, you can use "[[instance:raw]]" or [[instance:doublequote]]. Check this page for more information https://grafana.com/docs/grafana/latest/dashboards/variables/variable-syntax/

Examples for using it in queries

SELECT COUNT(*)
FROM [[variableName:doublequote]]

Apply the new dashboard, and drag it into the new row.

Selecting Which Graphs to Show

In the dashboard, in the top right, you should have a drop down menu for choosing which values should be used for generating the graphs.

The graphs and gauges you create should be generated for all these variable values.

Last modified 2023.01.29