From f562691bd2d98b2bc37361b49d954e629a01532a Mon Sep 17 00:00:00 2001 From: Jahir Date: Thu, 11 Apr 2024 09:06:02 +0100 Subject: [PATCH 1/2] added scaling out configuration for Radius service using memory utilisation MAXIMUM --- modules/ecs_auto_scaling_radius/main.tf | 49 ++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/modules/ecs_auto_scaling_radius/main.tf b/modules/ecs_auto_scaling_radius/main.tf index 881f157..a0d56c6 100644 --- a/modules/ecs_auto_scaling_radius/main.tf +++ b/modules/ecs_auto_scaling_radius/main.tf @@ -25,7 +25,7 @@ resource "aws_appautoscaling_policy" "ecs_policy_up" { depends_on = [aws_appautoscaling_target.radius] } -// Scaling out using memory utilisation +// Scaling out using memory_average utilisation resource "aws_appautoscaling_policy" "ecs_policy_up_memory_average" { name = "${var.prefix} ECS Scale Up Memory Average" service_namespace = "ecs" @@ -46,6 +46,26 @@ resource "aws_appautoscaling_policy" "ecs_policy_up_memory_average" { depends_on = [aws_appautoscaling_target.radius] } +resource "aws_appautoscaling_policy" "ecs_policy_up_memory_max" { + name = "${var.prefix} ECS Scale Up Memory Maximum" + service_namespace = "ecs" + policy_type = "StepScaling" + resource_id = "service/${var.cluster_name}/${var.service_name}" + scalable_dimension = "ecs:service:DesiredCount" + + step_scaling_policy_configuration { + adjustment_type = "ChangeInCapacity" + metric_aggregation_type = "Maximum" + cooldown = 300 + + step_adjustment { + metric_interval_lower_bound = 0 + scaling_adjustment = 1 + } + } + + depends_on = [aws_appautoscaling_target.radius] +} resource "aws_appautoscaling_policy" "ecs_policy_down" { name = "${var.prefix} ECS Scale Down" service_namespace = "ecs" @@ -187,7 +207,7 @@ resource "aws_cloudwatch_metric_alarm" "ecs_memory_average_alarm" { ServiceName = var.service_name } - alarm_description = "This alarm tells ECS to scale up based on average high usage of Memory in the cluster " + alarm_description = "This alarm tells ECS to scale up based on memory utilisation with AVERAGE statistics" alarm_actions = [ aws_appautoscaling_policy.ecs_policy_up_memory_average.arn @@ -196,3 +216,28 @@ resource "aws_cloudwatch_metric_alarm" "ecs_memory_average_alarm" { treat_missing_data = "breaching" tags = var.tags } + +resource "aws_cloudwatch_metric_alarm" "ecs_memory_maximum_alarm_high" { + alarm_name = "${var.prefix}-ecs-memory-maximum-alarm" + comparison_operator = "GreaterThanOrEqualToThreshold" + evaluation_periods = "1" + metric_name = "MemoryUtilization" + namespace = "AWS/ECS" + period = "60" + statistic = "Maximum" + threshold = "80" + + dimensions = { + ClusterName = var.cluster_name + ServiceName = var.service_name + } + + alarm_description = "This alarm tells ECS to scale up based on memory utilisation with MAXIMUM statistics" + + alarm_actions = [ + aws_appautoscaling_policy.ecs_policy_up_memory_max.arn + ] + + treat_missing_data = "breaching" + tags = var.tags +} From 3f5c3f9f2178fe13b8bdb0abfa5caf63b425d86c Mon Sep 17 00:00:00 2001 From: Jahir <124062934+juddin927@users.noreply.github.com> Date: Thu, 11 Apr 2024 12:32:35 +0100 Subject: [PATCH 2/2] Update main.tf --- modules/ecs_auto_scaling_radius/main.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/ecs_auto_scaling_radius/main.tf b/modules/ecs_auto_scaling_radius/main.tf index a0d56c6..7db7f35 100644 --- a/modules/ecs_auto_scaling_radius/main.tf +++ b/modules/ecs_auto_scaling_radius/main.tf @@ -66,6 +66,7 @@ resource "aws_appautoscaling_policy" "ecs_policy_up_memory_max" { depends_on = [aws_appautoscaling_target.radius] } + resource "aws_appautoscaling_policy" "ecs_policy_down" { name = "${var.prefix} ECS Scale Down" service_namespace = "ecs"