【发布时间】:2021-08-03 12:30:10
【问题描述】:
我正在尝试通过具有多个条件的 gcloud 为 Cloud-Sql instance_state 创建单个警报策略。
如果实例处于 “RUNNABLE” 或 “FAILED” 状态超过 5 分钟,则应触发警报。我能够在控制台中创建它,下面是屏幕截图:
现在我使用命令行尝试相同的操作并给出这个 gcloud 命令:
gcloud alpha monitoring policies create \
--display-name='Test Database State Alert ('$PROJECTID')' \
--condition-display-name='Instance is not running for 5 minutes'\
--notification-channels="x23234dfdfffffff" \
--aggregation='{"alignmentPeriod": "60s","perSeriesAligner": "ALIGN_COUNT_TRUE"}' \
--condition-filter='metric.type="cloudsql.googleapis.com/database/instance_state" AND resource.type="cloudsql_database" AND (metric.labels.state = "RUNNABLE")'
OR 'metric.type="cloudsql.googleapis.com/database/instance_state" AND resource.type="cloudsql_database" AND (metric.labels.state = "FAILED")' \
--duration='300s' \
--if='> 0.0' \
--trigger-count=1 \
--combiner='OR' \
--documentation='The rule "${condition.display_name}" has generated this alert for the "${metric.display_name}".' \
--project="$PROJECTID" \
--enabled
我在条件的 OR 部分收到以下错误:
ERROR: (gcloud.alpha.monitoring.policies.create) unrecognized arguments:
OR
metric.type="cloudsql.googleapis.com/database/instance_state" AND resource.type="cloudsql_database" AND (metric.labels.state = "FAILED")
即使我将 ( ) 放在条件上仍然失败,|| 运算符也会失败。
谁能告诉我正确的 gcloud 命令吗?此外,我希望警报策略的结构类似于在云控制台中创建的结构,如上所示
谢谢
【问题讨论】:
-
请查看command notes:“此命令当前在 ALPHA 中,可能会更改,恕不另行通知。如果此命令失败并出现 API 权限错误,尽管指定了权限项目,您可能正在尝试使用仅限邀请的早期访问许可列表访问 API。”您可以联系Google Cloud Sales Team 以获得早期访问权限。 尚未准备好用于生产。
-
谢谢,我已经为不同的 api 使用了 gcloud alpha 命令并成功了
-
您是否尝试仅在一行上设置条件?
-
'metric.type="cloudsql.googleapis.com/database/instance_state" AND resource.type="cloudsql_database" AND (metric.labels.state = "RUNNABLE" OR metric.labels.state= = "FAILed")' -> 这将创建,但不会创建如图所示的结构,因此我不想使用它
标签: google-cloud-platform gcloud google-cloud-stackdriver google-cloud-monitoring