我正在尝试使用 gcloud 命令行客户端在 Google Cloud Platform 中创建正常运行时间检查。这是一个示例:
gcloud monitoring uptime create 'example uptime check' --resource-labels=host=...,project_id=... --resource-type=uptime-url --protocol=https --port=443 "--path=..." --request-method=get --validate-ssl=true --status-codes=200 --matcher-type=contains-string "--matcher-content=..." --period=5 --timeout=30 --user-labels=instance-group=production,instance-type=authentication,monitoring-type=uptime
这通常有效,即创建了正常运行时间检查并且没有报告任何错误。但是,我的用户标签被默默忽略了。
我相信我正确地遵循了文档(https://cloud.google.com/sdk/gcloud/reference/monitoring/uptime/create):
--user-labels=[KEY=VALUE,…]
List of label KEY=VALUE pairs to add.
Keys must start with a lowercase character and contain only hyphens (-),
underscores (_), lowercase characters, and numbers. Values must contain only
hyphens (-), underscores (_), lowercase characters, and numbers.
我已成功向计算实例、磁盘等添加了非常相似的用户标签。
我也尝试通过 向现有的正常运行时间检查中添加用户标签gcloud monitoring uptime update
,但这也没有用。
更新:我已按照 Daniel t. 的建议创建了一个错误报告:https://issuetracker.google.com/issues/393989630
我能够重现此问题,这似乎是 gcloud sdk 上的一个错误。使用调试模式和 log-http 运行它显示 CLI 正在捕获用户传递的用户标签,但不会将其发送到 Cloud Monitoring API。截至 2025 年 1 月 30 日,最新版本的 Google Cloud SDK 为 508.0.0。您可以在此处提交错误 - https://cloud.google.com/sdk/docs/getting-support
这里的旗帜被准确地捕获 -
但是 --log-http 显示 userLabels 没有被发送到监控 API -
一种替代方法是使用 curl 或类似工具通过直接访问云监控 API 来创建正常运行时间检查。这是一个简单的示例 shell 脚本,