You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在GCP监控查询语言(MQL)中排除特定时段避免告警?

修改后的MQL查询
fetch pubsub_topic
| metric 'pubsub.googleapis.com/topic/send_request_count'
| filter
    resource.project_id == 'projectid'
    && (resource.topic_id == 'topic-id')
| align rate(1m)
| every 1m
| group_by [metric.response_code],
    [value_send_request_count_aggregate: aggregate(value.send_request_count)]
| absent_for 1800s
| filter time_of_day(timestamp) between time(6,0,0) and time(22,0,0)

关键改动说明

  • 新增最后一行过滤逻辑,通过time_of_day函数提取时间戳的时分秒信息,仅保留发生在每日6:00至22:00之间的指标缺失事件,自动排除22:00至次日6:00的时段,避免该区间触发告警。
  • time(6,0,0)和time(22,0,0)分别对应6点整和22点整,between运算符用于判断时间是否落在允许告警的区间内。

时区注意事项

GCP Monitoring默认采用UTC时区,若你的业务使用非UTC时区(如北京时间),需在time_of_day函数中指定对应时区,示例(北京时间):

| filter time_of_day(timestamp, "Asia/Shanghai") between time(6,0,0) and time(22,0,0)

内容的提问来源于stack exchange,提问作者aya62

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 17:14:55