google-cloud-platformalertmonitoringmql

GCP Alert policy MQL query


I need to build a GCP alert policy to be triggered if the total amount of a metric from this week is more than x % of the previous week. I think I need to use a conditional threshold.


Solution

  • You can create both threshold and absence alerting policies with MQL.

    You create an MQL-based alerting policy by using one of the following MQL alerting operations in your query:

    1. condition operation for threshold alerts.
    2. absent_for operation for absence alerts.

    Your query must end with one of these operations. Your query must omit an explicit time-range specification, that is, a within operation.

    For threshold alerts, use the condition operation. The condition operation takes an expression that evaluates a value against a threshold, like "the value is greater than 15 percent", and returns a boolean.

    The condition operation requires that the input table be aligned with an explicit alignment window. To align the input table with an explicit window, specify an alignment window to an align operation—for example, align delta_gauge(5m)—or use a temporal group_by with a sliding time window. The following example illustrates using group_by with a sliding operation:

    fetch gce_instance::compute.googleapis.com/instance/cpu/utilization
    | filter zone =~ 'us-central.*'
    | group_by sliding(5m), mean(val())
    | condition val() > .15 '10^2.%'
    

    Refer the document on Creating alert policies with MQL for more detailed information.