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

使用gcloud导入谷歌云监控告警策略时报filter需指定resource.type错误

问题原因

谷歌云监控API对告警策略的过滤规则有强制校验要求,所有告警条件的filter字段必须同时指定metric.type和resource.type两类限制,不能仅通过指标类型筛选,否则会触发参数校验失败。

修复步骤

  1. 确认你使用的logging.googleapis.com/user/some-metric指标对应的资源类型
    你可以在谷歌云监控的「指标浏览器」页面搜索该指标,查看关联的资源类型,常见的基于日志的自定义指标对应资源类型包括global、gce_instance、k8s_container、cloud_function等。
  2. 修改alert.json文件中的filter字段
    在原有过滤条件后追加资源类型限制,示例如下(以资源类型为global为例):
{
  "displayName": "somename",
  "conditions": [
    {
      "displayName": "somename",
      "conditionAbsent": {
        "aggregations": [
          {
            "alignmentPeriod": "300s",
            "crossSeriesReducer": "REDUCE_MEAN",
            "perSeriesAligner": "ALIGN_DELTA"
          }
        ],
        "duration": "300s",
        "filter": "metric.type=\"logging.googleapis.com/user/some-metric\" AND resource.type=\"global\""
      }
    }
  ],
  "combiner": "OR",
  "enabled": true,
  "notificationChannels": [
    "projects/my-prod-dod/notificationChannels/1962880049684990238",
    "projects/my-prod-dod/notificationChannels/9131919367771592634"
  ]
}

如果需要匹配多个资源类型,可通过OR拼接多个资源类型条件:

"filter": "metric.type=\"logging.googleapis.com/user/some-metric\" AND (resource.type=\"gce_instance\" OR resource.type=\"k8s_container\")"
  1. 重新执行导入命令
gcloud alpha monitoring policies create --policy-from-file alert.json

即可完成告警策略的导入。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.29 00:24:02