如何通过实例名称获取GCP结算信息? (不是按类型),资源和计费SKU ID之间是否有关联?

时间:2019-11-13 07:44:44

标签: google-cloud-platform google-cloud-billing spring-cloud-gcp

我可以按实例名称查看GCP结算吗? (不是按类型) 我正在尝试按实例名称过滤GCP结算,可以吗?我只成功按GCP Compute Engine和实例类型(n1-standard)等进行了过滤...

我正在尝试以编程方式将与GCP计算实例关联的machineType与相应的计费SKU匹配,但是无法找到直接关联的密钥。例如,这是来自machineType API的响应:

{
 "kind": "compute#machineType",
 "name": "n1-standard-32",
 "description": "32 vCPUs, 120 GB RAM",
 "guestCpus": 32,
 "memoryMb": 122880,
 "imageSpaceGb": 0,
 "maximumPersistentDisks": 128,
 "maximumPersistentDisksSizeGb": "65536",
 "zone": "us-east1-b",
 "isSharedCpu": false
}

这是cloudbilling API中对应的SKU:

  "name": "services/XXXX/skus/XXXX",
  "skuId": "XXXX",
  "description": "Standard Intel N1 32 VCPU running in Americas",
  "category": {
    "serviceDisplayName": "Compute Engine",
    "resourceFamily": "Compute",
    "resourceGroup": "N1Standard",
    "usageType": "OnDemand"
  },
  "serviceRegions": [
    "us-central1",
    "us-east1",
    "us-west1"
  ],
  "pricingInfo": [
    {
      "summary": "",
      "pricingExpression": {
        "usageUnit": "h",
        "usageUnitDescription": "hour",
        "baseUnit": "s",
        "baseUnitDescription": "second",
        "baseUnitConversionFactor": 3600,
        "displayQuantity": 1,
        "tieredRates": [
          {
            "startUsageAmount": 0,
            "unitPrice": {
              "currencyCode": "USD",
              "units": "1",
              "nanos": 520000000
            }
          }
        ]
      },
      "currencyConversionRate": 1,
      "effectiveTime": "2018-02-22T12:00:16.647Z"
    }
  ],
  "serviceProviderName": "Google"

在计费SKU中似乎没有一个值为n1-standard-32的字段。我们如何将这两个问题结合在一起,就像这个页面似乎一样:https://cloud.google.com/compute/pricing

1 个答案:

答案 0 :(得分:0)

您可以创建标签并添加到实例中,以获取每个实例的费用明细。该标签需要在每个实例上添加,添加后,您可以通过按标签对每个实例进行排序来查看每个实例的费用。

创建和管理标签可以为found here

您可以使用资源管理器API并执行诸如这样的请求

POST https://cloudresourcemanager.googleapis.com/v1beta1/projects

{
 "labels": {
  "color": "red"
 },
 "name": "myproject",
 "projectId": "our-project-123"
}

您还可以使用gcloud commands

为Compute Engine实例添加和编辑标签。