Skip to content
v2.274.0

AnomalyDetectionAlarmProps Struct ​

Properties for Anomaly Detection Alarms.

Example ​

ts
// Create a metric
const metric = new cloudwatch.Metric({
  namespace: 'AWS/EC2',
  metricName: 'CPUUtilization',
  statistic: 'Average',
  period: Duration.hours(1), // Alarm will use the metric's period
});

// Create an anomaly detection alarm
const alarm = new cloudwatch.AnomalyDetectionAlarm(this, 'AnomalyAlarm', {
  metric: metric,
  evaluationPeriods: 1,

  // Number of standard deviations for the band (default: 2)
  stdDevs: 2,
  // Alarm outside on either side of the band, or just below or above it (default: outside)
  comparisonOperator: cloudwatch.ComparisonOperator.LESS_THAN_LOWER_OR_GREATER_THAN_UPPER_THRESHOLD,
  alarmDescription: 'Alarm when metric is outside the expected band',
});

Properties ​

actionsEnabledoptionalbooleanactions_enabledoptionalboolactionsEnabledoptionalBooleanActionsEnabledoptionalboolActionsEnabledoptional*bool= true#
Whether the actions for this alarm are enabled.
alarmDescriptionoptionalstringalarm_descriptionoptionalstralarmDescriptionoptionalStringAlarmDescriptionoptionalstringAlarmDescriptionoptional*string#
Description for the alarm.

Default: No description

alarmNameoptionalstringalarm_nameoptionalstralarmNameoptionalStringAlarmNameoptionalstringAlarmNameoptional*string#
Name of the alarm.

Default: Automatically generated name

comparisonOperatoroptionalComparisonOperatorcomparison_operatoroptionalComparisonOperatorcomparisonOperatoroptionalComparisonOperatorComparisonOperatoroptionalComparisonOperatorComparisonOperatoroptionalComparisonOperator#
Comparison operator to use to check if metric is breaching.

Default: LESS_THAN_LOWER_OR_GREATER_THAN_UPPER_THRESHOLD

Must be one of the anomaly detection operators:

  • LESS_THAN_LOWER_OR_GREATER_THAN_UPPER_THRESHOLD
  • GREATER_THAN_UPPER_THRESHOLD
  • LESS_THAN_LOWER_THRESHOLD
datapointsToAlarmoptionalnumberdatapoints_to_alarmoptionalint | floatdatapointsToAlarmoptionalNumberDatapointsToAlarmoptionaldoubleDatapointsToAlarmoptional*float64= ``evaluationPeriods``#
The number of datapoints that must be breaching to trigger the alarm.

This is used only if you are setting an "M out of N" alarm. In that case, this value is the M. For more information, see Evaluating an Alarm in the Amazon CloudWatch User Guide.

evaluateLowSampleCountPercentileoptionalstringevaluate_low_sample_count_percentileoptionalstrevaluateLowSampleCountPercentileoptionalStringEvaluateLowSampleCountPercentileoptionalstringEvaluateLowSampleCountPercentileoptional*string#
Specifies whether to evaluate the data and potentially change the alarm state if there are too few data points to be statistically significant.

Default: Not configured.

Used only for alarms that are based on percentiles.

evaluationPeriodsnumberevaluation_periodsint | floatevaluationPeriodsNumberEvaluationPeriodsdoubleEvaluationPeriods*float64required#
The number of periods over which data is compared to the specified threshold.
metricIMetricmetricIMetricmetricIMetricMetricIMetricMetricIMetricrequired#
The metric to add the alarm on.

Metric objects can be obtained from most resources, or you can construct custom Metric objects by instantiating one.

periodoptionalDurationperiodoptionalDurationperiodoptionalDurationPeriodoptionalDurationPeriodoptionalDurationdeprecated#
Use `metric.with({ period: ... })` to encode the period into the Metric object

Default: The period from the metric

Cannot be used with MathExpression objects.

statisticoptionalstringstatisticoptionalstrstatisticoptionalStringStatisticoptionalstringStatisticoptional*stringdeprecated#
Use `metric.with({ statistic: ... })` to encode the period into the Metric object

Default: The statistic from the metric

Can be one of the following:

  • "Minimum" | "min"
  • "Maximum" | "max"
  • "Average" | "avg"
  • "Sum" | "sum"
  • "SampleCount | "n"
  • "pNN.NN"

Cannot be used with MathExpression objects.

stdDevsoptionalnumberstd_devsoptionalint | floatstdDevsoptionalNumberStdDevsoptionaldoubleStdDevsoptional*float64= 2#
The number of standard deviations to use for the anomaly detection band.
notes

The higher the value, the wider the band.

  • Must be greater than 0. A value of 0 or negative values would not make sense in the context of calculating standard deviations.
  • There is no strict maximum value defined, as standard deviations can theoretically extend infinitely. However, in practice, values beyond 5 or 6 standard deviations are rarely used, as they would result in an extremely wide anomaly detection band, potentially missing significant anomalies.
treatMissingDataoptionalTreatMissingDatatreat_missing_dataoptionalTreatMissingDatatreatMissingDataoptionalTreatMissingDataTreatMissingDataoptionalTreatMissingDataTreatMissingDataoptionalTreatMissingData= TreatMissingData.Missing#
Sets how this alarm is to handle missing data points.