Generated banner for Cloud Monitoring Alert Configuration
Generated logo for Cloud Monitoring Alert Configuration

Cloud Monitoring Alert Configuration

GoogleOfficialPublished by Google

  • Skill
  • Workflow
  • Cloud and DevOps
  • Apache-2.0
  • Low risk
  • Has scripts

From the author

Configures Cloud Monitoring alerting policies using Terraform and PromQL across Cloud Run, Google Kubernetes Engine (GKE), Compute Engine, AI Hypercomputer reservations, Vertex AI Agent Engine, and generic Google Cloud resources. Use when creating, reviewing, migrating, or deduplicating Terraform alerting policies for latency, traffic, error rates, saturation, host or reservation maintenance, GPU XID insights, or AI agent telemetry. Don't use for standalone PromQL query authoring without alerting, log querying, or billing cost audits.
— the description by Google

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides a structured workflow for defining, reviewing, and managing Cloud Monitoring alerting policies. It leverages Terraform for infrastructure-as-code and PromQL for metric conditions, ensuring consistent observability across Google Cloud resources including Cloud Run, GKE, Compute Engine, and AI Agent platforms. The skill enforces best practices like the Four Golden Signals, dynamic grouping, and proper labeling, while providing clear paths for delegating SLO-specific configurations and notification channel management.

What it does

  • Generates parameterized Terraform configurations for Cloud Monitoring alert policies.
  • Implements PromQL-based conditions for high-signal monitoring.
  • Provides resource-specific guidance for GKE, Cloud Run, Compute Engine, and AI agents.
  • Enforces standardized labeling for all generated alerting resources.
  • Integrates with specialized scripts to analyze traffic patterns for AI agent telemetry.
  • Delegates SLO and notification channel configuration to dedicated skills.

When to use it

  • When creating or migrating Terraform-based alerting policies for Google Cloud infrastructure.
  • When setting up monitoring for AI agent reliability, quality, and cost telemetry.
  • When deduplicating existing alert policies to improve signal-to-noise ratios.
  • When configuring alerts for latency, traffic, error rates, or saturation across cloud services.

Advantages

  • Ensures consistent observability standards across diverse cloud environments.
  • Reduces manual configuration errors through structured Terraform templates.
  • Promotes best practices like dynamic grouping and the Four Golden Signals.
  • Maintains clear separation of concerns by delegating SLO and notification tasks.
  • Provides data-driven traffic analysis for accurate AI agent alert thresholds.

Usage examples

“Create a Terraform alerting policy for high latency on my GKE service.”
The agent will guide you through selecting the appropriate GKE PromQL queries, generate the google_monitoring_alert_policy Terraform resource, and prompt you to attach notification channels.
“Configure a cost alert for my Vertex AI Agent based on token usage.”
The agent will run the traffic analysis script to determine your workload pattern and generate a PromQL-based alert policy tailored to your agent's historical token consumption.

Install

  1. Download the skill as a ZIP:

    https://autogineer.com/agent-skills/google/cloud-monitoring-alert-configuration/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip cloud-monitoring-alert-configuration.zip -d .agents/skills

Documentation by Google

Configure Cloud Monitoring Alerts

Configure high-signal alerting policies in Cloud Monitoring using Terraform (google_monitoring_alert_policy) and PromQL (condition_prometheus_query_language).

Usage Attribution

For all gcloud CLI, REST API, and MCP attribution requirements when executing commands with this skill, follow the instructions in Usage Attribution.

Enforce Core Alerting Rules

  1. Apply the Four Golden Signals: Cover latency, traffic, errors, and saturation for the target workload.

  2. Use Dynamic Grouping: Aggregate metrics by resource labels and parameterize thresholds with Terraform variables. Never hardcode ephemeral pod or instance identifiers.

  3. Default to PromQL: Use Prometheus Query Language (PromQL) for metric conditions, and use log-based alerts (condition_matched_log or google_logging_metric) for lifecycle and audit events.

  4. Attach Skill Attribution Labels: Always include user_labels with created-with-google-skill = "cloud-monitoring-alert-configuration" on every generated google_monitoring_alert_policy resource.

  5. Require User Confirmation Before Mutating Resources: Never execute commands that modify infrastructure, enable telemetry, create online monitors, or apply Terraform without waiting for explicit user confirmation.

  6. Prompt for Notification Channels: Alerting policies without notification channels incur charges without notifying anyone during an incident. Whenever notification channels are not specified in the user prompt across any workflow, explicitly inform the user that no notification channels are attached to the alerting policies, advise them to configure and attach notification channels before deploying, and ask at the end of your response if they want to configure notification channels.

Route by Target Resource Type

