Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- resource "aws_appautoscaling_target" "ecs-running-service" {
- max_capacity = "${var.ecs_max_desired_count}"
- min_capacity = "${var.ecs_desired_count}"
- resource_id = "service/${aws_ecs_cluster.cluster.name}/${aws_ecs_service.ecs-service.name}"
- scalable_dimension = "ecs:service:DesiredCount"
- service_namespace = "ecs"
- }
- resource "aws_appautoscaling_policy" "ecs-decreasing-service-size" {
- depends_on = ["aws_appautoscaling_target.ecs-running-service"]
- name = "${var.ecs_policy_scaling_down}"
- policy_type = "StepScaling"
- resource_id = "service/${aws_ecs_cluster.cluster.name}/${aws_ecs_service.ecs-service.name}"
- scalable_dimension = "${aws_appautoscaling_target.ecs-running-service.scalable_dimension}"
- service_namespace = "${aws_appautoscaling_target.ecs-running-service.service_namespace}"
- step_scaling_policy_configuration {
- adjustment_type = "ChangeInCapacity"
- cooldown = 300
- metric_aggregation_type = "Average"
- step_adjustment {
- metric_interval_upper_bound = "0"
- scaling_adjustment = "-1"
- }
- }
- }
- resource "aws_appautoscaling_policy" "ecs-increasing-service-size" {
- depends_on = ["aws_appautoscaling_target.ecs-running-service"]
- name = "${var.telecarga_scale_out}"
- policy_type = "StepScaling"
- resource_id = "service/${aws_ecs_cluster.cluster.name}/${aws_ecs_service.ecs-service.name}"
- scalable_dimension = "ecs:service:DesiredCount"
- service_namespace = "ecs"
- step_scaling_policy_configuration {
- adjustment_type = "ChangeInCapacity"
- cooldown = 180
- metric_aggregation_type = "Average"
- step_adjustment {
- metric_interval_upper_bound = "0"
- scaling_adjustment = "2"
- }
- }
- }
- #CloudWatch Alarms
- resource "aws_cloudwatch_metric_alarm" "ecs-cpu-high" {
- alarm_name = "${var.application_name}"
- alarm_actions = ["${aws_autoscaling_policy.autoscaling-policy-increase.arn}", "${aws_appautoscaling_policy.ecs-increasing-service-size.arn }"]
- evaluation_periods = "2"
- datapoints_to_alarm = "2"
- metric_name = "CPUUtilization"
- period = "60"
- statistic = "Average"
- comparison_operator = "GreaterThanOrEqualToThreshold"
- namespace = "AWS/ECS"
- threshold = "15"
- alarm_description = "Monitoring CPU ECS instances utilization"
- dimensions = {
- ClusterName = "${aws_ecs_cluster.cluster.name}"
- ServiceName = "${aws_ecs_service.ecs-service.name}"
- }
- }
- resource "aws_cloudwatch_metric_alarm" "ecs-cpu-low" {
- alarm_name = "${var.application_name}-cpu-low"
- alarm_actions = ["${aws_appautoscaling_policy.ecs-decreasing-service-size.arn}", "${aws_autoscaling_policy.autoscaling-policy-decrease.arn}"]
- evaluation_periods = "2"
- datapoints_to_alarm = "2"
- metric_name = "CPUUtilization"
- period = "300"
- comparison_operator = "LessThanOrEqualToThreshold"
- statistic = "Average"
- namespace = "AWS/ECS"
- threshold = "5"
- alarm_description = "Monitoring CPU ECS instances utilization"
- dimensions = {
- ClusterName = "${aws_ecs_cluster.cluster.name}"
- ServiceName = "${aws_ecs_service.ecs-service.name}"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement