Harnessing the Power of BigQuery and CloudQuery for Google Cloud Cost Optimization
Introduction #
Prerequisites #
- GCP Billing Export to BigQuery is enabled
Syncing data #
kind: source
spec:
# Source spec section
name: 'gcp'
path: 'cloudquery/gcp'
registry: 'cloudquery'
version: 'v17.3.1'
destinations: ['bigquery']
tables: ['gcp_billing*']
spec:
# GCP Spec section described below
project_ids: ['<project-id>']
---
kind: destination
spec:
name: bigquery
path: cloudquery/bigquery
registry: 'cloudquery'
version: 'v4.2.0'
write_mode: 'append'
spec:
project_id: '<project-id>'
dataset_id: costdata
gcp_
and two GCP billing table prefixed with gcp_billing_export
and gcp_billing_export_resource
. In our case the interesting one is gcp_billing_export_resource
which contains the billing data for each resource so we can join with CloudQuery data easily.Correlating Billing Data with CloudQuery Data #
Cost of unattached disks #
users
field is null (which per gcp documentation is the case for unattached disks):select * from gcp_compute_disks where users is null
SELECT sum(cost) FROM `cq-playground.costdata.gcp_billing_export_resource_v1_0183D4_4E0A4D_60E401` gcp_billing_export_resource
join `cq-playground.costdata.gcp_compute_disks` gcp_compute_disks on
gcp_billing_export_resource.resource.name = gcp_compute_disks.name
WHERE DATE(_PARTITIONTIME) = "2022-12-14" and ARRAY_LENGTH(gcp_compute_disks.users) = 0
Cost of instances by architecture #
Intel Broadwell
CPU:SELECT sum(cost) FROM `cq-playground.costdata.gcp_billing_export_resource_v1_0183D4_4E0A4D_60E401` gcp_billing_export_resource
join `cq-playground.costdata.gcp_compute_instances` gcp_compute_instances on gcp_billing_export_resource.resource.name = gcp_compute_instances.name
WHERE DATE(_PARTITIONTIME) = "2022-12-14" and gcp_compute_instances.cpu_platform = "Intel Broadwell"
Intel Broadwell
with AMD Rome
and/or any other architecture.Summary #
Written by Yevgeny Pats
Yevgeny Pats is the Co-Founder & CEO at CloudQuery. Prior to establishing CloudQuery, he successfully founded and exited other startups. He has a background in software engineering and cybersecurity.