我正在向日志管道添加警报/监控。具体来说,我正在创建 CW 警报,这些警报会在 Auto Scaling 组中的 EC2 实例的磁盘/内存利用率超过 50% 时触发。ASG 在“workers”模块目录中创建,并输出伸缩组名称以供在“cloudwatch”模块目录中创建警报时参考。
我很难理解有关创建此警报的一些事情:
- 在警报创建中是否必须引用指标的所有维度?
- 如果是这样,当 TF 文件中仅定义目标组/缩放组时,如何引用 InstanceID?
在“警报”父模块中:
resource "aws_cloudwatch_metric_alarm" "pipeline_DiskUtilization" {
alarm_name = "pipeline-disk-alarm"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "5"
metric_name = "disk_used_percent"
namespace = "CWAgent"
period = "60"
statistic = "Average"
threshold = "50"
dimensions = {
AutoScalingGroupName = var.scaling_name
}
alarm_description = "This metric monitors ec2 disk utilization"
alarm_actions = [var.scaling_group]
}
在“工人”父模块中:
resource "aws_autoscaling_group" "pipeline-scaling-group" {
name = "pipeline-worker-asg"
vpc_zone_identifier = var.operating_subnets
desired_capacity = 2
max_size = 4
min_size = 2
target_group_arns = [var.target_group]
launch_template {
id = aws_launch_template.pipeline-worker-launch-template.id
version = "$Latest"
}
}