-
-
Notifications
You must be signed in to change notification settings - Fork 101
/
alarms.tf
158 lines (140 loc) · 5.8 KB
/
alarms.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
locals {
thresholds = {
BurstBalanceThreshold = min(max(var.burst_balance_threshold, 0), 100)
CPUUtilizationThreshold = min(max(var.cpu_utilization_threshold, 0), 100)
CPUCreditBalanceThreshold = max(var.cpu_credit_balance_threshold, 0)
DiskQueueDepthThreshold = max(var.disk_queue_depth_threshold, 0)
FreeableMemoryThreshold = max(var.freeable_memory_threshold, 0)
FreeStorageSpaceThreshold = max(var.free_storage_space_threshold, 0)
SwapUsageThreshold = max(var.swap_usage_threshold, 0)
}
alarm_names = toset([
"burst_balance_too_low",
"cpu_utilization_too_high",
"cpu_credit_balance_too_low",
"disk_queue_depth_too_high",
"freeable_memory_too_low",
"free_storage_space_threshold",
"swap_usage_too_high"
])
}
module "label" {
source = "cloudposse/label/null"
version = "0.25.0"
for_each = local.alarm_names
name = coalesce(module.this.name, var.db_instance_id)
attributes = [each.key]
context = module.this.context
}
resource "aws_cloudwatch_metric_alarm" "burst_balance_too_low" {
alarm_name = module.label["burst_balance_too_low"].id
comparison_operator = "LessThanThreshold"
evaluation_periods = "1"
metric_name = "BurstBalance"
namespace = "AWS/RDS"
period = "600"
statistic = "Average"
threshold = local.thresholds["BurstBalanceThreshold"]
alarm_description = "Average database storage burst balance over last 10 minutes too low, expect a significant performance drop soon"
alarm_actions = aws_sns_topic.default.*.arn
ok_actions = aws_sns_topic.default.*.arn
dimensions = {
DBInstanceIdentifier = var.db_instance_id
}
}
resource "aws_cloudwatch_metric_alarm" "cpu_utilization_too_high" {
alarm_name = module.label["cpu_utilization_too_high"].id
comparison_operator = "GreaterThanThreshold"
evaluation_periods = "1"
metric_name = "CPUUtilization"
namespace = "AWS/RDS"
period = "600"
statistic = "Average"
threshold = local.thresholds["CPUUtilizationThreshold"]
alarm_description = "Average database CPU utilization over last 10 minutes too high"
alarm_actions = aws_sns_topic.default.*.arn
ok_actions = aws_sns_topic.default.*.arn
dimensions = {
DBInstanceIdentifier = var.db_instance_id
}
}
resource "aws_cloudwatch_metric_alarm" "cpu_credit_balance_too_low" {
alarm_name = module.label["cpu_credit_balance_too_low"].id
comparison_operator = "LessThanThreshold"
evaluation_periods = "1"
metric_name = "CPUCreditBalance"
namespace = "AWS/RDS"
period = "600"
statistic = "Average"
threshold = local.thresholds["CPUCreditBalanceThreshold"]
alarm_description = "Average database CPU credit balance over last 10 minutes too low, expect a significant performance drop soon"
alarm_actions = aws_sns_topic.default.*.arn
ok_actions = aws_sns_topic.default.*.arn
dimensions = {
DBInstanceIdentifier = var.db_instance_id
}
}
resource "aws_cloudwatch_metric_alarm" "disk_queue_depth_too_high" {
alarm_name = module.label["disk_queue_depth_too_high"].id
comparison_operator = "GreaterThanThreshold"
evaluation_periods = "1"
metric_name = "DiskQueueDepth"
namespace = "AWS/RDS"
period = "600"
statistic = "Average"
threshold = local.thresholds["DiskQueueDepthThreshold"]
alarm_description = "Average database disk queue depth over last 10 minutes too high, performance may suffer"
alarm_actions = aws_sns_topic.default.*.arn
ok_actions = aws_sns_topic.default.*.arn
dimensions = {
DBInstanceIdentifier = var.db_instance_id
}
}
resource "aws_cloudwatch_metric_alarm" "freeable_memory_too_low" {
alarm_name = module.label["freeable_memory_too_low"].id
comparison_operator = "LessThanThreshold"
evaluation_periods = "1"
metric_name = "FreeableMemory"
namespace = "AWS/RDS"
period = "600"
statistic = "Average"
threshold = local.thresholds["FreeableMemoryThreshold"]
alarm_description = "Average database freeable memory over last 10 minutes too low, performance may suffer"
alarm_actions = aws_sns_topic.default.*.arn
ok_actions = aws_sns_topic.default.*.arn
dimensions = {
DBInstanceIdentifier = var.db_instance_id
}
}
resource "aws_cloudwatch_metric_alarm" "free_storage_space_too_low" {
alarm_name = module.label["free_storage_space_threshold"].id
comparison_operator = "LessThanThreshold"
evaluation_periods = "1"
metric_name = "FreeStorageSpace"
namespace = "AWS/RDS"
period = "600"
statistic = "Average"
threshold = local.thresholds["FreeStorageSpaceThreshold"]
alarm_description = "Average database free storage space over last 10 minutes too low"
alarm_actions = aws_sns_topic.default.*.arn
ok_actions = aws_sns_topic.default.*.arn
dimensions = {
DBInstanceIdentifier = var.db_instance_id
}
}
resource "aws_cloudwatch_metric_alarm" "swap_usage_too_high" {
alarm_name = module.label["swap_usage_too_high"].id
comparison_operator = "GreaterThanThreshold"
evaluation_periods = "1"
metric_name = "SwapUsage"
namespace = "AWS/RDS"
period = "600"
statistic = "Average"
threshold = local.thresholds["SwapUsageThreshold"]
alarm_description = "Average database swap usage over last 10 minutes too high, performance may suffer"
alarm_actions = aws_sns_topic.default.*.arn
ok_actions = aws_sns_topic.default.*.arn
dimensions = {
DBInstanceIdentifier = var.db_instance_id
}
}