我正在尝试对INFLUX-DB执行查询,以获得唯一的values.Below是我使用的查询。
select host AS Host,(value/100) AS Load from metrics where time > now() - 1h and command='Check_load_current' and value>4000;查询的输出是,

我真正想要的是唯一的"Host“值。例如,我希望"host-1“作为输出只重复一次(最新的值),即使负载值是different.How,我也能做到吗?任何帮助都会很有帮助。
发布于 2018-06-25 06:43:46
Q:我想要来自每个唯一“主机”的最新值,我如何实现它?
为提供了以下数据库:
time host value
---- ---- -----
1529508443000000000 host01 42.72
1529508609000000000 host05 53.94
1529508856000000000 host01 40.37
1529508913000000000 host02 41.02
1529508937000000000 host01 44.49A:考虑将问题分解。
首先,您可以使用"Groupby"操作将“标记值”分组到各自的存储桶中。
Select * from number group by "host"
name: number
tags: host=host01
time value
---- -----
1529508443000000000 42.72
1529508856000000000 40.37
1529508937000000000 44.49
name: number
tags: host=host02
time value
---- -----
1529508913000000000 41.02
name: number
tags: host=host05
time value
---- -----
1529508609000000000 53.94接下来,您需要对每个存储桶中的数据进行降序排序,然后告诉influxdb只返回每个存储桶的前1行。
因此,将"Order by DESC“和"limit 1”过滤器添加到第一个查询中,它应该会为您生成所需的结果。
> select * from number group by "host" order by desc limit 1;
name: number
tags: host=host05
time value
---- -----
1529508609000000000 53.94
name: number
tags: host=host02
time value
---- -----
1529508913000000000 41.02
name: number
tags: host=host01
time value
---- -----
1529508937000000000 44.49参考:
https://docs.influxdata.com/influxdb/v1.5/query_language/data_exploration/#the-group-by-clause
https://docs.influxdata.com/influxdb/v1.5/query_language/data_exploration/#order-by-time-desc
发布于 2018-06-21 15:27:22
如果只想获取每个唯一host标记的最新值,请执行以下操作:
SELECT host AS Host, last(value)/100 AS Load
FROM metrics
GROUP BY hosthttps://stackoverflow.com/questions/50953241
复制相似问题