Skip to content

googleMonitoringAlertPolicy

A description of the conditions under which some aspect of your system is considered to be "unhealthy" and the ways to notify people or services about this state.

To get more information about AlertPolicy, see:

Example Usage - Monitoring Alert Policy Basic

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.monitoringAlertPolicy.MonitoringAlertPolicy(this, "alert_policy", {
  combiner: "OR",
  conditions: [
    {
      condition_threshold: [
        {
          aggregations: [
            {
              alignment_period: "60s",
              per_series_aligner: "ALIGN_RATE",
            },
          ],
          comparison: "COMPARISON_GT",
          duration: "60s",
          filter:
            'metric.type="compute.googleapis.com/instance/disk/write_bytes_count" AND resource.type="gce_instance"',
        },
      ],
      display_name: "test condition",
    },
  ],
  display_name: "My Alert Policy",
  user_labels: [
    {
      foo: "bar",
    },
  ],
});

Example Usage - Monitoring Alert Policy Evaluation Missing Data

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.monitoringAlertPolicy.MonitoringAlertPolicy(this, "alert_policy", {
  combiner: "OR",
  conditions: [
    {
      condition_threshold: [
        {
          aggregations: [
            {
              alignment_period: "60s",
              per_series_aligner: "ALIGN_RATE",
            },
          ],
          comparison: "COMPARISON_GT",
          duration: "60s",
          evaluation_missing_data: "EVALUATION_MISSING_DATA_INACTIVE",
          filter:
            'metric.type="compute.googleapis.com/instance/disk/write_bytes_count" AND resource.type="gce_instance"',
        },
      ],
      display_name: "test condition",
    },
  ],
  display_name: "My Alert Policy",
  user_labels: [
    {
      foo: "bar",
    },
  ],
});

Argument Reference

The following arguments are supported:

  • displayName - (Required) A short name or phrase used to identify the policy in dashboards, notifications, and incidents. To avoid confusion, don't use the same display name for multiple policies in the same project. The name is limited to 512 Unicode characters.

  • combiner - (Required) How to combine the results of multiple conditions to determine if an incident should be opened. Possible values are and, or, and andWithMatchingResource.

  • conditions - (Required) A list of conditions for the policy. The conditions are combined by AND or OR according to the combiner field. If the combined conditions evaluate to true, then an incident is created. A policy can have from one to six conditions. Structure is documented below.

The conditions block supports:

  • conditionAbsent - (Optional) A condition that checks that a time series continues to receive new data points. Structure is documented below.

  • name - (Output) The unique resource name for this condition. Its syntax is: projects/[PROJECT_ID]/alertPolicies/[POLICY_ID]/conditions/[CONDITION_ID] [CONDITION_ID] is assigned by Stackdriver Monitoring when the condition is created as part of a new or updated alerting policy.

  • conditionMonitoringQueryLanguage - (Optional) A Monitoring Query Language query that outputs a boolean stream Structure is documented below.

  • conditionThreshold - (Optional) A condition that compares a time series against a threshold. Structure is documented below.

  • displayName - (Required) A short name or phrase used to identify the condition in dashboards, notifications, and incidents. To avoid confusion, don't use the same display name for multiple conditions in the same policy.

  • conditionMatchedLog - (Optional) A condition that checks for log messages matching given constraints. If set, no other conditions can be present. Structure is documented below.

The conditionAbsent block supports:

  • aggregations - (Optional) Specifies the alignment of data points in individual time series as well as how to combine the retrieved time series together (such as when aggregating multiple streams on each resource to a single stream for each resource or when aggregating streams across all members of a group of resources). Multiple aggregations are applied in the order specified. Structure is documented below.

  • trigger - (Optional) The number/percent of time series for which the comparison must hold in order for the condition to trigger. If unspecified, then the condition will trigger if the comparison is true for any of the time series that have been identified by filter and aggregations. Structure is documented below.

  • duration - (Required) The amount of time that a time series must fail to report new data to be considered failing. Currently, only values that are a multiple of a minute--e.g. 60s, 120s, or 300s --are supported.

  • filter - (Optional) A filter that identifies which time series should be compared with the threshold.The filter is similar to the one that is specified in the MetricService.ListTimeSeries request (that call is useful to verify the time series that will be retrieved / processed) and must specify the metric type and optionally may contain restrictions on resource type, resource labels, and metric labels. This field may not exceed 2048 Unicode characters in length.

