How to get count of cpus used by all hosts in influxdb

grafana
influxdb
#1

I am working with Grafana to set up a metric to show how many CPU’s are being used by all hosts. My data source in Grafana is influxdb. I was able to get the metric to work with a single host using this query:

SHOW TAG VALUES CARDINALITY ON "telegraf" from "cpu" WITH KEY = "cpu" WHERE "cpu" =~ /cpu\d/ AND "domain"='host01.prod.pvt'

This shows the correct number of CPUs used for host01.prod.pvt. I have many more hosts in that domain and would like to know how can i query all of them for the total number of CPU’s that they are all using?

I tried tweaking my query above with no luck. Thank You

#2

I may have misunderstood the question, but i’m assuming the goal is to show the data/metrics in panels in Grafana then I think you could probably do this with a template variable, although it could be more of a Grafana issue than InfluxDB.

If you create a template variable for the host names just called host inside your Grafana dashboard

SHOW TAG VALUES WITH KEY = "host"

Then edit your query in Grafana
SELECT mean("usage_system") FROM "autogen"."cpu" WHERE ("host" =~ /^$host$/) AND $timeFilter GROUP BY time($__interval), "cpu" fill(null)

Grouping by the ‘cpu’ tag should then bring you all CPU’s used by that host a

The results should change depending on what host you choose from the drop down in Grafana
image

Where i have /^NutanixHosts/ you would change it to /^host/ (or what ever you named your tag in the template variable)

I ramble a little bit, so In short, i think you would want to get the host tag instead of ‘cpu’ - This will give you your hosts. Then in the Grafana query itself you would group by ‘cpu’ - then you would have a display of the current state of any CPU on that given host.

NB: by host, i was referring to ‘domain’ - i read teh question again and realised you had domain instead of host.

Hope that helps