Parul Chourasia
Parul Chourasia

Reputation: 117

How to aggregate/Sum multiple CPU cores to get one CPU metric in grafana?

Is there a way to aggregate across metrics/metric-names? For example, on a four core system, you have the following metric-names:

cpu.0.system cpu.1.system cpu.2.system cpu.3.system

I would like to SUM(cpu.*.system) to get the aggregated cpu.system.total.

Is there a way to accomplish this with the current Grafana-graphite query-editor?

Please advise.

Upvotes: 2

Views: 4380

Answers (3)

nuclear_bean
nuclear_bean

Reputation: 343

Here's a solution using only build-in Grafana functions

1-sum(rate(node_cpu_seconds_total{mode="idle"}[20s]))/8

Grafana will calculate average CPU usage over last 20 seconds.

IMPORTANT
Change last number ("/8" in example above), to match number of cores on your monitored instance and "20s" to whatever time interval you wish.

then change graph's display unit to percent 0.0-1.0

Upvotes: 1

Parul Chourasia
Parul Chourasia

Reputation: 117

I got one other solution as described below:

Edited vi /opt/collectd/etc/collectd.conf file.

Uncomment LoadPlugin aggregation.

LoadPlugin aggregation
<Plugin aggregation>
  <Aggregation>
    #Host "unspecified"
    Plugin "cpu"
    #PluginInstance "unspecified"
    Type "cpu"
    #TypeInstance "unspecified"

    GroupBy "Host"
    GroupBy "TypeInstance"

#    CalculateNum false
#    CalculateSum false
    CalculateAverage true
#    CalculateMinimum false
#    CalculateMaximum false
#    CalculateStddev false
  </Aggregation>
</Plugin>

And restarted the collecd services.

Upvotes: 2

Bilal Ali Jafri
Bilal Ali Jafri

Reputation: 1006

Try this

alias(sumSeries(cpu.*.system),'Total CPU')

Upvotes: 1

Related Questions