Wouldn't it be nice to have your infrastructure GCP billing along with with your infrastructure monitoring dashboard?
Let's get started!
- Create a BigQuery data set. GCP will save the Billing data here.
- Go to Billing console and configure the Billing export.
First, let's ensure that the billing data are already exported.
Let's say we want to know how much cost was incurred per service from April 1, 2020. The SQL query would be this.
SELECT service.description as service, currency, sum(cost) AS cost FROM `DATASET_NAME.gcp_billing_export_v1_*` WHERE usage_start_time >= "2020-04-01 00:00:00 UTC" GROUP BY service, currency ORDER BY cost DESC
Finally, use the example configuration to visualize the query in Grafana.
This is the equivalent query.
SELECT $__timeGroupAlias(usage_start_time, 1d), service.description AS metric, sum(cost) AS cost FROM `DATASET_NAME.gcp_billing_export_v1_*` WHERE $__timeFilter(usage_start_time) GROUP BY 1, 2 ORDER BY 1, 2
$__timeFilterare Grafana SQL macros.
- The column that is aliased as
metricwill be the labels to be shown and grouped in the graph.
Any question? Let me know in the comments section!
Thanks for reading!