我正在尝试使用 Grafana Loki 触发警报。如果到凌晨 5 点还没有看到日志,每天都需要触发警报。
这是我提出的查询。我认为它不正确,因为
offset 16h25m
:将时间范围改变了 16 小时 25 分钟。
count_over_time({env="dev", app="test-app"} |="YOUR Test Keyword" [1d] offset 16h25m) == 0
任何 Grafana Loki 专家有任何建议。
您可以使用类似的方法仅检查周一 4:25 左右的警报:
sum(count_over_time({app="my-service"} | label_format day=`{{ __timestamp__.Weekday }}` | label_format hour=`{{ __timestamp__.Hour }}` | label_format minute=`{{ __timestamp__.Minute }}` | hour = 4 and day = "Monday" and minute > 25 and minute < 35 [5m])) > 0
这会创建日、小时和分钟的标签,并且仅在星期一 9:30 UTC 时返回任何内容。它使用 golang 时间格式(https://www.pauladamsmith.com/blog/2011/05/go_time.html)来做到这一点。它有点挑剔,并且可能有使用预定义方法的不同方式。