Created
November 3, 2018 17:02
-
-
Save mlabouardy/47f8305211c900558bb663b1d7ea2a8e to your computer and use it in GitHub Desktop.
Scale out/in jenkins workers on demand
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Scale out | |
| resource "aws_cloudwatch_metric_alarm" "high-cpu-jenkins-slaves-alarm" { | |
| alarm_name = "high-cpu-jenkins-slaves-alarm" | |
| comparison_operator = "GreaterThanOrEqualToThreshold" | |
| evaluation_periods = "2" | |
| metric_name = "CPUUtilization" | |
| namespace = "AWS/EC2" | |
| period = "120" | |
| statistic = "Average" | |
| threshold = "80" | |
| dimensions { | |
| AutoScalingGroupName = "${aws_autoscaling_group.jenkins_slaves.name}" | |
| } | |
| alarm_description = "This metric monitors ec2 cpu utilization" | |
| alarm_actions = ["${aws_autoscaling_policy.scale-out.arn}"] | |
| } | |
| resource "aws_autoscaling_policy" "scale-out" { | |
| name = "scale-out-jenkins-slaves" | |
| scaling_adjustment = 1 | |
| adjustment_type = "ChangeInCapacity" | |
| cooldown = 300 | |
| autoscaling_group_name = "${aws_autoscaling_group.jenkins_slaves.name}" | |
| } | |
| // Scale In | |
| resource "aws_cloudwatch_metric_alarm" "low-cpu-jenkins-slaves-alarm" { | |
| alarm_name = "low-cpu-jenkins-slaves-alarm" | |
| comparison_operator = "LessThanOrEqualToThreshold" | |
| evaluation_periods = "2" | |
| metric_name = "CPUUtilization" | |
| namespace = "AWS/EC2" | |
| period = "120" | |
| statistic = "Average" | |
| threshold = "20" | |
| dimensions { | |
| AutoScalingGroupName = "${aws_autoscaling_group.jenkins_slaves.name}" | |
| } | |
| alarm_description = "This metric monitors ec2 cpu utilization" | |
| alarm_actions = ["${aws_autoscaling_policy.scale-in.arn}"] | |
| } | |
| resource "aws_autoscaling_policy" "scale-in" { | |
| name = "scale-in-jenkins-slaves" | |
| scaling_adjustment = -1 | |
| adjustment_type = "ChangeInCapacity" | |
| cooldown = 300 | |
| autoscaling_group_name = "${aws_autoscaling_group.jenkins_slaves.name}" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment