fixed conditional creation and updated readme

This commit is contained in:
Maurizio Noseda Pedraglio 2022-09-30 10:27:31 +02:00
parent 8b7bf698d2
commit 10811b3d31
3 changed files with 37 additions and 36 deletions

View File

@ -28,7 +28,7 @@ Labels are set with project id (which may differ from the monitoring workspace p
<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.
The solution can also create a basic monitoring alert policy, to demonstrate how to raise alerts when quotas utilization goes over a predefined threshold, to enable it, set variable `alert_create` to true and reapply main.tf after main.py has run at least one and quota monitoring metrics have been creaed.
## Running the blueprint

View File

@ -106,39 +106,40 @@ resource "google_project_iam_member" "quota_viewer" {
member = module.cf.service_account_iam_email
}
var.create_alert ? {
resource "google_monitoring_alert_policy" "alert_policy" {
project = module.project.project_id
display_name = "Quota monitor"
combiner = "OR"
conditions {
display_name = "simple quota threshold for cpus utilization"
condition_threshold {
filter = "metric.type=\"custom.googleapis.com/quota/cpus_utilization\" resource.type=\"global\""
threshold_value = 0.75
comparison = "COMPARISON_GT"
duration = "0s"
aggregations {
alignment_period = "60s"
group_by_fields = []
per_series_aligner = "ALIGN_MEAN"
}
trigger {
count = 1
percent = 0
}
resource "google_monitoring_alert_policy" "alert_policy" {
count = var.alert_create ? 1 : 0
project = module.project.project_id
display_name = "Quota monitor"
combiner = "OR"
conditions {
display_name = "simple quota threshold for cpus utilization"
condition_threshold {
filter = "metric.type=\"custom.googleapis.com/quota/cpus_utilization\" resource.type=\"global\""
threshold_value = 0.75
comparison = "COMPARISON_GT"
duration = "0s"
aggregations {
alignment_period = "60s"
group_by_fields = []
per_series_aligner = "ALIGN_MEAN"
}
trigger {
count = 1
percent = 0
}
}
enabled = false
user_labels = {
name = var.name
}
documentation {
content = "GCE cpus quota over threshold."
}
}
enabled = false
user_labels = {
name = var.name
}
documentation {
content = "GCE cpus quota over threshold."
}
}
resource "random_pet" "random" {
length = 1
}

View File

@ -14,18 +14,18 @@
* limitations under the License.
*/
variable "alert_create" {
description = "Enables the creation of a sample monitoring alert, false by default."
type = bool
default = false
}
variable "bundle_path" {
description = "Path used to write the intermediate Cloud Function code bundle."
type = string
default = "./bundle.zip"
}
variable "create_alert" {
description = "Enables the creation of a sample monitoring alert, false by default."
type = bool
default = false
}
variable "name" {
description = "Arbitrary string used to name created resources."
type = string
@ -33,7 +33,7 @@ variable "name" {
}
variable "project_create" {
description = "Create project instead ofusing an existing one."
description = "Create project instead of using an existing one."
type = bool
default = false
}