How to Select Multiple Options from Drop-Down Menu/Filter (Query Variable) in Grafana Based on PostgreSQL Table Column
Grafana is a popular open-source data visualization and analytics platform that enables creating dashboards and monitoring metrics from various data sources, for example, a database.
One of the useful features of Grafana is the ability to create drop-down panels that enable selecting specific values to filter data in other panels on the dashboard.
Earlier, in this post, I have shown how to create a drop-down menu to select stat for a particular device for my IoT project where I have over 200 devices constantly sending data to to the broker.
How to Create a New Drop-Down Menu/Filter in Grafana Based on PostgreSQL Table Column
However, the only issue was I could check sensor data visualization for only one device. Now, how about checking status for a group or cluster of devices!?
Let’s say five devices have similar properties, and we want to check stats at the same time. So, now, we need to have the option to select multiple devices from the drop-down menu.
It’s all the same procedure as mentioned in my previous post. Except for, we need to select the option for allowing multiple selections
when creating a Query variable.
And then use something like <column_name> in ($<variable_name>)
. In the folowing example, it’s "device_id" IN ($Devices)
.
SELECT $__timeGroup(record_time, '24h') as time,col1,col2,col3,col4
FROM sensor
WHERE $__timeFilter(record_time) AND
"record_time" > (date_trunc('day', CURRENT_DATE - INTERVAL '15 day')) AND
"record_time" < (date_trunc('day', now())) AND "device_id" IN ($Devices)
GROUP BY time,col1,col2,col3,col4
ORDER BY time
Grafana is a powerful data visualization and analytics tool that allows us to create custom dashboards and monitor metrics from various data sources.
In this tutorial, we have worked on selecting multiple options from the drop-down menu/filter. Grafana is a pretty cool tool for monitoring and instant data analysis or visualization.
More tutorials to come in the future! Until then, cheers!!! 😎
You can also read:
Leave a comment