Identify the target resource type and read only the matching reference file directly. Never run directory listings or workspace file searches to look for queries or .tf files unless the prompt explicitly provides a file path. If a user asks to fix or validate a PromQL query without providing the query text or a file path, construct a representative broken-and-corrected query example directly.

Configure Cloud Run Alerts
Configure Google Kubernetes Engine Alerts
Configure AI Agent Alerts
Configure Compute Engine and AI Hypercomputer Alerts
  • Compute Engine VMs, MIGs, GPU XID Insights, Host or Reservation Maintenance (type=scheduled, unscheduled, or multiple), and Machine or Domain Health: compute_engine_alerts.md

Configure Generic Resource Alerts
Delegate Service Level Objective Alerts

Delegate to the google-cloud-slo-alert-configuration skill. That skill owns the SLO setup wizard, the burn-rate PromQL templates (references/promql_templates.md), the SLI metric mapping (references/service_metrics.md), and the App Hub scoping labels (references/app_hub_labels.md). Do NOT duplicate those templates here or claim that this skill owns its own SLO PromQL template library.

Delegate whenever the user asks for an availability or latency SLO, an error budget or burn-rate alert, or a Service Level Objective on any resource. When SLOs are only one part of a broader request (for example, a full production alerting suite for a Cloud Run service), delegate the SLO policies and continue generating the remaining golden-signal policies from the resource-specific reference in the same response.

Every resource reference carries a Context to hand off list naming the SLI metric, its good or bad filter, and the grouping labels — under a ## Delegate Service Level Objective Alerts heading for Cloud Run and generic resources, and inside the SLO section itself for GKE and Agent Platform. Read it and pass that context on, so the SLO skill does not repeat discovery you have already done. When delegating, you MUST also:

  1. State the SLO target and window explicitly if the user gave them, or let the SLO skill apply its SRE defaults (99.9% over a rolling 28 days) if they did not.

  2. Require the returned policies to carry user_labels with created-with-google-skill = "cloud-monitoring-alert-configuration" so attribution stays consistent with the rest of the generated suite. This literal value does NOT change when you delegate: the label records the entry-point skill, not whichever skill supplied the template. Do NOT set created-with-google-skill = "google-cloud-slo-alert-configuration" on policies generated through this delegation.

  3. Preserve the burn-rate duration contract, which google-cloud-slo-alert-configuration does not specify: Fast Burn (1h and 5m windows, factor 14.4) carries duration = "300s", and Slow Burn ([3d] and [6h] lookback, factor 1.0) omits the duration field entirely — do not emit duration = "0s" in its place. Cloud Monitoring rejects a non-zero retest buffer when the lookback window exceeds 25 hours.

  4. When no notification channels are provided, inform the user that no notification channels are attached to the alerting policies, advise them to configure and attach notification channels, and ask if they want to configure notification channels.

[!IMPORTANT] Always tell the user about the referral, even on the fallback path. Some reference files in this skill include standalone burn-rate templates to use when the google-cloud-slo-alert-configuration skill is not installed. If you emit policies from those fallback templates, your response MUST still tell the user that google-cloud-slo-alert-configuration owns SLO configuration, state that the emitted policies use the local fallback templates, and list the handoff context. Never silently present SLO policies as if this skill owned them.

[!NOTE] Exception: Agent Platform (OpenTelemetry-instrumented AI agents on any runtime, including Vertex AI Agent Engine and Cloud Run) is the one resource whose Fast and Slow burn policies live in this skill and remain authoritative. Delegate only for SLO customization — see Reliability.

  • Notification Channels: Delegate to cloud-monitoring-notification-channels-configuration to configure email, PagerDuty, Pub/Sub, or Slack channels. When an alerting policy has no notification channels attached, inform the user that no notification channels are attached and that they should configure notification channels and attach them to the alerting policy.

  • PromQL Authoring: Delegate to cloud-monitoring-promql-query for standalone PromQL query authoring or metric exploration.

Follow the Alert Configuration Workflow

  1. Discover: Identify target resources, metric schemas, and scoping projects using the lookup commands in the matching reference file (such as discover_metric_schema.py for Compute Engine metrics and other Google Cloud resource metrics, or gather_agent_info.py, check_telemetry.py, analyze_traffic.py, create_online_monitor.py, list_trace_scope_table_names.py, and list_log_scope_table_names.py for AI agents).

  2. Route: Load the reference file for the target resource type or delegate SLOs to google-cloud-slo-alert-configuration.

  3. Generate: Produce parameterized Terraform HCL configurations with required user_labels.

  4. Validate: When the loaded reference file requires a validation script (such as lint_promql.py, validate_config.py, lint_syntax.py, or scan_duplicates.py), run or print that exact script command. Do not list or search the scripts/ directory.

  5. Explain and Prompt: Explain each alert policy in plain English. When no notification channels are provided, tell the user that no notification channels are attached to the alerting policy, advise them to configure and attach notification channels, and ask if they want to configure notification channels.

