【问题标题】:influxdb query for 5 top cpu usageinfluxdb 查询 5 个最高 cpu 使用率
【发布时间】:2018-05-27 08:29:48
【问题描述】:

我使用 CloudLinux 运行共享网络托管。 从中,我可以得到一堆性能指标

所以,我的 influxDB 是:

测量:lve

字段:CPU,EP,IO,IOPS,MEM,MEMPHY,NETI,NETO,NPROC,fEP,fMEM,fMEMPHY,fNPROC,lCPU,lCPUW,lEP,lIO,lIOPS,lMEM,lMEMPHY,lNETI,lNETO,lNPROC ,nCPU

标签:xpool、host、user(其中:xpool 是 xen-pool uid,host 是 cloudLinux 的主机名,user 是共享主机的用户名)

每 5 秒收集一次数据

查询语句如何:

  1. 从特定的 xpool+host 中选择记录,并且

  2. 得到 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”的最高值

真诚的

-比诺-

【问题讨论】:

    标签: influxdb influxdb-python


    【解决方案1】:

    可能子查询会有所帮助,例如,这是来自使用电报的数据库:

    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 (...)
    

    【讨论】:

      猜你喜欢
      • 2013-12-15
      • 2020-10-08
      • 1970-01-01
      • 2019-11-17
      • 2015-06-06
      • 1970-01-01
      • 2011-06-22
      • 2010-09-08
      • 2021-02-28
      相关资源
      最近更新 更多