首页 > 解决方案 > Influxdb 从测量中选择最后一个特定值

问题描述

我的詹金斯将所有测试的结果发送到一个 influxdb 测量,测量的值为 test_name status 等,当测量中的状态值为 0 时,表示测试失败,如果为 1,则测试通过,我想如果他的状态为 0,请选择詹金斯发送给 influx 的最后一个特定的 test_name,如果他的状态为 0,则显示 test_name,如果他的状态为 1,请不要显示。

SELECT last(test_name) FROM db  WHERE testname=example AND status = 0

此命令向我显示最后一个示例 testname,即 status 为 0,但我需要其他内容。

我需要他检查他的最新状态,如果他是 1,请不要给我任何回报,

标签: influxdb

解决方案


使用以下查询获取根据给定条件插入的最后一个值:

select test_name from yourmeasurement order by time desc where testname='example' and status=0 limit 1

这里需要按订单中的数据descending排序,然后选择前1个查询。由于数据插入是时间序列,因此您无需提供时间,因为它是自动进行的。


推荐阅读