How to group by fields?

I have time data in InfluxDB with pairs of hostnames (field “host”) and CPU temperatures (field “temp”).

I’ve set up nine queries - one for each host - like this:

Now, every time I add a new host, I need to modify this panel to make a new query. What if I would just like to select all temperature measurements, delete the WHERE host=… clause, and group the results by host? In ordinary SQL, I would use the GROUP BY clause to group by the field “host”, but I can’t do this in Grafana, since GROUP BY only allows time.

Is what I want possible with Grafana?

1 Like

Grafana can group time series by a column named metric.

So what you can do is put your host in select and name it metric:

SELECT temp, host AS metric

I got this info from Sven from the TimescaleDB-Slack-Community. All props to him.

1 Like

Thanks for the suggestion, but in the end, I chose to store the host name as a tag, rather than a field. That way, I can group by tags in the output. But an interesting suggestion!