首页 > 文章列表 > GO 中可用的 Google Cloud API 是否支持提取特定类型(如“e2”等)的 CPU 配额使用情况(而非限制)?

GO 中可用的 Google Cloud API 是否支持提取特定类型(如“e2”等)的 CPU 配额使用情况(而非限制)?

359 2024-01-31
问题内容

我正在尝试拉取特定类型的 CPU 配额使用情况(非限制),以在过去一小时内显示在前端门户上,但我认为没有直接的方法可以做到这一点。有什么建议吗?

我尝试了计算引擎 API 和服务使用 API,但没有成功。

正确答案

调用您的服务的QuotaInfo资源以确定当前的quotaValue

GET projects/PROJECT_NUMBER/locations/global/services/compute.googleapis.com/quotaInfos

返回数据示例:

"quotaInfos": [
    …
     {
        "name": "projects/PROJECT_NUMBER/locations/global/services/compute.googleapis.com/quotaInfos/CpusPerProjectPerRegion",
        "quotaId": "CpusPerProjectPerRegion",
        "metric": "compute.googleapis.com/cpus",
        "containerType": "PROJECT",
        "dimensions": [
            "region"
        ],
        "dimensionsInfo": [
            {
                "dimensions": [],
                "details": {
                    "quotaValue": 20,
                    "resetValue": 20
                },
                "applicableLocations": [
                    "us-central1",
                    "us-central2",
                    "us-west1",
                    "us-east1"
                ]
            }
        ]
    },
      …
]

如需了解更多信息,请先阅读此文档