influxdb 查询 5 个最高 cpu 用法
influxdb query for 5 top cpu usage
我 运行 使用 CloudLinux 的共享虚拟主机。
从中,我可以获得一堆性能指标
所以,我的 influxDB 是:
测量值:lve
字段:CPU、EP、IO、IOPS、MEM、MEMPHY、NETI、NETO、NPROC、fEP、fMEM、fMEMPHY、fNPROC、lCPU、lCPU W、lEP、lIO、lIOPS、lMEM、lMEMPHY、lNETI、lNETO、lNPROC、nCPU
标签:xpool、主机、用户(其中:xpool 是 xen-pool uid,主机是 cloudLinux 的主机名,用户是共享主机的用户名)
每 5 秒收集一次数据
如何查询语句为:
Select 来自特定 xpool+host 的记录,以及
获得 5 个在 5 分钟内产生 TOP CPU 使用率的唯一用户名?。
有数百个用户名,但我只想获得前 5 名。
注意:与 https://docs.influxdata.com/influxdb/v1.5/query_language/functions/#top 中 TOP() 的示例 4 相同,除非预期结果是:
name: h2o_feet
time top location
---- --- --------
2015-08-18T00:00:00Z 8.12 coyote_creek
2015-08-18T00:54:00Z 2.054 santa_monica
而不是:
name: h2o_feet
time top location
---- --- --------
2015-08-18T00:48:00Z 7.11 coyote_creek
2015-08-18T00:54:00Z 6.982 coyote_creek
2015-08-18T00:54:00Z 2.054 santa_monica
2015-08-18T00:24:00Z 7.635 coyote_creek
2015-08-18T00:30:00Z 7.5 coyote_creek
2015-08-18T00:36:00Z 7.372 coyote_creek
2015-08-18T00:00:00Z 8.12 coyote_creek
2015-08-18T00:06:00Z 8.005 coyote_creek
2015-08-18T00:12:00Z 7.887 coyote_creek
因为'8.12'是'coyote_creek'的最大值而'2.054'是'santa_monica'
的最大值
此致
-二元-
可能子查询会有所帮助,例如,这是来自使用 telegraf 的数据库:
SELECT top,host FROM (SELECT TOP(usage_user, 1) AS top, host from cpu WHERE time > now() -1m GROUP BY host)
它将输出如下内容:
name: cpu
time top host
---- --- ----
1527489800000000000 1.4937106918238994 1.host.tld
1527489808000000000 0.3933910306845004 2.host.tld
1527489810000000000 4.17981072555205 3.host.tld
1527489810000000000 0.8654602675059009 4.host.tld
第一个查询是:
SELECT TOP(usage_user, 1) AS top, host from cpu WHERE time > now() -1m GROUP BY host
正在使用 TOP
仅获取 1 项并使用字段 usage_user
然后到"pretty print"使用了一个子查询:
SELECT top,host FROM (...)
我 运行 使用 CloudLinux 的共享虚拟主机。 从中,我可以获得一堆性能指标
所以,我的 influxDB 是:
测量值:lve
字段:CPU、EP、IO、IOPS、MEM、MEMPHY、NETI、NETO、NPROC、fEP、fMEM、fMEMPHY、fNPROC、lCPU、lCPU W、lEP、lIO、lIOPS、lMEM、lMEMPHY、lNETI、lNETO、lNPROC、nCPU
标签:xpool、主机、用户(其中:xpool 是 xen-pool uid,主机是 cloudLinux 的主机名,用户是共享主机的用户名)
每 5 秒收集一次数据
如何查询语句为:
Select 来自特定 xpool+host 的记录,以及
获得 5 个在 5 分钟内产生 TOP CPU 使用率的唯一用户名?。 有数百个用户名,但我只想获得前 5 名。
注意:与 https://docs.influxdata.com/influxdb/v1.5/query_language/functions/#top 中 TOP() 的示例 4 相同,除非预期结果是:
name: h2o_feet
time top location
---- --- --------
2015-08-18T00:00:00Z 8.12 coyote_creek
2015-08-18T00:54:00Z 2.054 santa_monica
而不是:
name: h2o_feet
time top location
---- --- --------
2015-08-18T00:48:00Z 7.11 coyote_creek
2015-08-18T00:54:00Z 6.982 coyote_creek
2015-08-18T00:54:00Z 2.054 santa_monica
2015-08-18T00:24:00Z 7.635 coyote_creek
2015-08-18T00:30:00Z 7.5 coyote_creek
2015-08-18T00:36:00Z 7.372 coyote_creek
2015-08-18T00:00:00Z 8.12 coyote_creek
2015-08-18T00:06:00Z 8.005 coyote_creek
2015-08-18T00:12:00Z 7.887 coyote_creek
因为'8.12'是'coyote_creek'的最大值而'2.054'是'santa_monica'
的最大值此致
-二元-
可能子查询会有所帮助,例如,这是来自使用 telegraf 的数据库:
SELECT top,host FROM (SELECT TOP(usage_user, 1) AS top, host from cpu WHERE time > now() -1m GROUP BY host)
它将输出如下内容:
name: cpu
time top host
---- --- ----
1527489800000000000 1.4937106918238994 1.host.tld
1527489808000000000 0.3933910306845004 2.host.tld
1527489810000000000 4.17981072555205 3.host.tld
1527489810000000000 0.8654602675059009 4.host.tld
第一个查询是:
SELECT TOP(usage_user, 1) AS top, host from cpu WHERE time > now() -1m GROUP BY host
正在使用 TOP
仅获取 1 项并使用字段 usage_user
然后到"pretty print"使用了一个子查询:
SELECT top,host FROM (...)