我有以下查询,我在Prometheus数据源中使用Grafana:
(probe_success{instance="$target"} == 0)[30d:1m]
该查询返回probe_success
指标在过去30天内的时间序列数据,分辨率为1分钟。
我想扩展查询。它应该只返回上午09:00至下午05:00之间的数据。我试了一下:
(probe_success{instance="$target"} == 0) and (hour() >= 9 and hour() <= 17)[30d:1m]
不幸的是,这个查询似乎是错误的:
parse error: binary expression must contain only scalar and instant vector types
我看不出这个查询有什么问题。
尝试以下查询:
(
probe_success{instance="$target"} == 0
and on()
(hour() >= 9 and hour() <= 17)
)[30d:1m]
使用on()
修饰符将和算子左侧的任意时间序列与and
算子右侧的任意非空时间序列进行匹配。
当没有设置on()
修饰符时,普罗米修斯尝试在and
算子的左右两侧寻找具有相同标签集的时间序列对。没有这样的对,因为左边返回至少具有instance="$target"
标签的时间序列,而右边返回没有任何标签的时间序列。详情请参阅这些文档。
查询被处理为:
(probe_success{instance="$target"} == 0)
and
( (hour() >= 9 and hour() <= 17)[30d:1m] )
因此,[30d:1m]
只附着在and
的右侧。试试这个:
(probe_success{instance="$target"} == 0 and hour() >= 9 and hour() <= 17)[30d:1m]