Files

references/agent_platform_reliability_alert_policies.md

Configure Reliability Alert Policies

These alert policies help users pinpoint the root cause of ongoing increased agent latency and high error rates with model and tool requests.

[!IMPORTANT] Full Production Agent Configuration Requirements: When configuring full production alerts for an AI agent, you MUST read all five policy references (Reliability, Quality, Cost, Safety, and Security) and:

  1. Generate 11 alerting policies (5 reliability, 3 quality, 1 cost, 1 safety, and 1 security including High IAM Permission Denied Trigger Rate).

  2. Always include all four pre-populated supporting script commands with all parameter values filled in (even if a fallback table name is provided):

    • Streamlined Discovery: python3 scripts/agent_platform/gather_agent_info.py --project-id "<project_id>" --agent-name "<agent_name>"

    • Telemetry Verification: python3 scripts/agent_platform/check_telemetry.py --project-id "<project_id>" --location "us-central1" --agent-resource-name "projects/<project_id>/locations/us-central1/reasoningEngines/<agent_id>" --query-monitoring-metadata

    • Online Monitor Provisioning: python3 scripts/agent_platform/create_online_monitor.py --project-id "<project_id>" --agent-resource-name "projects/<project_id>/locations/us-central1/reasoningEngines/<agent_id>"

    • Duplicate Policy Scanner: python3 scripts/agent_platform/scan_duplicates.py monitoring/

  3. If Online Monitor provisioning or Telemetry enablement is not pre-approved in the prompt, you MUST warn the user about the potential billing costs of both the Online Monitor and Telemetry (Cloud Trace/Logging export) and include an explicit direct question asking the user for approval before configuring or provisioning them.

  4. Always prompt the user to ask whether they would like to configure notification channels if none were provided.

  5. Include a user_labels block with created-with-google-skill = "cloud-monitoring-alert-configuration" on every google_monitoring_alert_policy resource.

Table of Contents

  • Verify Prerequisites: Lines 34-110

    • Prepare SQL Metric Prerequisites: Lines 36-82

    • Prepare PromQL Metric Prerequisites: Lines 83-110

  • Follow Critical Rules: Lines 111-149

    • Review Telemetry Metrics: Lines 136-149

  • Configure Policy Specifications: Lines 150-587

    • Configure Latency Alerts: Lines 152-286

    • Configure Error Rate Fast Burn SLO (1-Hour and 5-Minute Windows): Lines 287-382

    • Configure Error Rate Slow Burn SLO (3-Day and 6-Hour Windows): Lines 383-440

    • Configure Model Call Error Rate Alerts: Lines 441-514

    • Configure Tool Call Error Rate Alerts: Lines 515-587

  • Run Tooling Scripts: Lines 588-610

  • Validate and Finalize: Lines 611-663

Verify Prerequisites

Prepare SQL Metric Prerequisites
Retrieve the Trace Scope Observability Analytics Table

Retrieve the Observability Analytics table where all the Trace scope spans are stored for the SQL-based alerts.

A linked BigQuery dataset instance is required to configure SQL alert policies depending on Observability Analytics trace data. This dataset MUST hold views for the _Trace trace bucket of the target Google Cloud project.

Applicable BigQuery datasets have a "type": "LINKED" attribute and reference the _Trace bucket in their description. To list all existing BigQuery datasets in a project, run the following command:

bq ls --format=prettyjson --project_id={project_id}

Where:

  • {project_id}: The target Google Cloud project ID.

If missing, you MUST get user confirmation before creating it. If denied, skip SQL reliability alerts. Otherwise, create it using:

gcloud beta observability buckets datasets links create \
  projects/{project_id}/locations/{location}/buckets/{bucket_id}/datasets/{dataset_id}/links/{link_id} \
 --dataset={dataset_id} \
 --bucket={bucket_id} \
 --location={location} \
 --project={project_id}

Where:

  • {project_id}: Target Google Cloud project ID.

  • {location}: Observability bucket location (found in the Observability Analytics table name).

  • {bucket_id}: Bucket ID (default: _Trace).

  • {dataset_id}: Dataset ID (default: Spans).

  • {link_id}: New BigQuery dataset name (default: trace_bq_linked_dataset).

Prepare PromQL Metric Prerequisites
Select Algorithms and Map Policies

