1 minute read

Earlier in this post, we have seen how to select a device and see analysis in a dashboard panel.

How to Create a New Drop-Down Menu/Filter (Query Variable) in Grafana Based on PostgreSQL Table Column

Issue

Now, how about we want to show individual panel for each device in the same dashboard?

One way of doing it is manually creating panels and select device ID to show analysis in corresponding panel. But, how about having 500 devices?

It is waste of time to create 500 panels for 500 devices. Rather, we will create one panel and repeat it for selected devices.

Create a new Query Variable

the solution is create a new query variable. We can do the following to create a query variable.

  1. Create a query variable you created.
  2. In the “Query Options” section, set the “Query” field to SELECT DISTINCT(<device_id>) FROM <table_name> ORDER BY <device_id> ASC.
  3. In the “General” section, set the “Name” field to something descriptive like “Device”.
  4. In the “Options” section, set the “Multi-value” option to “On”.
  5. In the “Options” section, set the “Include All option” option to “On”.
  6. In the “Options” section, set the “All format” field to $__all.
  7. Save the variable.

  8. Edit the query you want to use to show sensor data. Replace the hard-coded device ID with the variable name in your WHERE clause. For example, replace "device_id" = 'your_device_id' with "device_id" IN($device).

Enable Repeat Option

We can enable repeating options from the panel edit view. Let’s do the following:

  1. Click on the Panel Title to open the Edit Panel view.

  2. In the Panel Edit view, click on the Repeat tab.

  3. Under the Repeat tab, set the following values:

    • Variable name: device
    • Label: Device
    • Max values: set the maximum number of panels you want to display
  4. Save the panel and go back to the dashboard view. You should see the drop-down manu. From there, select all devices or select the ones you want to check. New panels will show up as you select more devices.

So, that’s all for today! Cheers!!!

  1. How to Create a Dashboard on Grafana showing IoT Device Status
  2. How to Create a New Drop-Down Menu/Filter (Query Variable) in Grafana Based on PostgreSQL Table Column
  3. How to Select Multiple Options from Drop-Down Menu/Filter (Query Variable) in Grafana Based on PostgreSQL Table Column

Leave a comment