cloud-foundation-fabric/cloud-operations/quota-monitoring
Julio Castillo 1e11c670f5 Update copyright to 2021 2021-02-15 09:38:10 +01:00
..
cf Update copyright to 2021 2021-02-15 09:38:10 +01:00
README.md Quota monitor end to end example (#125) 2020-08-29 11:29:46 +02:00
backend.tf.sample Update copyright to 2021 2021-02-15 09:38:10 +01:00
cloud-shell-readme.txt Quota monitor end to end example (#125) 2020-08-29 11:29:46 +02:00
diagram.png Quota monitor end to end example (#125) 2020-08-29 11:29:46 +02:00
explorer.png Quota monitor end to end example (#125) 2020-08-29 11:29:46 +02:00
main.tf Update copyright to 2021 2021-02-15 09:38:10 +01:00
outputs.tf Update copyright to 2021 2021-02-15 09:38:10 +01:00
variables.tf Update copyright to 2021 2021-02-15 09:38:10 +01:00

README.md

Compute Engine quota monitoring

This example improves on the GCE quota exporter tool (by the same author of this example), and shows a practical way of collecting and monitoring Compute Engine resource quotas via Cloud Monitoring metrics as an alternative to the recently released built-in quota metrics.

Compared to the built-in metrics, it offers a simpler representation of quotas and quota ratios which is especially useful in charts, it allows filtering or combining quotas between different projects regardless of their monitoring workspace, and it creates a default alerting policy without the need to interact directly with the monitoring API.

Regardless of its specific purpose, this example is also useful in showing how to manipulate and write time series to cloud monitoring. The resources it creates are shown in the high level diagram below:

GCP resource diagram

The solution is designed so that the Cloud Function arguments that control function execution (eg to set which project quotas to monitor) are defined in the Cloud Scheduler payload set in the PubSub message, so that a single function can be used for different configurations by creating more schedules.

Quota time series are stored using a custom metric with the custom.googleapis.com/quota/gce type and gauge kind, tracking the ratio between quota and limit as double to aid in visualization and alerting. Labels are set with the quota name, project id (which may differ from the monitoring workspace projects), value, and limit. This is how they look like in the metrics explorer.

GCP resource diagram

The solution also creates a basic monitoring alert policy, to demonstrate how to raise alerts when any of the tracked quota ratios go over a predefined threshold.

Running the example

Clone this repository or open it in cloud shell, then go through the following steps to create resources:

  • terraform init
  • terraform apply -var project_id=my-project-id

Variables

name description type required default
project_id Project id that references existing project. string
bundle_path Path used to write the intermediate Cloud Function code bundle. string ./bundle.zip
name Arbitrary string used to name created resources. string quota-monitor
project_create Create project instead ofusing an existing one. bool false
quota_config Cloud function configuration. object({...}) ...
region Compute region used in the example. string europe-west1
schedule_config Schedule timer configuration in crontab format string 0 * * * *

Outputs