Alerting policies for agents MUST map to the appropriate algorithms to ensure statistical stability and prevent alert noise or blind spots based on data classes:

  • Latency: Follows the workload traffic pattern (Steady / Consistent -> 1w Z-Score Baseline or Short-Window Z-Score (1h baseline); Seasonal / Cyclical -> Seasonal Decomposition (average 1w and 1d); Bursty / Inconsistent -> Moving Averages).

  • Error Rate: ALWAYS use Multi-Window Multi-Burn Rate SLOs (or ratio-based static thresholds). Error rate is naturally sparse (0). If standard deviation is 0, Z-scores are mathematically unstable (division-by-zero), causing false alerts.

To resolve the workload traffic pattern (Seasonal / Cyclical, Steady / Consistent, or Bursty / Inconsistent), follow the instructions corresponding to the availability of historical metrics data:

Follow Critical Rules

  • Brand New Agents (No Traffic History): When setting up alerts for a brand new agent, you MUST explicitly ask the user what traffic pattern they expect (Steady / Consistent, Seasonal / Cyclical, or Bursty / Inconsistent) in your response. If immediate setup is requested, ask the question but proceed using the default Steady/Consistent (Short-Window Z-Score (1h baseline)) pattern. Follow agent_platform_no_historical_traffic_data.md.

  • Query Types for Reliability (No MQL or Threshold Filters):

    • For latency and container SLO error rate metrics, you MUST use condition_prometheus_query_language with PromQL.

    • For the downstream model call and tool call error rate metrics, you MUST use condition_sql with GoogleSQL querying _Trace.Spans._AllSpans.

    • Do NOT use Monitoring Query Language (MQL) or standard condition_threshold for these reliability metrics.

  • Critical alert thresholds: Configure alerts with a 5% critical threshold (aligned with the Vertex AI SLA uptime definition). For warning alerts, optionally configure a 1% threshold to catch downstream degradation or quota exhaustion before it affects user experience.

  • For Metrics using PromQL: ALWAYS use grouping aggregations. Group by gen_ai_agent_name (for example, by (gen_ai_agent_name)). Avoid filtering to a single ID or name unless requested. Metrics are emitted through OpenTelemetry.

Review Telemetry Metrics

All raw telemetry metrics for the Agent Platform container runtime are cumulative counters monitored using PromQL. Downstream model calls are tracked through OpenTelemetry Trace Spans exported to Observability Analytics and monitored using SQL queries.

SignalSource / Raw MetricTypeDescription
Latencygen_ai_invoke_agent_duration_bucketCounterHistogram bucket of agent request latencies
Error Rategen_ai_invoke_agent_duration_countCounterCumulative count of agent requests
Model Call Error Rateglobal._Trace.Spans._AllSpans viewTrace SpansDownstream LLM API call traces (status.code = 2 is error)
Tool Call Error Rateglobal._Trace.Spans._AllSpans viewTrace SpansDownstream tool execution traces (status.code = 2 is error)

Configure Policy Specifications

Configure Latency Alerts
Select the Latency Telemetry Query
Configure Z-Score for Steady Traffic

Long-Window Z-Score (1w Z-Score Baseline, for established agents with more than 1 week of history)

Compares the 5-minute 95th percentile latency to the 1-week baseline.

  • LATENCY_ALGORITHM_NAME_SHORT: "long_window_zscore"

  • LATENCY_ALGORITHM_NAME_LONG: "Long-Window Z-Score"

  • LATENCY_ALGORITHM_CONDITION_DESCRIPTION: "Z-Score > 3"

abs(
  histogram_quantile(0.95, sum(rate(workload_googleapis_com:gen_ai_invoke_agent_duration_bucket{monitored_resource="generic_node"}[5m])) by (le, gen_ai_agent_name))
  -
  histogram_quantile(0.95, sum(rate(workload_googleapis_com:gen_ai_invoke_agent_duration_bucket{monitored_resource="generic_node"}[1w])) by (le, gen_ai_agent_name))
)
/
stddev_over_time(
  (histogram_quantile(0.95, sum(rate(workload_googleapis_com:gen_ai_invoke_agent_duration_bucket{monitored_resource="generic_node"}[5m])) by (le, gen_ai_agent_name)))[1w:5m]
) > 3

Note: The denominator uses a subquery [1w:5m] to calculate standard deviation of the 5-minute latency over 1 week. The numerator uses [1w] rate directly to avoid a second subquery for the mean.

Short-Window Z-Score (Short-Window Z-Score (1h baseline), for newer agents with more than 1 hour of history)

Compares the 1-minute 95th percentile latency to the 1-hour baseline for rapid activation on new agents.

  • LATENCY_ALGORITHM_NAME_SHORT: "short_window_zscore"

  • LATENCY_ALGORITHM_NAME_LONG: "Short-Window Z-Score"

  • LATENCY_ALGORITHM_CONDITION_DESCRIPTION: "Z-Score > 3"

