简体   繁体   English

如何聚合/求和多个 CPU 内核以获得 Grafana 中的一个 CPU 指标?

[英]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 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.我想 SUM(cpu.*.system) 来获得聚合的 cpu.system.total。

Is there a way to accomplish this with the current Grafana-graphite query-editor?有没有办法使用当前的 Grafana-graphite 查询编辑器来实现这一点?

Please advise.请指教。

尝试这个

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

I got one other solution as described below:我得到了另一种解决方案,如下所述:

Edited vi /opt/collectd/etc/collectd.conf file.编辑vi /opt/collectd/etc/collectd.conf文件。

Uncomment LoadPlugin aggregation.取消对 LoadPlugin 聚合的注释。

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.并重新启动了收集服务。

Here's a solution using only build-in Grafana functions这是仅使用内置 Grafana 函数的解决方案

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

Grafana will calculate average CPU usage over last 20 seconds. Grafana 将计算过去 20 秒内的平均 CPU 使用率。

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.更改最后一个数字(上面示例中的“/8” ),以将受监控实例上的核心数和“20s”与您希望的任何时间间隔相匹配。

then change graph's display unit to percent 0.0-1.0然后将图形的显示单位更改为百分比 0.0-1.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM