Skip to content

Commit

Permalink
added scaling out configuration for Radius service using memory utili…
Browse files Browse the repository at this point in the history
…sation MAXIMUM
  • Loading branch information
juddin927 committed Apr 11, 2024
1 parent d4e5895 commit f562691
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions modules/ecs_auto_scaling_radius/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
}

0 comments on commit f562691

Please sign in to comment.