abs(
  histogram_quantile(0.95, sum(rate(workload_googleapis_com:gen_ai_invoke_agent_duration_bucket{monitored_resource="generic_node"}[1m])) by (le, gen_ai_agent_name))
  -
  histogram_quantile(0.95, sum(rate(workload_googleapis_com:gen_ai_invoke_agent_duration_bucket{monitored_resource="generic_node"}[1h])) by (le, gen_ai_agent_name))
)
/
stddev_over_time(
  (histogram_quantile(0.95, sum(rate(workload_googleapis_com:gen_ai_invoke_agent_duration_bucket{monitored_resource="generic_node"}[1m])) by (le, gen_ai_agent_name)))[1h:1m]
) > 3
Configure Moving Averages for Bursty Traffic

Compares the 5-minute latency to the 1-hour Moving Averages baseline.

  • LATENCY_ALGORITHM_NAME_SHORT: "moving_average"

  • LATENCY_ALGORITHM_NAME_LONG: "Moving Average"

  • LATENCY_ALGORITHM_CONDITION_DESCRIPTION: "5m Above 1h Average"

histogram_quantile(0.95, sum(rate(workload_googleapis_com:gen_ai_invoke_agent_duration_bucket{monitored_resource="generic_node"}[5m])) by (le, gen_ai_agent_name))
>
1.5 * histogram_quantile(0.95, sum(rate(workload_googleapis_com:gen_ai_invoke_agent_duration_bucket{monitored_resource="generic_node"}[1h])) by (le, gen_ai_agent_name))
Configure Seasonal Decomposition for Cyclical Traffic

[!NOTE] For the Latency alert policy, ONLY use seasonal decomposition (Seasonal Decomposition (average 1w and 1d)) to track latency spikes. Alert policies using seasonal decomposition tracking both spikes and drops can falsely trigger alerts.

Compares the 5-minute latency to the average of 1-week and 1-day lookback baselines.

[!CAUTION] The numerator (current latency) MUST NOT have any offset. Offsets (offset 1d, offset 1w) MUST only be applied to the denominator to construct the historical baseline for comparison. Never apply an offset to the first numerator.

  • LATENCY_ALGORITHM_NAME_SHORT: "seasonal_decomposition"

  • LATENCY_ALGORITHM_NAME_LONG: "Seasonal Decomposition"

  • LATENCY_ALGORITHM_CONDITION_DESCRIPTION: "Seasonal Decomposition > 2"

histogram_quantile(0.95, sum(rate(workload_googleapis_com:gen_ai_invoke_agent_duration_bucket{monitored_resource="generic_node"}[5m])) by (le, gen_ai_agent_name))
/
(
  (
    histogram_quantile(0.95, sum(rate(workload_googleapis_com:gen_ai_invoke_agent_duration_bucket{monitored_resource="generic_node"}[5m] offset 1d)) by (le, gen_ai_agent_name))
    +
    histogram_quantile(0.95, sum(rate(workload_googleapis_com:gen_ai_invoke_agent_duration_bucket{monitored_resource="generic_node"}[5m] offset 1w)) by (le, gen_ai_agent_name))
  ) / 2
)
> 2
Define Terraform HCL for Latency
resource "google_monitoring_alert_policy" "latency_{latency_algorithm_name_short}" {
  project      = var.project_id
  display_name = "Agent Reliability - Latency {latency_algorithm_name_long}"
  combiner     = "OR"

  conditions {
    display_name = "Latency {latency_algorithm_condition_description}"
    condition_prometheus_query_language {
      query    = <<EOT
{latency_telemetry_query}
EOT
    }
  }

  documentation {
    content   = "High latency detected for the agent."
    mime_type = "text/markdown"
    subject   = "Agent Reliability - Latency {latency_algorithm_name_long} on $${metric.label.gen_ai_agent_name}"
  }

  user_labels = {
    created-with-google-skill = "cloud-monitoring-alert-configuration"
  }
}

Where:

  • {latency_algorithm_name_short}: Short algorithm name.

  • {latency_algorithm_name_long}: Long algorithm name.

  • {latency_algorithm_condition_description}: Condition description.

  • {latency_telemetry_query}: PromQL query from above.

Configure Error Rate Fast Burn SLO (1-Hour and 5-Minute Windows)

[!IMPORTANT] SLO standard alignment. The Fast Burn (factor 14.4, 1h & 5m windows, duration = "300s") and Slow Burn (factor 1.0, 3d & 6h windows, no duration because the lookback exceeds 25h) policies below are the Agent Platform implementation of the standard SRE burn-rate contract, and remain the authoritative templates for agent reliability alerts.

This is a deliberate exception to the skill-wide delegation rule: Agent Platform is the one resource whose burn-rate policies live in this skill. If the user asks to customize the SLO — a different target, a latency SLO, window-based "good minutes" evaluation, or App Hub scoping — delegate to the google-cloud-slo-alert-configuration skill, which owns the SLO wizard, the burn-rate templates (references/promql_templates.md), the SLI mapping (references/service_metrics.md), and the App Hub scoping labels (references/app_hub_labels.md).

