通过 terraform 管理 ASG [英] manage ASG via terraform

查看:36
本文介绍了通过 terraform 管理 ASG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过 terraform 管理的自动缩放策略.

I have a auto scaling policy which is managed via terraform.

代码如下:

resource "aws_autoscaling_policy" "agents-scale-up" {
    name = "agents-scale-up"
    scaling_adjustment = 1
    adjustment_type = "ChangeInCapacity"
    cooldown = 300
    autoscaling_group_name = "${aws_autoscaling_group.agents.name}"
}

resource "aws_autoscaling_policy" "agents-scale-down" {
    name = "agents-scale-down"
    scaling_adjustment = -1
    adjustment_type = "ChangeInCapacity"
    cooldown = 300
    autoscaling_group_name = "${aws_autoscaling_group.agents.name}"
}

我有一个 cloudwatch 指标警报,它根据阈值调用此 ASP.

And I have a cloudwatch metric alarm which calls out to this ASP based on the threshold .

resource "aws_cloudwatch_metric_alarm" "memory-high" {
    alarm_name = "mem-util-high-agents"
    comparison_operator = "GreaterThanOrEqualToThreshold"
    evaluation_periods = "2"
    metric_name = "MemoryUtilization"
    namespace = "System/Linux"
    period = "300"
    statistic = "Average"
    threshold = "80"
    alarm_description = "This metric monitors ec2 memory for high utilization on agent hosts"
    alarm_actions = [
        "${aws_autoscaling_policy.agents-scale-up.arn}"
    ]
    dimensions = {
        AutoScalingGroupName = "${aws_autoscaling_group.agents.name}"
    }
}

现在我还想调用我的 ASP,即我想在星期六晚上缩小规模并在星期一早上再次扩大规模.那么我如何调用ASP,我只知道如何根据我在上面代码中使用的阈值来调用ASP.

Now I additionally want to call my ASP i.e. I want to scale down on saturday night and scale up again on monday morning . So how can I call the ASPs , I only know how to call the ASP based on the threshold value which i use in the above code.

我如何对我的两个 ASP 进行基于时间的调用.

HOW CAN I DO THE TIME BASED calling of my both ASPs.

推荐答案

我们做了类似的事情,扩展了办公时间,但使用预定的扩展来改变 asg 的最小值、最大值和所需的实例值,而不是云监视警报.

We do something similar, scaling out of office hours but using a scheduled scaling to alter the min, Max and desired instance values of the asg instead of cloud watch alert.

参见 https://registry.terraform.io/provider/hashicorp/aws/latest/docs/resources/autoscaling_schedule

对于基于时间的常规缩放,这是更明智的方法.

This is more sensible approach for regular time based scaling.

这篇关于通过 terraform 管理 ASG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