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.
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
| Data | Source | Details |
|---|---|---|
| Cost | The detailed usage cost export in BigQuery | The cost of each resource |
| Inventory | Cloud Asset Inventory | Virtual machines, disks, and Cloud SQL instances in the whole organization or folder |
| Capacity | Compute Engine | The vCPUs and the memory of each machine type |
| Utilization | Cloud Monitoring | CPU, network in and out, and disk operations and bytes of virtual machines. Also the metrics of Cloud SQL and Google Kubernetes Engine (GKE) |
| Memory | Cloud Monitoring | Only for the E2 machine family, or for virtual machines with the Ops Agent |
| Recommendations | Recommender | Machine type recommendations, and idle virtual machines, disks, and Cloud SQL instances |
Prerequisites
| You need | Details |
|---|---|
| A Cloud Billing export to BigQuery | The 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 account | The service account and its key live in this project. |
| Permission to grant roles | On 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 key | Some organizations forbid this with a policy. See Troubleshooting. |
| The gcloud CLI | For the commands on this page. You can also use the Google Cloud console. |
| The owner role in Hypermeter | To 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.
- In the Google Cloud console, open Billing, and select the billing account.
- Open Billing export, and select the BigQuery export tab.
- Under Detailed usage cost, select Edit settings.
- 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
| Role | Grant it on | Hypermeter uses it for |
|---|---|---|
roles/bigquery.dataViewer | The dataset of the billing export | The cost rows |
roles/bigquery.jobUser | The project that runs the queries | The queries on the export. Google bills the queries to this project |
roles/monitoring.viewer | The organization or the folder | The metrics of Cloud Monitoring |
roles/cloudasset.viewer | The organization or the folder | The inventory |
roles/recommender.viewer | The organization or the folder | The recommendations |
roles/compute.viewer | The organization or the folder | The machine types |
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'
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.
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
| Value | Details |
|---|---|
| The email address of the service account | client_email in the key file |
| The private key | private_key in the key file. A secret |
| The billing export | The project, the dataset, and the table |
| The query project | The project with roles/bigquery.jobUser |
| The scope | The 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.
| Field | Value |
|---|---|
| URL | https://oauth2.googleapis.com/token |
| Issuer | The email address of the service account |
| Scope | https://www.googleapis.com/auth/cloud-platform |
| Audience | https://oauth2.googleapis.com/token |
| Duration | 3600. This is the number of seconds, and Google accepts one hour at most |
| Private key | A secret with the value of private_key |
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
You can check the access before the workflows run.
-
Check that the export has resource names. Run this query in BigQuery:
SELECT resource.name, resource.global_name, costFROM `<project>.<dataset>.gcp_billing_export_resource_v1_<billing-account-id>`WHERE resource.name IS NOT NULLLIMIT 10 -
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
| Value | What to know |
|---|---|
| CPU, 95th percentile | Cloud 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. |
| Memory | Only the E2 machine family reports memory without an agent. Other virtual machines have memory values only with the Ops Agent. |
| Disk space | Cloud SQL reports the storage in use. |
| History | Cloud 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 savings | Recommender 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. |
| Days | Google Cloud cuts billing days at midnight in the US/Pacific timezone. |
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 see | What it means | What to do |
|---|---|---|
| Google refuses to grant a role to the service account, and names an organization policy | The organization enforces domain restricted sharing, and the service account belongs to another organization. | See Access across organizations. |
| Google refuses to create a key | The 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_grant | The 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 Denied | A 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 name | The 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 metrics | The roles are not granted on the folder or the organization of that project. | Grant the roles on the organization. |
| Virtual machines have no memory values | The 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.