Context to hand off (so the SLO skill does not repeat discovery):

  • Resource type: an OpenTelemetry-instrumented AI agent. This is runtime-agnostic — the agent may run on Vertex AI Agent Engine, Cloud Run, or any other OpenTelemetry-instrumented host. Do not hand off a Vertex-specific monitored resource: these are generic OpenTelemetry workload metrics, which land under generic_node, and every query in this file filters monitored_resource="generic_node".

  • Grouping labels: gen_ai_agent_name.

  • Error rate SLI: workload_googleapis_com:gen_ai_invoke_agent_duration_count; bad = error_type!="".

  • Latency SLI: workload_googleapis_com:gen_ai_invoke_agent_duration_bucket; percentile using histogram_quantile(q, sum(rate(...)) by (le, gen_ai_agent_name)).

  • SLO target: slo_target (default 0.999).

Model call and tool call error rates are not available as SLIs: they are derived from trace spans in global._Trace.Spans._AllSpans using SQL, not PromQL, so the SLO skill cannot build burn-rate queries from them.

Define variable "slo_target" (default 0.999) in the generated Terraform so the burn-rate thresholds stay parameterized.

Define the Fast Burn Telemetry Query

Always use Multi-Window Multi-Burn Rate SLOs. Z-score is not recommended due to sparsity.

(
  sum(rate(workload_googleapis_com:gen_ai_invoke_agent_duration_count{monitored_resource="generic_node",error_type!=""}[5m])) by (gen_ai_agent_name)
  /
  sum(rate(workload_googleapis_com:gen_ai_invoke_agent_duration_count{monitored_resource="generic_node"}[5m])) by (gen_ai_agent_name)
  > (1 - ${var.slo_target}) * 14.4
)
and
(
  sum(rate(workload_googleapis_com:gen_ai_invoke_agent_duration_count{monitored_resource="generic_node",error_type!=""}[1h])) by (gen_ai_agent_name)
  /
  sum(rate(workload_googleapis_com:gen_ai_invoke_agent_duration_count{monitored_resource="generic_node"}[1h])) by (gen_ai_agent_name)
  > (1 - ${var.slo_target}) * 14.4
)
Define Terraform HCL for Fast Burn SLO
resource "google_monitoring_alert_policy" "error_rate_fast_burn" {
  project      = var.project_id
  display_name = "Agent Reliability - Error Rate Fast Burn SLO"
  combiner     = "OR"

  conditions {
    display_name = "Error Rate Fast Burn (1h/5m)"
    condition_prometheus_query_language {
      query    = {error_rate_fast_slo_telemetry_query}
      duration = "300s" # 5m buffer
    }
  }

  documentation {
    content   = "Fast Burn error rate SLO violation detected."
    mime_type = "text/markdown"
    subject   = "Error Rate Fast Burn (1h/5m) on $${metric.label.gen_ai_agent_name}"
  }

  user_labels = {
    created-with-google-skill = "cloud-monitoring-alert-configuration"
  }
}

Where:

  • {error_rate_fast_slo_telemetry_query}: The PromQL alert query configured in Define the Fast Burn Telemetry Query above.

Configure Error Rate Slow Burn SLO (3-Day and 6-Hour Windows)
Define the Slow Burn Telemetry Query

Always use Multi-Window Multi-Burn Rate SLOs. Z-score is not recommended due to sparsity.

(
  sum(rate(workload_googleapis_com:gen_ai_invoke_agent_duration_count{monitored_resource="generic_node",error_type!=""}[6h])) by (gen_ai_agent_name)
  /
  sum(rate(workload_googleapis_com:gen_ai_invoke_agent_duration_count{monitored_resource="generic_node"}[6h])) by (gen_ai_agent_name)
  > (1 - ${var.slo_target}) * 1.0
)
and
(
  sum(rate(workload_googleapis_com:gen_ai_invoke_agent_duration_count{monitored_resource="generic_node",error_type!=""}[3d])) by (gen_ai_agent_name)
  /
  sum(rate(workload_googleapis_com:gen_ai_invoke_agent_duration_count{monitored_resource="generic_node"}[3d])) by (gen_ai_agent_name)
  > (1 - ${var.slo_target}) * 1.0
)
Define Terraform HCL for Slow Burn SLO
resource "google_monitoring_alert_policy" "error_rate_slow_burn" {
  project      = var.project_id
  display_name = "Agent Reliability - Error Rate Slow Burn SLO"
  combiner     = "OR"

  conditions {
    display_name = "Error Rate Slow Burn (3d/6h)"
    condition_prometheus_query_language {
      query = <<EOT
{error_rate_slow_slo_telemetry_query}
EOT
    }
  }

  documentation {
    content   = "Slow Burn error rate SLO violation detected."
    mime_type = "text/markdown"
    subject   = "Error Rate Slow Burn (3d/6h) on $${metric.label.gen_ai_agent_name}"
  }

  user_labels = {
    created-with-google-skill = "cloud-monitoring-alert-configuration"
  }
}

