Hello,
I am trying to use the alerting policy for a project and I want to monitor multiple instance groups for cpu utilisation via monitoring policy.
I am however not able to set multiple conditions in one block. I don’t want to crete multiple blocks, I want to make that work in one go. Please help me.
provider “google” {
project = “YOUR_PROJECT_ID”
region = “YOUR_REGION”
}
Create a Notification Channel for email alerts
resource “google_monitoring_notification_channel” “email_channel” {
display_name = “Email Notification Channel”
type = “email”
labels = {
email_address = “your-email@example.com” # Replace with your email
}
}
Create a single alert policy with multiple conditions (queries)
resource “google_monitoring_alert_policy” “multi_query_alert” {
display_name = “Multi-Condition Alert Policy”
Combiner specifies whether ALL or ANY condition needs to be met for alert
combiner = “OR” # Set to “AND” if you want all conditions to trigger the alert
Notification Channels
notification_channels = [google_monitoring_notification_channel.email_channel.id]
Query 1: High CPU Usage
conditions {
display_name = “High CPU Usage”
condition_threshold {
filter = "metric.type=\"compute.googleapis.com/instance/cpu/utilization\""
comparison = "COMPARISON_GT"
threshold_value = 0.8 # Trigger alert if CPU utilization > 80%
duration = "60s" # Condition must hold true for 60 seconds
aggregations {
alignment_period = "60s"
per_series_aligner = "ALIGN_MEAN"
}
}
}
Query 2: High Memory Usage
conditions {
display
Query 1 and Query 2 needs to be clubbed together.