The aggregations block supports:

  • perSeriesAligner - (Optional) The approach to be used to align individual time series. Not all alignment functions may be applied to all time series, depending on the metric type and value type of the original time series. Alignment may change the metric type or the value type of the time series.Time series data must be aligned in order to perform cross- time series reduction. If crossSeriesReducer is specified, then perSeriesAligner must be specified and not equal ALIGN_NONE and alignmentPeriod must be specified; otherwise, an error is returned. Possible values are alignNone, alignDelta, alignRate, alignInterpolate, alignNextOlder, alignMin, alignMax, alignMean, alignCount, alignSum, alignStddev, alignCountTrue, alignCountFalse, alignFractionTrue, alignPercentile99, alignPercentile95, alignPercentile50, alignPercentile05, and alignPercentChange.

  • groupByFields - (Optional) The set of fields to preserve when crossSeriesReducer is specified. The groupByFields determine how the time series are partitioned into subsets prior to applying the aggregation function. Each subset contains time series that have the same value for each of the grouping fields. Each individual time series is a member of exactly one subset. The crossSeriesReducer is applied to each subset of time series. It is not possible to reduce across different resource types, so this field implicitly contains resource.type. Fields not specified in groupByFields are aggregated away. If groupByFields is not specified and all the time series have the same resource type, then the time series are aggregated into a single output time series. If crossSeriesReducer is not defined, this field is ignored.

  • alignmentPeriod - (Optional) The alignment period for per-time series alignment. If present, alignmentPeriod must be at least 60 seconds. After per-time series alignment, each time series will contain data points only on the period boundaries. If perSeriesAligner is not specified or equals ALIGN_NONE, then this field is ignored. If perSeriesAligner is specified and does not equal ALIGN_NONE, then this field must be defined; otherwise an error is returned.

  • crossSeriesReducer - (Optional) The approach to be used to combine time series. Not all reducer functions may be applied to all time series, depending on the metric type and the value type of the original time series. Reduction may change the metric type of value type of the time series.Time series data must be aligned in order to perform cross- time series reduction. If crossSeriesReducer is specified, then perSeriesAligner must be specified and not equal ALIGN_NONE and alignmentPeriod must be specified; otherwise, an error is returned. Possible values are reduceNone, reduceMean, reduceMin, reduceMax, reduceSum, reduceStddev, reduceCount, reduceCountTrue, reduceCountFalse, reduceFractionTrue, reducePercentile99, reducePercentile95, reducePercentile50, and reducePercentile05.

The trigger block supports:

  • percent - (Optional) The percentage of time series that must fail the predicate for the condition to be triggered.

  • count - (Optional) The absolute number of time series that must fail the predicate for the condition to be triggered.

The conditionMonitoringQueryLanguage block supports:

  • query - (Required) Monitoring Query Language query that outputs a boolean stream.

  • duration - (Required) The amount of time that a time series must violate the threshold to be considered failing. Currently, only values that are a multiple of a minute--e.g., 0, 60, 120, or 300 seconds--are supported. If an invalid value is given, an error will be returned. When choosing a duration, it is useful to keep in mind the frequency of the underlying time series data (which may also be affected by any alignments specified in the aggregations field); a good duration is long enough so that a single outlier does not generate spurious alerts, but short enough that unhealthy states are detected and alerted on quickly.

  • trigger - (Optional) The number/percent of time series for which the comparison must hold in order for the condition to trigger. If unspecified, then the condition will trigger if the comparison is true for any of the time series that have been identified by filter and aggregations, or by the ratio, if denominator_filter and denominator_aggregations are specified. Structure is documented below.

  • evaluationMissingData - (Optional) A condition control that determines how metric-threshold conditions are evaluated when data stops arriving. Possible values are evaluationMissingDataInactive, evaluationMissingDataActive, and evaluationMissingDataNoOp.