Where:

  • {error_rate_slow_slo_telemetry_query}: The PromQL alert query configured in Define the Slow Burn Telemetry Query above.

Configure Model Call Error Rate Alerts
Define the Model Call Error Rate Query

When configuring a SQL-based alerting condition (condition_sql) in Google Cloud Monitoring for an agent, use the following template to query trace spans exported to Observability Analytics:

SELECT
  JSON_VALUE(resource.attributes, '$."cloud.resource_id"') as agent_id,
  JSON_VALUE(attributes, '$."gen_ai.request.model"') as model,
  (COUNTIF(status.code = 2) * 100.0) / COUNT(*) AS model_error_rate
FROM
  `${TRACE_SCOPE_TABLE_NAME}`
WHERE
  JSON_VALUE(attributes, '$."gen_ai.request.model"') IS NOT NULL
GROUP BY
  agent_id,
  model
HAVING
  model_error_rate > 5.0

Where:

  • {trace_scope_table_name}: The Trace scope Observability Analytics table name retrieved in Verify Prerequisites.

Define Terraform HCL for Model Call Error Rate

Implement the alert policy resource using a condition_sql block with a row_count_test condition:

resource "google_monitoring_alert_policy" "model_call_error_rate" {
  project      = var.project_id
  display_name = "Agent Reliability - High Model Call Error Rate"
  combiner     = "OR"

  conditions {
    display_name = "Agent Model Call Error Rate Exceeds 5%"
    condition_sql {
      query = <<EOT
{model_call_high_error_rate_telemetry_query}
EOT

      # Run evaluation periodically (periodicity value must be between 5 and 1440 minutes)
      minutes {
        periodicity = 5
      }

      # Test triggers when one or more models violate the threshold (returning rows)
      row_count_test {
        comparison = "COMPARISON_GT"
        threshold  = 0
      }
    }
  }

  user_labels = {
    created-with-google-skill = "cloud-monitoring-alert-configuration"
  }

  notification_channels = [google_monitoring_notification_channel.email.name]
}

Where:

  • {model_call_high_error_rate_telemetry_query}: The SQL alert query configured in Define the Model Call Error Rate Query above.

Configure Tool Call Error Rate Alerts
Define the Tool Call Error Rate Query

When configuring a SQL-based alerting condition (condition_sql) in Google Cloud Monitoring for an agent to monitor tool call error rates, use the following template to query trace spans exported to Observability Analytics:

SELECT
  JSON_VALUE(resource.attributes, '$."cloud.resource_id"') as agent_id,
  JSON_VALUE(attributes, '$."gen_ai.tool.name"') as tool_name,
  (COUNTIF(status.code = 2) * 100.0) / COUNT(*) AS tool_error_rate
FROM
  `${TRACE_SCOPE_TABLE_NAME}`
WHERE
  JSON_VALUE(attributes, '$."gen_ai.operation.name"') = 'execute_tool'
  AND JSON_VALUE(attributes, '$."gen_ai.tool.name"') IS NOT NULL
GROUP BY
  agent_id,
  tool_name
HAVING
  tool_error_rate > 5.0

Where:

  • {trace_scope_table_name}: The Trace scope Observability Analytics table name retrieved in Verify Prerequisites.

Define Terraform HCL for Tool Call Error Rate

Implement the alert policy resource using a condition_sql block with a row_count_test condition:

resource "google_monitoring_alert_policy" "tool_call_error_rate" {
  project      = var.project_id
  display_name = "Agent Reliability - High Tool Call Error Rate"
  combiner     = "OR"

  conditions {
    display_name = "Agent Tool Call Error Rate Exceeds 5%"
    condition_sql {
      query = <<EOT
{tool_call_high_error_rate_telemetry_query}
EOT

      minutes {
        periodicity = 5
      }

      row_count_test {
        comparison = "COMPARISON_GT"
        threshold  = 0
      }
    }
  }

  user_labels = {
    created-with-google-skill = "cloud-monitoring-alert-configuration"
  }

  notification_channels = [google_monitoring_notification_channel.email.name]
}

Where:

  • {tool_call_high_error_rate_telemetry_query}: The SQL alert query configured in Define the Tool Call Error Rate Query above.

