Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated quota monitoring CF doc #848

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 17 additions & 3 deletions blueprints/cloud-operations/quota-monitoring/README.md
Expand Up @@ -10,11 +10,25 @@ Regardless of its specific purpose, this blueprint is also useful in showing how

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](https://cloud.google.com/monitoring/custom-metrics) with the `custom.googleapis.com/quota/gce` type and [gauge kind](https://cloud.google.com/monitoring/api/v3/kinds-and-types#metric-kinds), 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.
Quota time series are stored using [custom metrics](https://cloud.google.com/monitoring/custom-metrics) with metric type for usage, limit and utilization; metric types are named using a common prefix and two tokens joined by a `-` character:

<img src="explorer.png" width="640px" alt="GCP resource diagram">
- `prefix` (custom.googleapis.com/quota/)
- `quota name`
- `{usage,limit,utilization}`

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.
e.g:

- `custom.googleapis.com/quota/firewalls_usage`
- `custom.googleapis.com/quota/firewalls_limit`
- `custom.googleapis.com/quota/firewalls_utilization`

All custom metrics are associated to the `global` resource type and use [gauge kind](https://cloud.google.com/monitoring/api/v3/kinds-and-types#metric-kinds)

Labels are set with project id (which may differ from the monitoring workspace projects) and region (quotas that are not region specific are labelled `global`), this is how a usage/limit/utilization triplet looks in in Metrics Explorer

<img src="explorer.png" width="640px" alt="GCP Metrics Explorer, usage, limit and utilization view sample">

The solution also creates a basic monitoring alert policy, to demonstrate how to raise alerts when quotas utilization goes over a predefined threshold.

## Running the blueprint

Expand Down
9 changes: 0 additions & 9 deletions blueprints/cloud-operations/quota-monitoring/cf/main.py
Expand Up @@ -138,7 +138,6 @@ def _quota_to_series_triplet(project, region, quota):
region: set in converted time series labels
quota: quota object received from the GCE API
"""
#labels = dict((k, str(v)) for k, v in quota.items())
labels = dict()
labels['project'] = project
labels['region'] = region
Expand Down Expand Up @@ -221,14 +220,6 @@ def _main(monitoring_project, gce_project=None, gce_region=None, verbose=False,
[_quota_to_series_triplet(*q) for q in quotas[i:i + _BATCH_SIZE]], [])
_add_series(monitoring_project, series, client)
i += _BATCH_SIZE
#
#for quota in quotas:
# series_triplet = _quota_to_series(project,region,quota)
# series_batch.update(series_triplet)
# if (series_batch.__len__==_BATCH_SIZE):
# _add_series(monitoring_project, series_batch, client)
# series_batch=dict()
#_add_series(monitoring_project, series_batch, client)


if __name__ == '__main__':
Expand Down
Binary file modified blueprints/cloud-operations/quota-monitoring/explorer.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions blueprints/cloud-operations/quota-monitoring/main.tf
Expand Up @@ -111,9 +111,9 @@ resource "google_monitoring_alert_policy" "alert_policy" {
display_name = "Quota monitor"
combiner = "OR"
conditions {
display_name = "simple quota threshold"
display_name = "simple quota threshold for cpus utilization"
condition_threshold {
filter = "metric.type=\"custom.googleapis.com/quota/gce\" resource.type=\"global\""
filter = "metric.type=\"custom.googleapis.com/quota/cpus_utilization\" resource.type=\"global\""
maunope marked this conversation as resolved.
Show resolved Hide resolved
threshold_value = 0.75
comparison = "COMPARISON_GT"
duration = "0s"
Expand All @@ -133,7 +133,7 @@ resource "google_monitoring_alert_policy" "alert_policy" {
name = var.name
}
documentation {
content = "GCE quota over threshold."
content = "GCE cpus quota over threshold."
}
}

Expand Down