The trigger block supports:

  • percent - (Optional) The percentage of time series that must fail the predicate for the condition to be triggered.

  • count - (Optional) The absolute number of time series that must fail the predicate for the condition to be triggered.

The conditionThreshold block supports:

  • thresholdValue - (Optional) A value against which to compare the time series.

  • denominatorFilter - (Optional) A filter that identifies a time series that should be used as the denominator of a ratio that will be compared with the threshold. If a denominator_filter is specified, the time series specified by the filter field will be used as the numerator.The filter is similar to the one that is specified in the MetricService.ListTimeSeries request (that call is useful to verify the time series that will be retrieved / processed) and must specify the metric type and optionally may contain restrictions on resource type, resource labels, and metric labels. This field may not exceed 2048 Unicode characters in length.

  • denominatorAggregations - (Optional) Specifies the alignment of data points in individual time series selected by denominatorFilter as well as how to combine the retrieved time series together (such as when aggregating multiple streams on each resource to a single stream for each resource or when aggregating streams across all members of a group of resources).When computing ratios, the aggregations and denominator_aggregations fields must use the same alignment period and produce time series that have the same periodicity and labels.This field is similar to the one in the MetricService.ListTimeSeries request. It is advisable to use the ListTimeSeries method when debugging this field. Structure is documented below.

  • duration - (Required) The amount of time that a time series must violate the threshold to be considered failing. Currently, only values that are a multiple of a minute--e.g., 0, 60, 120, or 300 seconds--are supported. If an invalid value is given, an error will be returned. When choosing a duration, it is useful to keep in mind the frequency of the underlying time series data (which may also be affected by any alignments specified in the aggregations field); a good duration is long enough so that a single outlier does not generate spurious alerts, but short enough that unhealthy states are detected and alerted on quickly.

  • comparison - (Required) The comparison to apply between the time series (indicated by filter and aggregation) and the threshold (indicated by threshold_value). The comparison is applied on each time series, with the time series on the left-hand side and the threshold on the right-hand side. Only COMPARISON_LT and COMPARISON_GT are supported currently. Possible values are comparisonGt, comparisonGe, comparisonLt, comparisonLe, comparisonEq, and comparisonNe.

  • trigger - (Optional) The number/percent of time series for which the comparison must hold in order for the condition to trigger. If unspecified, then the condition will trigger if the comparison is true for any of the time series that have been identified by filter and aggregations, or by the ratio, if denominator_filter and denominator_aggregations are specified. Structure is documented below.

  • aggregations - (Optional) Specifies the alignment of data points in individual time series as well as how to combine the retrieved time series together (such as when aggregating multiple streams on each resource to a single stream for each resource or when aggregating streams across all members of a group of resources). Multiple aggregations are applied in the order specified.This field is similar to the one in the MetricService.ListTimeSeries request. It is advisable to use the ListTimeSeries method when debugging this field. Structure is documented below.

  • filter - (Optional) A filter that identifies which time series should be compared with the threshold.The filter is similar to the one that is specified in the MetricService.ListTimeSeries request (that call is useful to verify the time series that will be retrieved / processed) and must specify the metric type and optionally may contain restrictions on resource type, resource labels, and metric labels. This field may not exceed 2048 Unicode characters in length.

  • evaluationMissingData - (Optional) A condition control that determines how metric-threshold conditions are evaluated when data stops arriving. Possible values are evaluationMissingDataInactive, evaluationMissingDataActive, and evaluationMissingDataNoOp.

