Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yihyang/53c54195718476ac60563d92094cd8e5 to your computer and use it in GitHub Desktop.
Save yihyang/53c54195718476ac60563d92094cd8e5 to your computer and use it in GitHub Desktop.
Understanding Your Google Cloud Costs
# Analyzing Billing Data with BigQuery
SELECT * FROM `billing_dataset.enterprise_billing` WHERE Cost > 0
SELECT Line_Item FROM `billing_dataset.enterprise_billing` GROUP BY Line_Item
SELECT Line_Item, COUNT(*) as NUM FROM `billing_dataset.enterprise_billing` GROUP BY Line_Item
SELECT Project_ID, COUNT(*) as num FROM `billing_dataset.enterprise_billing` GROUP BY Project_ID
SELECT SUM(cost) as Cost, Project_Name FROM `billing_dataset.enterprise_billing` GROUP BY Project_Name
# Visualizing Billing Data with Data Studio
SELECT service.description FROM `ctg-storage.bigquery_billing_export.gcp_billing_export_v1_01150A_B8F62B_47D999` GROUP BY service.description
SELECT * FROM `ctg-storage.bigquery_billing_export.gcp_billing_export_v1_01150A_B8F62B_47D999`
SELECT service.description, COUNT(*) AS num FROM `ctg-storage.bigquery_billing_export.gcp_billing_export_v1_01150A_B8F62B_47D999` GROUP BY service.description
SELECT location.region FROM `ctg-storage.bigquery_billing_export.gcp_billing_export_v1_01150A_B8F62B_47D999` GROUP BY location.region
SELECT location.region, COUNT(*) AS num FROM `ctg-storage.bigquery_billing_export.gcp_billing_export_v1_01150A_B8F62B_47D999` GROUP BY location.region
# Examining BigQuery Billing Data in Google Sheets
SELECT *
FROM billing_dataset.enterprise_billing
SELECT Account_ID, Measurement1_Total_Consumption, Measurement1_Units, Credit1, Credit1_Amount, Credit1_Currency, Cost, Currency, Project_Number, Project_ID, Project_Name, Description
FROM billing_dataset.enterprise_billing
WHERE Project_Name IN ('CTG - Dev','CTG - Prod')
ORDER BY Project_Name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment