2023-05-23 13:10:16 +08:00
|
|
|
locals {
|
|
|
|
alb-name = "app/${split("/", var.load-balancer)[2]}/${split("/", var.load-balancer)[3]}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_cloudwatch_metric_alarm" "alb-HTTPCode_ELB_5XX_Count" {
|
|
|
|
alarm_name = "${var.settings.HTTPCode_ELB_5XX_Count.ecccode}-ALB_${local.alb-name}-HTTPCode_ELB_5XX_Count"
|
|
|
|
comparison_operator = var.settings.HTTPCode_ELB_5XX_Count.comparison_operator
|
|
|
|
evaluation_periods = var.settings.HTTPCode_ELB_5XX_Count.evaluation_periods
|
|
|
|
metric_name = "HTTPCode_ELB_5XX_Count"
|
|
|
|
period = var.settings.HTTPCode_ELB_5XX_Count.period
|
|
|
|
statistic = var.settings.HTTPCode_ELB_5XX_Count.statistic
|
|
|
|
threshold = var.settings.HTTPCode_ELB_5XX_Count.threshold
|
|
|
|
alarm_description = "ALB:HTTPCode_ELB_5XX_Count"
|
|
|
|
namespace = "AWS/ApplicationELB"
|
|
|
|
insufficient_data_actions = []
|
|
|
|
actions_enabled = var.actions-enabled
|
|
|
|
alarm_actions = [var.settings.HTTPCode_ELB_5XX_Count.action]
|
|
|
|
ok_actions = [var.settings.HTTPCode_ELB_5XX_Count.action]
|
|
|
|
dimensions = {
|
|
|
|
LoadBalancer = local.alb-name
|
|
|
|
}
|
|
|
|
tags = var.default-tags
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_cloudwatch_metric_alarm" "alb-TargetConnectionErrorCount" {
|
|
|
|
alarm_name = "${var.settings.TargetConnectionErrorCount.ecccode}-ALB_${local.alb-name}-TargetConnectionErrorCount"
|
|
|
|
comparison_operator = var.settings.TargetConnectionErrorCount.comparison_operator
|
|
|
|
evaluation_periods = var.settings.TargetConnectionErrorCount.evaluation_periods
|
|
|
|
metric_name = "TargetConnectionErrorCount"
|
|
|
|
period = var.settings.TargetConnectionErrorCount.period
|
|
|
|
statistic = var.settings.TargetConnectionErrorCount.statistic
|
|
|
|
threshold = var.settings.TargetConnectionErrorCount.threshold
|
|
|
|
alarm_description = "ALB:TargetConnectionErrorCount"
|
|
|
|
namespace = "AWS/ApplicationELB"
|
|
|
|
insufficient_data_actions = []
|
|
|
|
actions_enabled = var.actions-enabled
|
|
|
|
alarm_actions = [var.settings.TargetConnectionErrorCount.action]
|
|
|
|
ok_actions = [var.settings.TargetConnectionErrorCount.action]
|
|
|
|
dimensions = {
|
|
|
|
LoadBalancer = local.alb-name
|
2022-10-25 14:21:37 +08:00
|
|
|
}
|
2023-05-23 13:10:16 +08:00
|
|
|
tags = var.default-tags
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_cloudwatch_metric_alarm" "alb-TargetResponseTime" {
|
|
|
|
alarm_name = "${var.settings.TargetResponseTime.ecccode}-ALB_${local.alb-name}-TargetResponseTime"
|
|
|
|
comparison_operator = var.settings.TargetResponseTime.comparison_operator
|
|
|
|
evaluation_periods = var.settings.TargetResponseTime.evaluation_periods
|
|
|
|
metric_name = "TargetResponseTime"
|
|
|
|
period = var.settings.TargetResponseTime.period
|
|
|
|
statistic = var.settings.TargetResponseTime.statistic
|
|
|
|
threshold = var.settings.TargetResponseTime.threshold
|
|
|
|
alarm_description = "ALB:TargetResponseTime"
|
|
|
|
namespace = "AWS/ApplicationELB"
|
|
|
|
insufficient_data_actions = []
|
|
|
|
actions_enabled = var.actions-enabled
|
|
|
|
alarm_actions = [var.settings.TargetResponseTime.action]
|
|
|
|
ok_actions = [var.settings.TargetResponseTime.action]
|
|
|
|
dimensions = {
|
|
|
|
LoadBalancer = local.alb-name
|
|
|
|
}
|
|
|
|
tags = var.default-tags
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
module "alb-targetgroups" {
|
|
|
|
source = "../../util/resource-list"
|
|
|
|
resource-type = "alb-targetgroups"
|
|
|
|
query-input = var.load-balancer
|
|
|
|
asrolearn = var.asrolearn
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
// causes Rate exceeded error, maybe because of adaptive AWS_RETRY_MODE?
|
|
|
|
|
|
|
|
module "alb_tgs" {
|
|
|
|
assume_role_arn = var.asrolearn
|
|
|
|
role_session_name = "terraform-resource-list"
|
|
|
|
source = "../../util/terraform-aws-cli"
|
|
|
|
aws_cli_commands = ["elbv2", "describe-target-groups", "--load-balancer-arn", var.load-balancer]
|
|
|
|
aws_cli_query = "TargetGroups[*].TargetGroupArn"
|
2022-10-25 14:21:37 +08:00
|
|
|
}
|
|
|
|
|
2022-10-26 11:13:56 +08:00
|
|
|
resource "aws_cloudwatch_metric_alarm" "alb-HealthyHostCount" {
|
2023-05-23 13:10:16 +08:00
|
|
|
# for_each = module.alb-targetgroups.result-set
|
|
|
|
for_each = toset(flatten(module.alb_tgs.result))
|
|
|
|
alarm_name = "${var.settings.HealthHostCountMin.ecccode}-ALBTG_:${split(":", each.value)[5]}-HealthyHostCount"
|
|
|
|
comparison_operator = var.settings.HealthHostCountMin.comparison_operator
|
|
|
|
evaluation_periods = var.settings.HealthHostCountMin.evaluation_periods
|
2022-10-26 11:13:56 +08:00
|
|
|
metric_name = "HealthyHostCount"
|
2023-05-23 13:10:16 +08:00
|
|
|
period = var.settings.HealthHostCountMin.period
|
|
|
|
statistic = var.settings.HealthHostCountMin.statistic
|
|
|
|
threshold = var.settings.HealthHostCountMin.threshold
|
2022-10-26 11:13:56 +08:00
|
|
|
alarm_description = "ALBTG:HealthyHostCount"
|
|
|
|
namespace = "AWS/ApplicationELB"
|
2022-10-25 14:21:37 +08:00
|
|
|
insufficient_data_actions = []
|
2022-10-26 11:13:56 +08:00
|
|
|
actions_enabled = var.actions-enabled
|
2023-05-23 13:10:16 +08:00
|
|
|
alarm_actions = [var.settings.HealthHostCountMin.action]
|
|
|
|
ok_actions = [var.settings.HealthHostCountMin.action]
|
2022-10-25 14:21:37 +08:00
|
|
|
dimensions = {
|
2023-05-23 13:10:16 +08:00
|
|
|
TargetGroup = split(":", each.value)[5]
|
2022-10-26 11:13:56 +08:00
|
|
|
LoadBalancer = "app/${split("/", var.load-balancer)[2]}/${split("/", var.load-balancer)[3]}"
|
2022-10-25 14:21:37 +08:00
|
|
|
}
|
|
|
|
tags = var.default-tags
|
|
|
|
}
|