Available solutions
GCP Cost Monitoring by HTTP
Overview
This template monitors Google Cloud Platform (GCP) billing costs using the BigQuery API via Zabbix. It works without any external scripts and uses the script items.
The template retrieves cost data aggregated by service and project from Cloud Billing data exported to BigQuery. Two master items (monthly and daily) drive all dependent items and LLD discoveries, minimizing the number of BigQuery API calls.
Requirements
Zabbix version: 8.0 and higher.
Tested versions
This template has been tested on:
- Google Cloud Platform
Configuration
Zabbix should be configured according to the instructions in the Templates out of the box section.
Setup
- Enable Cloud Billing export to BigQuery in the Google Cloud Console (needs to be done by someone with cost admin permissions). See Export Cloud Billing data to BigQuery.
- Create a service account in the GCP project that hosts the billing export dataset. More on managing service accounts.
- Grant the service account the
BigQuery Data Viewerrole on the billing export dataset. - Grant
bigquery.jobs.createpermission on the billing project to the service account. - Create and download a JSON key for the service account. More on service account keys.
- Link this template to a Zabbix host.
- Configure the macros:
{$GCP.CLIENT.EMAIL},{$GCP.PRIVATE.KEY.ID},{$GCP.PRIVATE.KEY},{$GCP.COST.BIGQUERY.TABLE}.
Notes
{$GCP.COST.BIGQUERY.TABLE}must be in the formatproject_id.dataset_id.table_id(no backticks).- If this template is co-hosted with
GCP by HTTP, the auth macros are shared — configure them once at the host level. - To reduce BigQuery query costs, lower
{$GCP.COST.BILLING.MONTH}(e.g. to3).
More on metrics and used API methods:
Macros used
| Name | Description | Default |
|---|---|---|
| {$GCP.CLIENT.EMAIL} | Service account client e-mail. |
|
| {$GCP.PRIVATE.KEY.ID} | Service account private key ID. |
|
| {$GCP.PRIVATE.KEY} | Service account private key data. |
|
| {$GCP.COST.BIGQUERY.TABLE} | BigQuery billing export table path in the format: project_id.dataset_id.table_id. |
|
| {$GCP.BILLING.PROJECT.ID} | GCP project ID where BigQuery jobs are created. If empty, the project from {$GCP.COST.BIGQUERY.TABLE} is used. Set this when the service account lacks bigquery.jobs.create on the billing export project. |
|
| {$GCP.COST.BILLING.MONTH} | Number of months of historical data to retrieve from BigQuery. Maximum 24. |
11 |
| {$GCP.AUTH.FREQUENCY} | The update interval for the GCP Cost Authorization item, which also equals to the access token regeneration request frequency. The GCP Access Token is available for 1 hour (3600 seconds) after the generation request. |
45m |
| {$GCP.COST.SERVICE.MATCHES} | Filter to include discovered services by name. |
.* |
| {$GCP.COST.SERVICE.NOT_MATCHES} | Filter to exclude discovered services by name. |
CHANGE_IF_NEEDED |
| {$GCP.COST.PROJECT.ID.MATCHES} | Filter to include discovered projects by ID. |
.* |
| {$GCP.COST.PROJECT.ID.NOT_MATCHES} | Filter to exclude discovered projects by ID. |
CHANGE_IF_NEEDED |
| {$GCP.COST.REGION.MATCHES} | Filter to include discovered regions. |
.* |
| {$GCP.COST.REGION.NOT_MATCHES} | Filter to exclude discovered regions. |
CHANGE_IF_NEEDED |
| {$GCP.COST.DAILY.MAX} | Daily cost alert threshold. |
1000 |
| {$GCP.COST.MONTHLY.MAX} | Monthly cost alert threshold. |
10000 |
| {$GCP.COST.SPIKE.FACTOR} | Multiplier used to detect a cost spike. Daily cost exceeding avg * factor triggers an alert. |
1.5 |
| {$GCP.COST.WEEKLY.CHANGE.WARN} | Week-over-week cost increase alert threshold (percentage). |
20 |
| {$GCP.COST.MONTHLY.CHANGE.WARN} | Month-over-month cost increase alert threshold (percentage). |
20 |
| {$GCP.COST.PROJECT.MONTHLY.MAX} | Per-project monthly cost alert threshold. |
5000 |
| {$GCP.DATA.TIMEOUT} | API response timeout. |
60s |
| {$GCP.PROXY} | Sets HTTP proxy value. If this macro is empty, then no proxy is used. |
|
| {$HTTP.TLS.VERIFY} | TLS certificate verification for script items and JavaScript preprocessing: "none" - disabled, "peer" - verify the certificate chain and expiration, "full" - full verification. Any other value enables full verification. To override the setting for this template only, define the macro with the context "GCP Cost Monitoring", e.g. {$HTTP.TLS.VERIFY:"GCP Cost Monitoring"}. |
full |
Items
| Name | Description | Type | Key and additional info |
|---|---|---|---|
| GCP annual cost | GCP annual cost. |
Calculated | gcp.annual.cost Preprocessing
|
| Authorization | Google Cloud Platform REST authorization with service account authentication parameters and temporary-generated RSA-based JWT-token usage. The necessary scopes are pre-defined. Returns a signed authorization token with 1 hour lifetime; it is required only once, and is used for all the dependent script items. Check the template documentation for the details. |
Script | gcp.cost.authorization |
| Authorization errors check | A list of errors from authorization requests. |
Dependent item | gcp.cost.auth.err.check Preprocessing
|
| Get monthly costs | Get raw monthly cost data aggregated by service and project from the BigQuery billing export. |
Dependent item | gcp.get.monthly.costs Preprocessing
|
| Get daily costs | Get raw daily cost data for the last 31 days aggregated by service from the BigQuery billing export. |
Dependent item | gcp.get.daily.costs Preprocessing
|
| Billing currency | Currency code reported by the BigQuery billing export (e.g. USD, EUR). Used as units on all billing summary items. |
Dependent item | gcp.cost.currency Preprocessing
|
| Yesterday cost | Total cost for the most recent complete billing day. |
Dependent item | gcp.cost.yesterday Preprocessing
|
| Service count | Number of GCP services with billing activity on the most recent complete day. |
Dependent item | gcp.cost.service.count Preprocessing
|
| Daily avg | Average daily cost over the last 7 billing days. |
Calculated | gcp.cost.daily.avg |
| Monthly avg | Average daily cost over the last 30 days. |
Calculated | gcp.cost.monthly.avg |
| Monthly cost change | Month-over-month cost change as a percentage. Not set when there is no prior month data. |
Dependent item | gcp.cost.monthly.change.pct Preprocessing
|
| Weekly cost change | Week-over-week cost change as a percentage. Not set when there is no prior week data. |
Dependent item | gcp.cost.weekly.change.pct Preprocessing
|
| Get monthly costs errors | A list of errors from API requests. |
Dependent item | gcp.get.monthly.costs.errors Preprocessing
|
| Get daily costs errors | A list of errors from API requests. |
Dependent item | gcp.get.daily.costs.errors Preprocessing
|
| Monthly cost: Current month | Monthly billing total for the current month. |
Dependent item | gcp.cost.monthly.summary.current Preprocessing
|
| Monthly cost: Previous month | Monthly billing total for the previous month. |
Dependent item | gcp.cost.monthly.summary.previous Preprocessing
|
| Daily cost: Yesterday | Billing total for yesterday. |
Dependent item | gcp.cost.daily.summary.yesterday Preprocessing
|
| Weekly cost: Current week | Billing total for the current week. |
Dependent item | gcp.cost.weekly.summary.current Preprocessing
|
| Weekly cost: Previous week | Billing total for the previous week. |
Dependent item | gcp.cost.weekly.summary.previous Preprocessing
|
Triggers
| Name | Description | Expression | Severity | Dependencies and additional info |
|---|---|---|---|---|
| GCP Cost: Authorization has failed | GCP Cost: Authorization has failed. |
length(last(/GCP Cost Monitoring by HTTP/gcp.cost.auth.err.check)) > 0 |
Average | |
| GCP Cost: No billing data received | No billing data has been received in the last 24 hours. |
nodata(/GCP Cost Monitoring by HTTP/gcp.get.monthly.costs,24h)=1 |
Info | Manual close: Yes |
| GCP Cost: Daily cost exceeds threshold | Total daily cost has exceeded the configured threshold. |
min(/GCP Cost Monitoring by HTTP/gcp.cost.yesterday,1h)>{$GCP.COST.DAILY.MAX} |
Warning | Manual close: Yes |
| GCP Cost: Cost spike detected | Daily cost significantly exceeds the 7-day historical average. |
last(/GCP Cost Monitoring by HTTP/gcp.cost.yesterday)>avg(/GCP Cost Monitoring by HTTP/gcp.cost.yesterday,7d)*{$GCP.COST.SPIKE.FACTOR} |
Average | Manual close: Yes |
| GCP Cost: Monthly cost increased significantly | The current month's total cost exceeds the prior month by more than the configured threshold. |
min(/GCP Cost Monitoring by HTTP/gcp.cost.monthly.change.pct,1h)>{$GCP.COST.MONTHLY.CHANGE.WARN} |
Warning | Manual close: Yes |
| GCP Cost: Weekly cost increased significantly | The current week's total cost exceeds the prior week by more than the configured threshold. |
min(/GCP Cost Monitoring by HTTP/gcp.cost.weekly.change.pct,1h)>{$GCP.COST.WEEKLY.CHANGE.WARN} |
Warning | Manual close: Yes |
| GCP Cost: There are errors in requests to API | Zabbix has received errors in response to API requests. |
length(last(/GCP Cost Monitoring by HTTP/gcp.get.monthly.costs.errors))>0 |
Average | |
| GCP Cost: There are errors in requests to API | Zabbix has received errors in response to API requests. |
length(last(/GCP Cost Monitoring by HTTP/gcp.get.daily.costs.errors))>0 |
Average | |
| GCP Cost: Monthly cost exceeds threshold | Monthly billing cost has exceeded the configured threshold. |
min(/GCP Cost Monitoring by HTTP/gcp.cost.monthly.summary.current,1h)>{$GCP.COST.MONTHLY.MAX} |
Average | Manual close: Yes |
LLD rule GCP monthly costs discovery
| Name | Description | Type | Key and additional info |
|---|---|---|---|
| GCP monthly costs discovery | Discovery of total monthly costs per billing month. |
Dependent item | gcp.cost.monthly.discovery Preprocessing
|
Item prototypes for GCP monthly costs discovery
| Name | Description | Type | Key and additional info |
|---|---|---|---|
| Month ["{#GCP.COST.MONTH}"] total cost | Total billing cost for month {#GCP.COST.MONTH}. |
Dependent item | gcp.cost.monthly["{#GCP.COST.MONTH}"] Preprocessing
|
LLD rule GCP monthly costs by service discovery
| Name | Description | Type | Key and additional info |
|---|---|---|---|
| GCP monthly costs by service discovery | Discovery of monthly costs by service and billing month. |
Dependent item | gcp.cost.service.monthly.discovery Preprocessing
|
Item prototypes for GCP monthly costs by service discovery
| Name | Description | Type | Key and additional info |
|---|---|---|---|
| Service ["{#GCP.COST.SERVICE.NAME}"]: Month ["{#GCP.COST.MONTH}"] cost | Monthly cost for service {#GCP.COST.SERVICE.NAME} in month {#GCP.COST.MONTH}. |
Dependent item | gcp.cost.service.monthly["{#GCP.COST.SERVICE.NAME}","{#GCP.COST.MONTH}"] Preprocessing
|
LLD rule GCP monthly costs by project discovery
| Name | Description | Type | Key and additional info |
|---|---|---|---|
| GCP monthly costs by project discovery | Discovery of monthly costs by project and billing month. |
Dependent item | gcp.cost.project.monthly.discovery Preprocessing
|
Item prototypes for GCP monthly costs by project discovery
| Name | Description | Type | Key and additional info |
|---|---|---|---|
| Project ["{#GCP.COST.PROJECT.ID}"]: Month ["{#GCP.COST.MONTH}"] cost | Monthly cost for project {#GCP.COST.PROJECT.ID} in month {#GCP.COST.MONTH}. |
Dependent item | gcp.cost.project.monthly["{#GCP.COST.PROJECT.ID}","{#GCP.COST.MONTH}"] Preprocessing
|
Trigger prototypes for GCP monthly costs by project discovery
| Name | Description | Expression | Severity | Dependencies and additional info |
|---|---|---|---|---|
| GCP Cost: Project [{#GCP.COST.PROJECT.ID}]: Monthly cost exceeds threshold | Monthly cost for project {#GCP.COST.PROJECT.ID} has exceeded the configured threshold. |
min(/GCP Cost Monitoring by HTTP/gcp.cost.project.monthly["{#GCP.COST.PROJECT.ID}","{#GCP.COST.MONTH}"],1h)>{$GCP.COST.PROJECT.MONTHLY.MAX} |
Warning | Manual close: Yes |
LLD rule GCP daily costs by service discovery
| Name | Description | Type | Key and additional info |
|---|---|---|---|
| GCP daily costs by service discovery | Discovery of daily costs by service for the most recent complete billing day. |
Dependent item | gcp.cost.daily.service.discovery Preprocessing
|
Item prototypes for GCP daily costs by service discovery
| Name | Description | Type | Key and additional info |
|---|---|---|---|
| Service ["{#GCP.COST.SERVICE.NAME}"]: Daily cost | Daily cost for service {#GCP.COST.SERVICE.NAME} for the most recent complete billing day. |
Dependent item | gcp.cost.daily.service["{#GCP.COST.SERVICE.NAME}"] Preprocessing
|
LLD rule GCP monthly costs by region discovery
| Name | Description | Type | Key and additional info |
|---|---|---|---|
| GCP monthly costs by region discovery | Discovery of monthly costs by region and billing month. |
Dependent item | gcp.cost.region.monthly.discovery Preprocessing
|
Item prototypes for GCP monthly costs by region discovery
| Name | Description | Type | Key and additional info |
|---|---|---|---|
| Region ["{#GCP.COST.REGION}"]: Month ["{#GCP.COST.MONTH}"] cost | Monthly cost for region {#GCP.COST.REGION} in month {#GCP.COST.MONTH}. |
Dependent item | gcp.cost.region.monthly["{#GCP.COST.REGION}","{#GCP.COST.MONTH}"] Preprocessing
|
LLD rule GCP daily costs by region discovery
| Name | Description | Type | Key and additional info |
|---|---|---|---|
| GCP daily costs by region discovery | Discovery of daily costs by region for the most recent complete billing day. |
Dependent item | gcp.cost.daily.region.discovery Preprocessing
|
Item prototypes for GCP daily costs by region discovery
| Name | Description | Type | Key and additional info |
|---|---|---|---|
| Region ["{#GCP.COST.REGION}"]: Daily cost | Daily cost for region {#GCP.COST.REGION} for the most recent complete billing day. |
Dependent item | gcp.cost.daily.region["{#GCP.COST.REGION}"] Preprocessing
|
Feedback
Please report any issues with the template at https://support.zabbix.com
You can also provide feedback, discuss the template, or ask for help at ZABBIX forums