如何在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
相关产品推荐
相关产品推荐

