-
Notifications
You must be signed in to change notification settings - Fork 5
/
monitoring.tf
83 lines (70 loc) · 3.25 KB
/
monitoring.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
##################
## Resources ##
##################
### Slack forwarder lambda
module "notify-slack" {
source = "terraform-aws-modules/notify-slack/aws"
version = "~> 2.0"
create = var.enable_monitoring
lambda_function_name = trim(substr("${var.resource_prefix}-${terraform.workspace}-cloudwatch-events-forwarder", 0, 64), "-") # 64 character max-length
sns_topic_name = "${var.resource_prefix}-${terraform.workspace}-cloudwatch-events"
slack_webhook_url = var.monitoring_slack_webhook_url
slack_channel = var.monitoring_slack_channel
slack_username = "Amazon CloudWatch"
}
### CloudWatch configuration
# module "alb-target-group-cloudwatch-sns-alarms" {
# source = "cloudposse/alb-target-group-cloudwatch-sns-alarms/aws"
# version = "0.6.1"
# enabled = var.enable_monitoring
# namespace = var.resource_prefix
# stage = terraform.workspace
# name = "alb-tg-alarms"
# notify_arns = [module.notify-slack.this_slack_topic_arn]
# alb_name = aws_lb.main.name
# alb_arn_suffix = aws_lb.main.arn_suffix
# target_group_name = aws_lb_target_group.app.name
# target_group_arn_suffix = aws_lb_target_group.app.arn_suffix
# treat_missing_data = "notBreaching"
# evaluation_periods = "3"
# target_3xx_count_threshold = "-1"
# target_5xx_count_threshold = "5"
# target_4xx_count_threshold = "5"
# elb_5xx_count_threshold = "5"
# }
resource "aws_cloudwatch_metric_alarm" "httpcode_target_5xx_count" {
count = var.enable_monitoring ? 1 : 0
alarm_name = "${var.resource_prefix}-${terraform.workspace}-5XX-target-group-errors"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = var.monitoring_evaluation_periods
metric_name = "HTTPCode_Target_5XX_Count"
namespace = "AWS/ApplicationELB"
period = var.monitoring_period
statistic = "Sum"
threshold = 5
treat_missing_data = "notBreaching"
alarm_description = "${var.resource_prefix}-${terraform.workspace}-5XX-target-group-errors"
alarm_actions = [module.notify-slack.this_slack_topic_arn]
dimensions = {
"TargetGroup" = aws_lb_target_group.app.arn_suffix
"LoadBalancer" = aws_lb.main.arn_suffix
}
}
resource "aws_cloudwatch_metric_alarm" "unhealthy_host_count" {
count = var.enable_monitoring ? 1 : 0
alarm_name = "${var.resource_prefix}-${terraform.workspace}-unhealthy-hosts"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = var.monitoring_evaluation_periods
metric_name = "UnHealthyHostCount"
namespace = "AWS/ApplicationELB"
period = var.monitoring_period
statistic = "Average"
threshold = 0
treat_missing_data = "notBreaching"
alarm_description = "${var.resource_prefix}-${terraform.workspace}-unhealthy-hosts"
alarm_actions = [module.notify-slack.this_slack_topic_arn]
dimensions = {
"TargetGroup" = aws_lb_target_group.app.arn_suffix
"LoadBalancer" = aws_lb.main.arn_suffix
}
}