Run Tooling Scripts

  1. gather_agent_info (Primary Streamlined Discovery — REQUIRED): Always run (or print when execution is disabled) this streamlined discovery command first with all parameter values filled in, even if a fallback table name is provided:

    • Command: python3 scripts/agent_platform/gather_agent_info.py --project-id="{gcp_project}" --agent-name="{agent_name}"

  2. scan_duplicates (Required Duplicate Policy Verification): Always run (or print when execution is disabled) this command to verify that no duplicate alert policy blocks exist:

    • Command: python3 scripts/agent_platform/scan_duplicates.py monitoring/

  3. lint_syntax (HCL and PromQL Syntax Validation): When reviewing, validating, or correcting an existing or draft .tf file for an AI agent, run (or print when execution is disabled) this linter to check for balanced parentheses/braces, valid PromQL time windows ([5m], [1w:5m]), agent identifier grouping (gen_ai_agent_name), and duration buffer rules:

    • Command: python3 scripts/agent_platform/lint_syntax.py <path_to_tf_file>

  4. list_trace_scope_table_names (Fallback): Use this script ONLY if gather_agent_info.py fails to retrieve the associated Trace scope Observability Analytics SQL table name:

    • Command: python3 scripts/agent_platform/list_trace_scope_table_names.py --project_id={gcp_project}

Validate and Finalize

  • Lint Draft HCL and PromQL Queries: When asked to validate or fix draft agent alert configurations (for example, in draft_invalid_query.tf or monitoring/alerts.tf), run python3 scripts/agent_platform/lint_syntax.py <path_to_tf_file> to detect and auto-correct unbalanced parentheses or braces, invalid time window units, missing gen_ai_agent_name grouping, and invalid duration buffers on long-lookback (>25h) queries.

  • Enforce SQL Alert Constraints:

    1. No manual timestamp filters or temporal groupings.

    2. Group by agent identifier: Use cloud.resource_id (Reasoning Engine ID or Cloud Run service) to monitor dynamically. Do NOT filter for specific agents unless requested.

    3. Aggregate failures: Group by agent or tool name, calculating the ratio of failed requests (status code 2 indicating ERROR) to total requests.

    4. Use HAVING clause to filter out healthy tools and models.

    5. Pinning (Only if explicitly requested): Use ENDS_WITH(JSON_VALUE(resource.attributes, '$."cloud.resource_id"'), 'AGENT_IDENTIFIER') with a string identifier (for example, 'support-bot'), not numeric, unless instructed. Customize this filter only when explicitly requested; otherwise avoid pinning in favor of dynamic grouping as described in the main skill instructions.

  • Configure Duration Buffers (Transient Glitches): To avoid alerts firing on transient spikes, use duration and retest window buffers appropriately:

    • Reliability Metrics (PromQL / Cloud Monitoring):

      • For short-lookback alerts querying data under 25 hours (such as Short-Window Z-Score (1h baseline), Moving Averages, and Fast Burn SLO), ALWAYS use a duration = "300s" (5 minutes) buffer to filter out transient cold start or deployment spikes.

      • For long-lookback alerts querying data longer than 25 hours (such as 1w Z-Score Baseline, Seasonal Decomposition (average 1w and 1d), and Slow Burn SLO), duration and retest windows are disabled by the platform. Do not set a duration (omit it entirely).

  • Explain the Dynamic Baseline Adaptation Blind Spot: Explain to users that dynamic statistical Z-score thresholds compare current rates to a moving statistical baseline. If a system degrades slowly over days, the standard baseline curve adapts to this slow drift, making standard Z-score alerts blind to persistent slow errors. Recommend a hard static threshold alert in parallel for strict SLA enforcement.

  • Prevent Seasonal Decomposition Double Alerting: Configure seasonal decomposition alert policies ONLY to track spikes (for example, latency spikes) OR drops, and NEVER use dual-direction evaluations (such as absolute deviation). Explain this limitation to the user: when comparing to a historical offset (for example, offset 1w), the alert policy triggers twice if tracking both directions (when the anomaly first occurs, and again after 1 week when the anomaly becomes the baseline). To prevent this, the generated policy MUST only track either spikes (using >) or drops (using <), avoiding abs().

  • Handle Script Failures: If list_trace_scope_table_names.py fails unexpectedly, verify the project ID and ensure you have permissions to view trace scopes and linked datasets.

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Needs: Needs Python

Security

What our scanner noticed· Low risk

  • Scripts that your agent may run

This skill includes scripts that your agent may run. Read them before you use it.

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Published by
Google
Publisher
Google (Official)
Source
google/skills · skills/cloud/cloud-monitoring-alert-configuration · commit 2194d3b
Licence
Apache License 2.0 (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced

AutoGineer is not affiliated with or endorsed by Google or Google.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download cloud-monitoring-alert-configuration.zip