3

Can I see GCP billing by instance name? (Not by type) I am trying to filter GCP billing by instance name, is it possible? I only succeeded to filter by GCP Compute Engine and instance type (n1-standard) etc...

I am trying to programmatically match the machineType associated with a GCP compute instance to the corresponding billing SKU, but am unable to find a key for direct association. For example, here is the response from the 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
}

And here is the corresponding SKU from the cloudbilling APIs:

  "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"

There doesn't seem to be a field with value n1-standard-32 in the billing SKU. How do we tie these two together as this page seems to do: https://cloud.google.com/compute/pricing?

Chris32
  • 4,716
  • 2
  • 18
  • 30
  • I have exactly the same question as yours, was you able to find a solution or some mapping between these2 APIs that could help, many thanks in advance. – Waleed Asif Jul 14 '21 at 08:12

1 Answers1

1

You can create labels and add to your instances in order to get a breakdown of the charges per instance. This label needs to be added on each instance, once added, you will be able to see the charges per instance on the billing reports by sorting it per label.

Creating and managing labels can be found here

You can use the Resource Manager API and perform a request such as

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

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

You can also add and edit labels for your Compute Engine Instances using the gcloud commands

Chris32
  • 4,716
  • 2
  • 18
  • 30