The denominatorAggregations block supports:

  • perSeriesAligner - (Optional) The approach to be used to align individual time series. Not all alignment functions may be applied to all time series, depending on the metric type and value type of the original time series. Alignment may change the metric type or the value type of the time series.Time series data must be aligned in order to perform cross- time series reduction. If crossSeriesReducer is specified, then perSeriesAligner must be specified and not equal ALIGN_NONE and alignmentPeriod must be specified; otherwise, an error is returned. Possible values are alignNone, alignDelta, alignRate, alignInterpolate, alignNextOlder, alignMin, alignMax, alignMean, alignCount, alignSum, alignStddev, alignCountTrue, alignCountFalse, alignFractionTrue, alignPercentile99, alignPercentile95, alignPercentile50, alignPercentile05, and alignPercentChange.

  • groupByFields - (Optional) The set of fields to preserve when crossSeriesReducer is specified. The groupByFields determine how the time series are partitioned into subsets prior to applying the aggregation function. Each subset contains time series that have the same value for each of the grouping fields. Each individual time series is a member of exactly one subset. The crossSeriesReducer is applied to each subset of time series. It is not possible to reduce across different resource types, so this field implicitly contains resource.type. Fields not specified in groupByFields are aggregated away. If groupByFields is not specified and all the time series have the same resource type, then the time series are aggregated into a single output time series. If crossSeriesReducer is not defined, this field is ignored.

  • alignmentPeriod - (Optional) The alignment period for per-time series alignment. If present, alignmentPeriod must be at least 60 seconds. After per-time series alignment, each time series will contain data points only on the period boundaries. If perSeriesAligner is not specified or equals ALIGN_NONE, then this field is ignored. If perSeriesAligner is specified and does not equal ALIGN_NONE, then this field must be defined; otherwise an error is returned.

  • crossSeriesReducer - (Optional) The approach to be used to combine time series. Not all reducer functions may be applied to all time series, depending on the metric type and the value type of the original time series. Reduction may change the metric type of value type of the time series.Time series data must be aligned in order to perform cross- time series reduction. If crossSeriesReducer is specified, then perSeriesAligner must be specified and not equal ALIGN_NONE and alignmentPeriod must be specified; otherwise, an error is returned. Possible values are reduceNone, reduceMean, reduceMin, reduceMax, reduceSum, reduceStddev, reduceCount, reduceCountTrue, reduceCountFalse, reduceFractionTrue, reducePercentile99, reducePercentile95, reducePercentile50, and reducePercentile05.

The trigger block supports:

  • percent - (Optional) The percentage of time series that must fail the predicate for the condition to be triggered.

  • count - (Optional) The absolute number of time series that must fail the predicate for the condition to be triggered.

The aggregations block supports:

  • perSeriesAligner - (Optional) The approach to be used to align individual time series. Not all alignment functions may be applied to all time series, depending on the metric type and value type of the original time series. Alignment may change the metric type or the value type of the time series.Time series data must be aligned in order to perform cross- time series reduction. If crossSeriesReducer is specified, then perSeriesAligner must be specified and not equal ALIGN_NONE and alignmentPeriod must be specified; otherwise, an error is returned. Possible values are alignNone, alignDelta, alignRate, alignInterpolate, alignNextOlder, alignMin, alignMax, alignMean, alignCount, alignSum, alignStddev, alignCountTrue, alignCountFalse, alignFractionTrue, alignPercentile99, alignPercentile95, alignPercentile50, alignPercentile05, and alignPercentChange.

  • groupByFields - (Optional) The set of fields to preserve when crossSeriesReducer is specified. The groupByFields determine how the time series are partitioned into subsets prior to applying the aggregation function. Each subset contains time series that have the same value for each of the grouping fields. Each individual time series is a member of exactly one subset. The crossSeriesReducer is applied to each subset of time series. It is not possible to reduce across different resource types, so this field implicitly contains resource.type. Fields not specified in groupByFields are aggregated away. If groupByFields is not specified and all the time series have the same resource type, then the time series are aggregated into a single output time series. If crossSeriesReducer is not defined, this field is ignored.

  • alignmentPeriod - (Optional) The alignment period for per-time series alignment. If present, alignmentPeriod must be at least 60 seconds. After per-time series alignment, each time series will contain data points only on the period boundaries. If perSeriesAligner is not specified or equals ALIGN_NONE, then this field is ignored. If perSeriesAligner is specified and does not equal ALIGN_NONE, then this field must be defined; otherwise an error is returned.

  • crossSeriesReducer - (Optional) The approach to be used to combine time series. Not all reducer functions may be applied to all time series, depending on the metric type and the value type of the original time series. Reduction may change the metric type of value type of the time series.Time series data must be aligned in order to perform cross- time series reduction. If crossSeriesReducer is specified, then perSeriesAligner must be specified and not equal ALIGN_NONE and alignmentPeriod must be specified; otherwise, an error is returned. Possible values are reduceNone, reduceMean, reduceMin, reduceMax, reduceSum, reduceStddev, reduceCount, reduceCountTrue, reduceCountFalse, reduceFractionTrue, reducePercentile99, reducePercentile95, reducePercentile50, and reducePercentile05.

