grafana将ps_cputime转换为百分比

时间:2019-02-08 18:41:48

标签: sql grafana influxdb cpu-time

我试图在influxdb + grafana中绘制memcached数据,但发现ps_cputimemicrosecond中。

如何将其转换为易于理解的可读格式。

influxdb:

> select * from memcached_syst limit 10;
name: memcached_syst
time                host                                         type       value
----                ----                                         ----       -----
1549595956627272659 ostack-infra-01_memcached_container-167ecaa7 ps_cputime 15853819249
1549596016550515653 ostack-infra-01_memcached_container-167ecaa7 ps_cputime 15853923573
1549596076550356985 ostack-infra-01_memcached_container-167ecaa7 ps_cputime 15854047878
1549596136550415911 ostack-infra-01_memcached_container-167ecaa7 ps_cputime 15854165969
1549596196550481720 ostack-infra-01_memcached_container-167ecaa7 ps_cputime 15854288341
1549596256550522792 ostack-infra-01_memcached_container-167ecaa7 ps_cputime 15854387422

Grafana查询:

SELECT mean("value") FROM "memcached_syst"  WHERE ("host" =~ /^$host$/ AND "type"='ps_cputime' ) AND $timeFilter GROUP BY time($interval) fill(null)

在这里我可以做些什么呢?

2 个答案:

答案 0 :(得分:0)

您需要使用NON_NEGATIVE_DERIVATIVE,结果将以百分比表示:

SELECT NON_NEGATIVE_DERIVATIVE("value", 1s) / 1000
FROM "memcached_syst"
WHERE ("host" =~ /^$host$/ AND "type"='ps_cputime' ) AND $timeFilter
GROUP BY time($interval) fill(null)

此查询可能需要一些调整,例如通过核数进行归一化。

答案 1 :(得分:0)

您可以将微秒转换为小时并显示结果。 公式转换为小时-微秒/ 3600000000

  Select (column_name/3600000000)      as time_in_hrs from table_name;

谢谢