I’d like to understand what would be the efficient query to filter a large number of tag values while performing a group by . Here’s an example
Let’s assume we have 5000 hosts which have telegraf running and all of them send their metrics to an influxdb located elsewhere . Lets take the “CPU” telegraf metric for example . Now I’d like to fetch the average CPU consumed for a list of hosts which can be say around 300 . Now “host” is a tag for each metric which is unique for each host.
What would be the most efficient way to query influx to just get the average cpu for the last 1 day for 300 specific hosts?
Lets say the tag values for host are host1,host2,host3 etc
I currently know of only 2 methods
1) Just chain the OR statements
select mean(usage_system) from cpu where time > now() - 1d where host=‘host1’ or host=‘host2’ or … (for 300 hosts) group by host
select mean(usage_system) from cpu where time > now() - 1d where host ~= /host1|host2|host3|…(300hosts)/ group by host
I find both of them highly inefficient . Is there a better way to do this?