Skip to main content

Connect Google Cloud

This guide explains how to prepare your Google Cloud environment and establish a connection with Hypermeter.

Hypermeter reads the cost from your Cloud Billing export in BigQuery, and the utilization of the same resources from Cloud Monitoring. A report can then show rightsizing and waste next to the real spend.

All access is read-only. Hypermeter signs in as one service account.

Integration status

The Google Cloud workflows are in preparation. This page describes the access that they need, so that you can prepare your environment now. Where a detail is not established yet, the page says so. For the current status, contact Exivity support.

What Hypermeter collects​

DataSourceDetails
CostThe detailed usage cost export in BigQueryThe cost of each resource
InventoryCloud Asset InventoryVirtual machines, disks, and Cloud SQL instances in the whole organization or folder
CapacityCompute EngineThe vCPUs and the memory of each machine type
UtilizationCloud MonitoringCPU, network in and out, and disk operations and bytes of virtual machines. Also the metrics of Cloud SQL and Google Kubernetes Engine (GKE)
MemoryCloud MonitoringOnly for the E2 machine family, or for virtual machines with the Ops Agent
RecommendationsRecommenderMachine type recommendations, and idle virtual machines, disks, and Cloud SQL instances

Prerequisites​

You needDetails
A Cloud Billing export to BigQueryThe Detailed usage cost export. The standard export has no resource names, so Hypermeter cannot match its cost with a resource.
A project for the service accountThe service account and its key live in this project.
Permission to grant rolesOn the organization or the folder that you want in the reports, on the dataset of the billing export, and on the project that runs the queries.
Permission to create a service account keySome organizations forbid this with a policy. See Troubleshooting.
The gcloud CLIFor the commands on this page. You can also use the Google Cloud console.
The owner role in HypermeterTo store the key of the service account. See Roles and permissions.

Configure Google Cloud access​

1. Turn on the detailed billing export​

Skip this step if the detailed export is already on.

  1. In the Google Cloud console, open Billing, and select the billing account.
  2. Open Billing export, and select the BigQuery export tab.
  3. Under Detailed usage cost, select Edit settings.
  4. Choose the project and the dataset, and select Save.

Google writes the export to a table named gcp_billing_export_resource_v1_<billing-account-id>. Note the project, the dataset, and the table.

2. Create the service account​

gcloud iam service-accounts create hypermeter-reader --project '<project-id>' --display-name 'Hypermeter reader'

The email address of the service account is hypermeter-reader@<project-id>.iam.gserviceaccount.com.

3. Enable the APIs​

Enable the APIs in the project of the service account:

gcloud services enable monitoring.googleapis.com cloudasset.googleapis.com recommender.googleapis.com bigquery.googleapis.com --project '<project-id>'

4. Grant the read roles​

RoleGrant it onHypermeter uses it for
roles/bigquery.dataViewerThe dataset of the billing exportThe cost rows
roles/bigquery.jobUserThe project that runs the queriesThe queries on the export. Google bills the queries to this project
roles/monitoring.viewerThe organization or the folderThe metrics of Cloud Monitoring
roles/cloudasset.viewerThe organization or the folderThe inventory
roles/recommender.viewerThe organization or the folderThe recommendations
roles/compute.viewerThe organization or the folderThe machine types
Grant roles at the organization level

Grant the last four roles on the organization where you can. New projects are then covered automatically.

For example:

gcloud organizations add-iam-policy-binding '<organization-id>' \
--member 'serviceAccount:hypermeter-reader@<project-id>.iam.gserviceaccount.com' \
--role 'roles/monitoring.viewer'

Repeat the command for each role. For a folder, use gcloud resource-manager folders add-iam-policy-binding '<folder-id>' with the same options.

What the service account can read depends on these roles only. It is not established yet that roles/recommender.viewer covers every recommender of Compute Engine.

5. Create a key​

gcloud iam service-accounts keys create hypermeter-key.json \
--iam-account 'hypermeter-reader@<project-id>.iam.gserviceaccount.com'
Secure credential storage

The key file is a credential. Store its private key in Hypermeter as described below, and then delete the file.

Hypermeter does not support Workload Identity Federation. It needs a key.

6. Optional: install the Ops Agent​

Google Cloud reports memory without an agent only for the E2 machine family. For other virtual machines, install the Ops Agent on the machines that you want to rightsize on memory.

Additional monitoring charges

Google charges for the metrics that the Ops Agent sends. That charge is on your own invoice.

Access across organizations​

Do you collect from an organization that is not your own, for example as a reseller for your customers? Then the owner of each organization grants the roles of step 4 to your service account.

