AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1171822
Accepted
PowerGnom
PowerGnom
Asked: 2025-01-28 23:25:31 +0800 CST2025-01-28 23:25:31 +0800 CST 2025-01-28 23:25:31 +0800 CST

如何使用 Google Cloud CLI (gcloud) 创建带有用户标签的正常运行时间检查

  • 772

我正在尝试使用 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

google-cloud-platform
  • 1 1 个回答
  • 35 Views

1 个回答

  • Voted
  1. Best Answer
    Daniel t.
    2025-01-30T20:23:31+08:002025-01-30T20:23:31+08:00

    我能够重现此问题,这似乎是 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

    这里的旗帜被准确地捕获 -

    gcloud monitoring uptime create test-uptime --resource-labels=host=example.com,project_id=myproject --resource-type=uptime-url --protocol=https --port=443 --path=/status --request-method=get --validate-ssl=true --status-codes=200 --user-labels=environment=sandbox --period=15 --timeout=30 --log-http --verbosity=debug
    
    DEBUG: Running [gcloud.monitoring.uptime.create] with arguments: [--log-http: "true", --path: "/status", --period: "15", --port: "443", --protocol: "https", --request-method: "get", --resource-labels: "OrderedDict([('host', 'example.com'), ('project_id', 'myproject')])", --resource-type: "uptime-url", --status-codes: "[200]", --timeout: "30", --user-labels: "OrderedDict([('environment', 'sandbox')])", --validate-ssl: "True", --verbosity: "debug", DISPLAY_NAME: "test-uptime"]
    

    但是 --log-http 显示 userLabels 没有被发送到监控 API -

    -- body start --
    {
      "name": "projects/myproject/uptimeCheckConfigs/test-uptime-ABn9TbKDCj8",
      "displayName": "test-uptime",
      "monitoredResource": {
        "type": "uptime_url",
        "labels": {
          "host": "example.com",
          "project_id": "myproject"
        }
      },
      "httpCheck": {
        "useSsl": true,
        "path": "/status",
        "port": 443,
        "validateSsl": true,
        "requestMethod": "GET",
        "acceptedResponseStatusCodes": [
          {
            "statusValue": 200
          }
        ]
      },
      "period": "900s",
      "timeout": "30s",
      "checkerType": "STATIC_IP_CHECKERS"
    }
    

    一种替代方法是使用 curl 或类似工具通过直接访问云监控 API 来创建正常运行时间检查。这是一个简单的示例 shell 脚本,

    #!/bin/bash
    
    Project_id=your_gcp_project_id
    
    url="https://monitoring.googleapis.com/v3/projects/$Project_id/uptimeCheckConfigs?alt=json"
    
    body='{"displayName": "test-uptime", "httpCheck": {"acceptedResponseStatusCodes": [{"statusValue": 200}], "authInfo": {}, "contentType": "TYPE_UNSPECIFIED", "path": "/status", "port": 443, "requestMethod": "GET", "useSsl": true, "validateSsl": true}, "monitoredResource": {"labels": {"host": "example.com", "project_id": "$Project_id"}, "type": "uptime_url"}, "period": "900s", "timeout": "30s", "userLabels": {"environment": "sandbox"}}'
    
    token="$(gcloud auth print-access-token)"
    
    curl -i -X POST -H "content-type: application/json" -H "Authorization: Bearer $token" -d "${body}" $url
    
    
    • 0

相关问题

  • 网络定价如何在云平台中准确运作?我应该如何避免专门的定价攻击?

  • 云有多大?[关闭]

  • 无需短信即可注册 Google AppEngine?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve