Need to configure Cloudwatch alarm notifications based on current threshold value

Viewed 29

I have created a cloudwatch metric alarm for cpu utilization with a threshold 80% as below:-

resource "aws_cloudwatch_metric_alarm" "ec2-high-cpu-alarm" {
  count                = length(local.monitor_instance_tags)
  
  alarm_name           = "ec2-high-cpu-alarm-for-${local.monitor_instance_tags[count.index]}"
  comparison_operator  = "GreaterThanOrEqualToThreshold"
  evaluation_periods   = "1"
  metric_name          = "CPUUtilization"
  namespace            = "AWS/EC2"
  period               = var.alarm_monitor_period
  statistic            = "Average"
  threshold            = "80"
  alarm_description    = "This metric monitors ec2 cpu utilization exceeding 80%"
  dimensions           = { 
    InstanceId = local.monitor_instance_ids[count.index]
  }

  alarm_actions       = local.alarm_notify_actions
  ok_actions          = local.alarm_notify_actions
  insufficient_data_actions = []
  actions_enabled           = true
}

My requirement is to receive a "WARNING" notification when the threshold is between 80% to 90%. After crossing the 90% threshold, I need to receive a critical "ALARM" notification. Ideally, it would have been better if Cloudwatch alarms had an additional ALARM state as WARNING; but currently, there are only 3 states possible: OK, INSUFFICIENT_DATA, ALARM.

My Question: How to check the current threshold value in the ALARM state?
In that case, I would customize the alarm notification message (alarm_name or description) to add a "WARNING"/"CRITICAL ALARM" label.

If checking the current threshold value is not possible in the metric alarm code creation, then please suggest, if there is any workaround to manage my requirement.
NOTE: I want to avoid adding multiple alarms for same metric with just different threshold values.

0 Answers
Related