An organization that enforces domain restricted sharing (iam.allowedPolicyMemberDomains) refuses a principal of another organization. The organization then has two options:

  • Add an exception to the policy for your organization.
  • Create a service account of its own, with its own key, and hand the key to you over a secure channel. You store it as a separate secret.

Connect Google Cloud to Hypermeter​

Have the details ready​

ValueDetails
The email address of the service accountclient_email in the key file
The private keyprivate_key in the key file. A secret
The billing exportThe project, the dataset, and the table
The query projectThe project with roles/bigquery.jobUser
The scopeThe ID of the organization, or the IDs of the folders

Create the authenticator​

The Extract jobs sign in with a JWT authenticator. Hypermeter signs a token with the private key and exchanges it at Google for an access token.

FieldValue
URLhttps://oauth2.googleapis.com/token
IssuerThe email address of the service account
Scopehttps://www.googleapis.com/auth/cloud-platform
Audiencehttps://oauth2.googleapis.com/token
Duration3600. This is the number of seconds, and Google accepts one hour at most
Private keyA secret with the value of private_key
Private key formatting

The private key is the text from -----BEGIN PRIVATE KEY----- through -----END PRIVATE KEY-----. In the key file, each line break is written as \n. Replace each \n with a real line break before you paste the value.

The scope does not decide what Hypermeter can read. The roles of the service account do.

For the steps, see Create an authenticator and Setting a secret field.

Verify the connection​

Verify access in advance

You can check the access before the workflows run.

  1. Check that the export has resource names. Run this query in BigQuery:

    SELECT resource.name, resource.global_name, cost
    FROM `<project>.<dataset>.gcp_billing_export_resource_v1_<billing-account-id>`
    WHERE resource.name IS NOT NULL
    LIMIT 10
  2. Check the roles of the service account on the organization:

    gcloud organizations get-iam-policy '<organization-id>' \
    --flatten 'bindings[].members' \
    --filter 'bindings.members:hypermeter-reader@<project-id>.iam.gserviceaccount.com' \
    --format 'table(bindings.role)'

    The result lists the four roles that you granted on the organization.

After the first run of the workflows, check that:

  • Every project with cost also has metrics. A project with cost and without metrics is one that the service account cannot read.
  • At least one running virtual machine has CPU and network values.
  • The recommendations are present, or Recommender has none for you.

How to read the numbers​

ValueWhat to know
CPU, 95th percentileCloud Monitoring has no percentile for CPU utilization. Hypermeter takes the 95th percentile of the hourly maximums, as it does for Azure. The field is named cpu_p95_of_hourly_max, and it is higher than a true 95th percentile.
MemoryOnly the E2 machine family reports memory without an agent. Other virtual machines have memory values only with the Ops Agent.
Disk spaceCloud SQL reports the storage in use.
HistoryCloud Monitoring keeps these metrics for 24 months. It keeps the original values for 6 weeks, and one value per 10 minutes after that. A maximum of an older period is therefore lower than a maximum of a recent period. Do not compare the two.
Recommended savingsRecommender uses the last 8 days for machine type recommendations, and hides a recommendation that saves less than $10 per month. It calls a disk idle when the disk was detached for 15 days or more. Read the savings as list prices, not as your contract prices.
DaysGoogle Cloud cuts billing days at midnight in the US/Pacific timezone.
Cloud Monitoring API charges

Reading metrics has a charge at Google: $0.50 per million time series returned. The first million for each billing account are free. It is not established yet which billing account pays this charge.

Troubleshooting​

What you seeWhat it meansWhat to do
Google refuses to grant a role to the service account, and names an organization policyThe organization enforces domain restricted sharing, and the service account belongs to another organization.See Access across organizations.
Google refuses to create a keyThe organization enforces the policy Disable service account key creation (iam.disableServiceAccountKeyCreation).Ask the administrator of the organization for an exception on the project of the service account.
The sign-in fails with invalid_grantThe issuer is not the email address of the service account, the audience is not the token URL, the duration is more than 3600, the key was deleted, or the private key has \n in place of line breaks.Correct the authenticator. For a new key, rotate the secret.
A query on the export is refused with Access DeniedA BigQuery role is missing.Grant roles/bigquery.dataViewer on the dataset, and roles/bigquery.jobUser on the query project.
The cost rows have no resource nameThe table is the standard export, not the detailed export.Turn on Detailed usage cost. The name of the right table contains resource_v1.
A project has cost and no metricsThe roles are not granted on the folder or the organization of that project.Grant the roles on the organization.
Virtual machines have no memory valuesThe machines are not of the E2 family and have no Ops Agent.Install the Ops Agent.

If a run fails for another reason, see Troubleshooting run failures.