Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new max scaling metric to ECS #291

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 51 additions & 6 deletions modules/dns/ecs_auto_scaling.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ resource "aws_appautoscaling_target" "auth_ecs_target" {
scalable_dimension = "ecs:service:DesiredCount"
}

resource "aws_appautoscaling_policy" "ecs_policy_up" {
name = "ECS Scale Up"
resource "aws_appautoscaling_policy" "ecs_policy_up_average" {
name = "ECS Scale Up Average"
service_namespace = "ecs"
policy_type = "StepScaling"
resource_id = "service/${aws_ecs_cluster.server_cluster.name}/${aws_ecs_service.service.name}"
Expand All @@ -26,6 +26,27 @@ resource "aws_appautoscaling_policy" "ecs_policy_up" {
depends_on = [aws_appautoscaling_target.auth_ecs_target]
}

resource "aws_appautoscaling_policy" "ecs_policy_up_max" {
name = "ECS Scale Up Max"
service_namespace = "ecs"
policy_type = "StepScaling"
resource_id = "service/${aws_ecs_cluster.server_cluster.name}/${aws_ecs_service.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.auth_ecs_target]
}

resource "aws_appautoscaling_policy" "ecs_policy_down" {
name = "ECS Scale Down"
service_namespace = "ecs"
Expand All @@ -46,8 +67,8 @@ resource "aws_appautoscaling_policy" "ecs_policy_down" {
depends_on = [aws_appautoscaling_target.auth_ecs_target]
}

resource "aws_cloudwatch_metric_alarm" "ecs_cpu_alarm_high" {
alarm_name = "${var.prefix}-ecs-cpu-alarm-high"
resource "aws_cloudwatch_metric_alarm" "ecs_cpu_average_alarm_high" {
alarm_name = "${var.prefix}-ecs-cpu-average-alarm-high"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
metric_name = "CPUUtilization"
Expand All @@ -61,10 +82,34 @@ resource "aws_cloudwatch_metric_alarm" "ecs_cpu_alarm_high" {
ServiceName = aws_ecs_service.service.name
}

alarm_description = "This alarm tells ECS to scale up based on high CPU"
alarm_description = "This alarm tells ECS to scale up based on average high CPU"

alarm_actions = [
aws_appautoscaling_policy.ecs_policy_up_average.arn
]

treat_missing_data = "breaching"
}

resource "aws_cloudwatch_metric_alarm" "ecs_cpu_maximum_alarm_high" {
alarm_name = "${var.prefix}-ecs-cpu-maximum-alarm-high"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
metric_name = "CPUUtilization"
namespace = "AWS/ECS"
period = "60"
statistic = "Maximum"
threshold = "80"

dimensions = {
ClusterName = aws_ecs_cluster.server_cluster.name
ServiceName = aws_ecs_service.service.name
}

alarm_description = "This alarm tells ECS to scale up based on maxmium high CPU"

alarm_actions = [
aws_appautoscaling_policy.ecs_policy_up.arn
aws_appautoscaling_policy.ecs_policy_up_max.arn
]

treat_missing_data = "breaching"
Expand Down