Dear Community, dear pros.
I just started with Grafana and try to using it for system metrics like CPU, memory and so on.
The data comes from Prometheus.
My problem is to get a Bar Gauge dashboard for all my CPU threads in % with user and system CPU usage as an average over the time range selected in the top of the dashboard, where system% and user% should stack to see the total usage, but still have different colors.
The queries are:
- avg_over_time(cpu_logicals_sys{host=“$hostname”}[$__range])
- avg_over_time(cpu_logicals_user{host=“$hostname”}[$__range])
Data looks like this for example:
cpu000(0) sys%
2024-11-15 00:00:00;9.07%
2024-11-15 00:00:15;9.53%
2024-11-15 00:00:30;9.99%
2024-11-15 00:00:45;10.45%
cpu000(8) user%
2024-11-15 00:00:00;6.84%
2024-11-15 00:00:15;7.06%
2024-11-15 00:00:30;7.29%
2024-11-15 00:00:45;7.52%
On different servers I have different amount of CPU’s.
How can I stack the values based on the same {{cpu_logical_name}} ?
Any ideas are welcome. I tried now for hours without any usable outcome.
Many thanks in advance for your help and support.
kind regards,
Joerg
i used infinity to replicate your data:
made sure of the field types for the pie chart:
and changed the calc to mean:
Thanks Raymond for your effort. I need a gauge bar where all CPU are shown similar to:
Only, that the user CPU usage (blue) and system CPU usage (red) for each CPU are stacked.
Additionally, I have over 400 systems all with different amount of CPU. The smallest hast just four and the biggest having more that 150. So, with transformation in bar gauge I can just choose each CPU one by one.
kind regards,
Joerg
Hi,
I don’t think you can do (easily) stacking on Gauge Bar, but you can do that in Bar Chart, which might look identical. What you need to do is:
- Either ensure your query is of type instant (which will return only one value) OR use Reduce transformation to get just one value from the output vector.
- Create a table (using Group to Matrix transformation) where the columns are sys / user and the rows are the hosts (each row will be one bar, so act accordingly, I think it might be it but I might be mistaken).
- Set the stacking option to Normal / 100% (based on what you need).
This should do what you want, though I tested it on a single query, not two, so there will be some Joining / Merging required (both are transformations).
As for the Convert field type it was used in the previous answer to change the type of prepared data (Infinity Plugin in CSV mode sets type to string by default, Prometheus gives you numeric values, so it isn’t required).
Hello David,
thanks for your support and your effort.
It might be, that I don’t understand your answer in detail, but in this case I have some problems:
- the returned value for an “instant” query is not correct. It gives back the value 10.09% as average, but is is 9.275 % (9.28) just for cpu000.
- transformation implies, that all hosts have the same amount of cpu, what it’s not.
kind regards,
Joerg
Hello Dawid,
thanks again for your support and your tip to use reduce transformation.
Unfortunately, with “reduce” I can’t stack Query A with Query B anymore, because, there is only “Mean” as value available and I can’t color the two queries differently either.
I spent days now to solve this, and tried even different panel plugins without any success.
Don’t know why stacking is not implemented in the Bar Gauge panel. It would solve my problem in seconds…
Thanks to all who takes time to read this thread and one more thanks to those who tried to help me.
kind regards,
Joerg