The conditionMatchedLog block supports:

  • filter - (Required) A logs-based filter.

  • labelExtractors - (Optional) A map from a label key to an extractor expression, which is used to extract the value for this label key. Each entry in this map is a specification for how data should be extracted from log entries that match filter. Each combination of extracted values is treated as a separate rule for the purposes of triggering notifications. Label keys and corresponding values can be used in notifications generated by this condition.


  • enabled - (Optional) Whether or not the policy is enabled. The default is true.

  • notificationChannels - (Optional) Identifies the notification channels to which notifications should be sent when incidents are opened or closed or when new violations occur on an already opened incident. Each element of this array corresponds to the name field in each of the NotificationChannel objects that are returned from the notificationChannels.list method. The syntax of the entries in this field is projects/[projectId]/notificationChannels/[channelId]

  • alertStrategy - (Optional) Control over how this alert policy's notification channels are notified. Structure is documented below.

  • userLabels - (Optional) This field is intended to be used for organizing and identifying the AlertPolicy objects.The field can contain up to 64 entries. Each key and value is limited to 63 Unicode characters or 128 bytes, whichever is smaller. Labels and values can contain only lowercase letters, numerals, underscores, and dashes. Keys must begin with a letter.

  • documentation - (Optional) Documentation that is included with notifications and incidents related to this policy. Best practice is for the documentation to include information to help responders understand, mitigate, escalate, and correct the underlying problems detected by the alerting policy. Notification channels that have limited capacity might not show this documentation. Structure is documented below.

  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

The alertStrategy block supports:

  • notificationRateLimit - (Optional) Required for alert policies with a LogMatch condition. This limit is not implemented for alert policies that are not log-based. Structure is documented below.

  • autoClose - (Optional) If an alert policy that was active has no data for this long, any open incidents will close.

The notificationRateLimit block supports:

  • period - (Optional) Not more than one notification per period.

The documentation block supports:

  • content - (Optional) The text of the documentation, interpreted according to mimeType. The content may not exceed 8,192 Unicode characters and may not exceed more than 10,240 bytes when encoded in UTF-8 format, whichever is smaller.

  • mimeType - (Optional) The format of the content field. Presently, only the value "text/markdown" is supported.

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

  • id - an identifier for the resource with format {{name}}

  • name - The unique resource name for this policy. Its syntax is: projects/[PROJECT_ID]/alertPolicies/[ALERT_POLICY_ID]

  • creationRecord - A read-only record of the creation of the alerting policy. If provided in a call to create or update, this field will be ignored. Structure is documented below.

The creationRecord block contains:

  • mutateTime - (Output) When the change occurred.

  • mutatedBy - (Output) The email address of the user making the change.

Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 20 minutes.
  • update - Default is 20 minutes.
  • delete - Default is 20 minutes.

Import

AlertPolicy can be imported using any of these accepted formats:

$ terraform import google_monitoring_alert_policy.default {{name}}

User Project Overrides

This resource supports User Project Overrides.