Skip to main content

Google Cloud billing and cost analytics

v0.2.5

Read-only Google Cloud spend analytics — cost by service, project, and SKU, a daily trend, and export freshness — read from the Cloud Billing export in BigQuery, alongside billing account, linked project, and budget reads from the Cloud Billing API. Google Cloud publishes no cost-report API, so the cost actions read the billing export rather than a reporting endpoint.

8 allowed by default
Pack ID
gcp-billing
Vendor
emisar
OS
linux
Actions
8
Required binaries. Install these on the host before relying on the pack — an action that calls a missing one fails at run time.
gcloud curl jq

Install

emisar pack install fetches this pack, re-validates it, and verifies its content hash against the --hash below — the exact bytes this page was rendered against, so a tampered copy is rejected — before copying it into the runner's packs dir. The command reloads a running daemon itself; no manual restart.

on the runner host
sudo emisar pack install gcp-billing --hash sha256:e6304a5cfe3a93e6e7e5575772b3a16af72d15c39956955b517a050795643364

Setup

Uses gcloud authentication on the runner host. The cost actions obtain a short-lived access token from gcloud and post an authored query to the fixed bigquery.googleapis.com endpoint, keeping the token out of argv and output.

Environment

Set these on the runner host, then add each name to execution.inherit_env so the value reaches the action.

  • CLOUDSDK_CONFIG

    Optional gcloud configuration directory.

  • CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE

    Optional path to a credential file that overrides the active gcloud account.

Notes

  • Any credential/config env you set must be allowlisted in the runner's execution.inherit_env ; attached service accounts and workload identity need no credential env.
  • The cost actions read whichever billing export the account turned on — the standard gcp_billing_export_v1_<BILLING_ACCOUNT_ID> table, or the detailed gcp_billing_export_resource_v1_<BILLING_ACCOUNT_ID> one — and name the table they read. Turn on Billing export to BigQuery first: it is not retroactive and takes up to a day to populate, so a fresh export answers recent windows only.
  • A detailed export splits the same charges into resource-level rows, so the same window scans more of it and a wide one may need a higher max_scan_gb.
  • The account, project, and budget reads need roles/billing.viewer bound on the billing account itself; a project-level binding does not reach it, and gcloud then reports that the caller does not have permission to access the billing account.
  • The cost queries additionally need roles/bigquery.jobUser on the query project and roles/bigquery.dataViewer on the export dataset, which also carries the table read that resolves the export.
  • Budget reads need billingbudgets.googleapis.com enabled on the quota project.
  • BigQuery bills every cost query by bytes scanned, so each cost action sends maximumBytesBilled from its max_scan_gb argument: an over-broad window fails outright instead of billing an unbounded scan.
  • Cost rows settle for several days after usage, and credits post on their own schedule, so a recent window is an estimate rather than the invoice.
  • This remote-target pack declares no host detection signal and is never auto-suggested merely because gcloud is installed.

Verify it works

Runs gcp.billing_accounts, a low-risk read that confirms the pack can reach its target. Run it on the host once the pack is installed; pack install runs it for you.

on the runner host
sudo emisar pack verify gcp-billing

Install and configure a pack walks through the whole sequence on a host.

Actions 8 total

View on GitHub
  • gcp.billing_accounts exec low Low — read-only or trivially reversible

    gcloud billing accounts list

    List Cloud Billing accounts the runner's credentials can see, with currency, open state, and parent organization.

    View source on GitHub
  • gcp.billing_budgets exec low Low — read-only or trivially reversible

    gcloud billing budgets list

    List budgets on one Cloud Billing account, with their amounts, threshold rules, and the projects or services each one filters.

    View source on GitHub
  • gcp.billing_projects exec low Low — read-only or trivially reversible

    gcloud billing projects list

    List projects billed to one Cloud Billing account, with each project's billing-enabled state.

    View source on GitHub
  • gcp.cost_by_project script low Low — read-only or trivially reversible

    Show Google Cloud cost by project

    Show gross cost, credits, and net cost per project over a recent window, read from the Cloud Billing export in BigQuery and ordered by the largest net spend. Charges that carry no project, such as support, group as (unattributed).

    View source on GitHub
  • gcp.cost_by_service script low Low — read-only or trivially reversible

    Show Google Cloud cost by service

    Show gross cost, credits, and net cost per Google Cloud service over a recent window, read from the Cloud Billing export in BigQuery and ordered by the largest net spend.

    View source on GitHub
  • gcp.cost_by_sku script low Low — read-only or trivially reversible

    Show Google Cloud cost by SKU

    Show the costliest SKUs over a recent window with their billed usage quantity, read from the Cloud Billing export in BigQuery. This is the breakdown that names what a spend increase actually bought.

    View source on GitHub
  • gcp.cost_daily_trend script low Low — read-only or trivially reversible

    Show the Google Cloud daily cost trend

    Show net cost per day over a recent window, newest first, read from the Cloud Billing export in BigQuery. This is the series that dates a spend increase before the by-SKU breakdown names it.

    View source on GitHub
  • gcp.cost_export_freshness script low Low — read-only or trivially reversible

    Check Cloud Billing export freshness

    Check how current the Cloud Billing export in BigQuery is — its newest export time, that lag in hours, the usage period it covers, and the row count in the window. Run this before trusting a cost number that looks too low.

    View source on GitHub