-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathalarms.tf
308 lines (281 loc) · 15.6 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
locals {
thresholds = {
FreeStorageSpaceThreshold = floor(max(var.free_storage_space_threshold, 0))
FreeStorageSpaceTotalThreshold = floor(max(var.free_storage_space_total_threshold, 0))
MinimumAvailableNodes = floor(max(var.min_available_nodes, 0))
CPUUtilizationThreshold = floor(min(max(var.cpu_utilization_threshold, 0), 100))
JVMMemoryPressureThreshold = floor(min(max(var.jvm_memory_pressure_threshold, 0), 100))
MasterCPUUtilizationThreshold = floor(min(max(coalesce(var.master_cpu_utilization_threshold, var.cpu_utilization_threshold), 0), 100))
MasterJVMMemoryPressureThreshold = floor(min(max(coalesce(var.master_jvm_memory_pressure_threshold, var.jvm_memory_pressure_threshold), 0), 100))
}
}
resource "aws_cloudwatch_metric_alarm" "cluster_status_is_red" {
count = var.monitor_cluster_status_is_red ? 1 : 0
alarm_name = "${var.alarm_name_prefix}ElasticSearch-ClusterStatusIsRed${var.alarm_name_postfix}"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = var.alarm_cluster_status_is_red_periods
datapoints_to_alarm = var.alarm_cluster_status_is_red_periods
metric_name = "ClusterStatus.red"
namespace = "AWS/ES"
period = var.alarm_cluster_status_is_red_period
statistic = "Maximum"
threshold = "1"
alarm_description = "Average elasticsearch cluster status is in red over last ${floor(var.alarm_cluster_status_is_red_periods * var.alarm_cluster_status_is_red_period / 60)} minute(s)"
alarm_actions = [local.aws_sns_topic_arn]
ok_actions = [local.aws_sns_topic_arn]
treat_missing_data = "ignore"
tags = var.tags
dimensions = {
DomainName = var.domain_name
ClientId = data.aws_caller_identity.default.account_id
}
}
resource "aws_cloudwatch_metric_alarm" "cluster_status_is_yellow" {
count = var.monitor_cluster_status_is_yellow ? 1 : 0
alarm_name = "${var.alarm_name_prefix}ElasticSearch-ClusterStatusIsYellow${var.alarm_name_postfix}"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = var.alarm_cluster_status_is_yellow_periods
datapoints_to_alarm = var.alarm_cluster_status_is_yellow_periods
metric_name = "ClusterStatus.yellow"
namespace = "AWS/ES"
period = var.alarm_cluster_status_is_yellow_period
statistic = "Maximum"
threshold = "1"
alarm_description = "Average elasticsearch cluster status is in yellow over last ${floor(var.alarm_cluster_status_is_yellow_periods * var.alarm_cluster_status_is_yellow_period / 60)} minute(s)"
alarm_actions = [local.aws_sns_topic_arn]
ok_actions = [local.aws_sns_topic_arn]
treat_missing_data = "ignore"
tags = var.tags
dimensions = {
DomainName = var.domain_name
ClientId = data.aws_caller_identity.default.account_id
}
}
resource "aws_cloudwatch_metric_alarm" "free_storage_space_too_low" {
count = var.monitor_free_storage_space_too_low ? 1 : 0
alarm_name = "${var.alarm_name_prefix}ElasticSearch-FreeStorageSpaceTooLow${var.alarm_name_postfix}"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = var.alarm_free_storage_space_too_low_periods
datapoints_to_alarm = var.alarm_free_storage_space_too_low_periods
metric_name = "FreeStorageSpace"
namespace = "AWS/ES"
period = var.alarm_free_storage_space_too_low_period
statistic = "Minimum"
threshold = local.thresholds["FreeStorageSpaceThreshold"]
alarm_description = "Minimum free disk space on a single node under ${local.thresholds["FreeStorageSpaceThreshold"]}MB for the last ${floor(var.alarm_free_storage_space_too_low_periods * var.alarm_free_storage_space_too_low_period / 60)} minute(s)"
alarm_actions = [local.aws_sns_topic_arn]
ok_actions = [local.aws_sns_topic_arn]
treat_missing_data = "ignore"
tags = var.tags
dimensions = {
DomainName = var.domain_name
ClientId = data.aws_caller_identity.default.account_id
}
}
resource "aws_cloudwatch_metric_alarm" "free_storage_space_total_too_low" {
# If the user specified how many nodes, and they want to create this alert (disabled by default)
count = var.monitor_free_storage_space_total_too_low ? var.min_available_nodes > 0 ? 1 : 0 : 0
alarm_name = "${var.alarm_name_prefix}ElasticSearch-FreeStorageSpaceTotalTooLow${var.alarm_name_postfix}"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = var.alarm_free_storage_space_total_too_low_periods
datapoints_to_alarm = var.alarm_free_storage_space_total_too_low_periods
metric_name = "FreeStorageSpace"
namespace = "AWS/ES"
period = var.alarm_free_storage_space_total_too_low_period
statistic = "Sum"
threshold = local.thresholds["FreeStorageSpaceTotalThreshold"]
alarm_description = "Total aggregate free disk space under ${local.thresholds["FreeStorageSpaceTotalThreshold"]}MB for the last ${floor(var.alarm_free_storage_space_total_too_low_periods * var.alarm_free_storage_space_total_too_low_period / 60)} minute(s)"
alarm_actions = [local.aws_sns_topic_arn]
ok_actions = [local.aws_sns_topic_arn]
treat_missing_data = "ignore"
tags = var.tags
dimensions = {
DomainName = var.domain_name
ClientId = data.aws_caller_identity.default.account_id
}
}
resource "aws_cloudwatch_metric_alarm" "cluster_index_writes_blocked" {
count = var.monitor_cluster_index_writes_blocked ? 1 : 0
alarm_name = "${var.alarm_name_prefix}ElasticSearch-ClusterIndexWritesBlocked${var.alarm_name_postfix}"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = var.alarm_cluster_index_writes_blocked_periods
datapoints_to_alarm = var.alarm_cluster_index_writes_blocked_periods
metric_name = "ClusterIndexWritesBlocked"
namespace = "AWS/ES"
period = var.alarm_cluster_index_writes_blocked_period
statistic = "Maximum"
threshold = "1"
alarm_description = "Elasticsearch index writes being blocker over last ${floor(var.alarm_cluster_index_writes_blocked_periods * var.alarm_cluster_index_writes_blocked_period / 60)} minute(s)"
alarm_actions = [local.aws_sns_topic_arn]
ok_actions = [local.aws_sns_topic_arn]
treat_missing_data = "ignore"
tags = var.tags
dimensions = {
DomainName = var.domain_name
ClientId = data.aws_caller_identity.default.account_id
}
}
resource "aws_cloudwatch_metric_alarm" "insufficient_available_nodes" {
count = var.monitor_min_available_nodes ? (var.min_available_nodes > 0 ? 1 : 0) : 0
alarm_name = "${var.alarm_name_prefix}ElasticSearch-InsufficientAvailableNodes${var.alarm_name_postfix}"
comparison_operator = "LessThanThreshold"
evaluation_periods = var.alarm_min_available_nodes_periods
datapoints_to_alarm = var.alarm_min_available_nodes_periods
metric_name = "Nodes"
namespace = "AWS/ES"
period = var.alarm_min_available_nodes_period
statistic = "Minimum"
threshold = local.thresholds["MinimumAvailableNodes"]
alarm_description = "Elasticsearch nodes minimum < ${local.thresholds["MinimumAvailableNodes"]} for ${floor(var.alarm_min_available_nodes_periods * var.alarm_min_available_nodes_period / 60)} minutes(s)"
alarm_actions = [local.aws_sns_topic_arn]
ok_actions = [local.aws_sns_topic_arn]
treat_missing_data = "ignore"
tags = var.tags
dimensions = {
DomainName = var.domain_name
ClientId = data.aws_caller_identity.default.account_id
}
}
resource "aws_cloudwatch_metric_alarm" "automated_snapshot_failure" {
count = var.monitor_automated_snapshot_failure ? 1 : 0
alarm_name = "${var.alarm_name_prefix}ElasticSearch-AutomatedSnapshotFailure${var.alarm_name_postfix}"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = var.alarm_automated_snapshot_failure_periods
datapoints_to_alarm = var.alarm_automated_snapshot_failure_periods
metric_name = "AutomatedSnapshotFailure"
namespace = "AWS/ES"
period = var.alarm_automated_snapshot_failure_period
statistic = "Maximum"
threshold = "1"
alarm_description = "Elasticsearch automated snapshot failed over last ${floor(var.alarm_automated_snapshot_failure_periods * var.alarm_automated_snapshot_failure_period / 60)} minute(s)"
alarm_actions = [local.aws_sns_topic_arn]
ok_actions = [local.aws_sns_topic_arn]
treat_missing_data = "ignore"
tags = var.tags
dimensions = {
DomainName = var.domain_name
ClientId = data.aws_caller_identity.default.account_id
}
}
resource "aws_cloudwatch_metric_alarm" "cpu_utilization_too_high" {
count = var.monitor_cpu_utilization_too_high ? 1 : 0
alarm_name = "${var.alarm_name_prefix}ElasticSearch-CPUUtilizationTooHigh${var.alarm_name_postfix}"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = var.alarm_cpu_utilization_too_high_periods
datapoints_to_alarm = var.alarm_cpu_utilization_too_high_periods
metric_name = "CPUUtilization"
namespace = "AWS/ES"
period = var.alarm_cpu_utilization_too_high_period
statistic = "Average"
threshold = local.thresholds["CPUUtilizationThreshold"]
alarm_description = "Average elasticsearch cluster CPU utilization above ${local.thresholds["CPUUtilizationThreshold"]} over last ${floor(var.alarm_cpu_utilization_too_high_periods * var.alarm_cpu_utilization_too_high_period / 60)} minute(s) too high"
alarm_actions = [local.aws_sns_topic_arn]
ok_actions = [local.aws_sns_topic_arn]
tags = var.tags
dimensions = {
DomainName = var.domain_name
ClientId = data.aws_caller_identity.default.account_id
}
}
resource "aws_cloudwatch_metric_alarm" "jvm_memory_pressure_too_high" {
count = var.monitor_jvm_memory_pressure_too_high ? 1 : 0
alarm_name = "${var.alarm_name_prefix}ElasticSearch-JVMMemoryPressure${var.alarm_name_postfix}"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = var.alarm_jvm_memory_pressure_too_high_periods
datapoints_to_alarm = var.alarm_jvm_memory_pressure_too_high_periods
metric_name = "JVMMemoryPressure"
namespace = "AWS/ES"
period = var.alarm_jvm_memory_pressure_too_high_period
statistic = "Maximum"
threshold = local.thresholds["JVMMemoryPressureThreshold"]
alarm_description = "Elasticsearch JVM memory pressure is over ${local.thresholds["JVMMemoryPressureThreshold"]} over the last ${floor(var.alarm_jvm_memory_pressure_too_high_periods * var.alarm_jvm_memory_pressure_too_high_period / 60)} minute(s)"
alarm_actions = [local.aws_sns_topic_arn]
ok_actions = [local.aws_sns_topic_arn]
tags = var.tags
dimensions = {
DomainName = var.domain_name
ClientId = data.aws_caller_identity.default.account_id
}
}
resource "aws_cloudwatch_metric_alarm" "master_cpu_utilization_too_high" {
count = var.monitor_master_cpu_utilization_too_high ? 1 : 0
alarm_name = "${var.alarm_name_prefix}ElasticSearch-MasterCPUUtilizationTooHigh${var.alarm_name_postfix}"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = var.alarm_master_cpu_utilization_too_high_periods
datapoints_to_alarm = var.alarm_master_cpu_utilization_too_high_periods
metric_name = "MasterCPUUtilization"
namespace = "AWS/ES"
period = var.alarm_master_cpu_utilization_too_high_period
statistic = "Average"
threshold = local.thresholds["MasterCPUUtilizationThreshold"]
alarm_description = "Average elasticsearch cluster master CPU utilization above ${local.thresholds["MasterCPUUtilizationThreshold"]} over last ${floor(var.alarm_master_cpu_utilization_too_high_periods * var.alarm_master_cpu_utilization_too_high_period / 60)} minute(s) too high"
alarm_actions = [local.aws_sns_topic_arn]
ok_actions = [local.aws_sns_topic_arn]
tags = var.tags
dimensions = {
DomainName = var.domain_name
ClientId = data.aws_caller_identity.default.account_id
}
}
resource "aws_cloudwatch_metric_alarm" "master_jvm_memory_pressure_too_high" {
count = var.monitor_master_jvm_memory_pressure_too_high ? 1 : 0
alarm_name = "${var.alarm_name_prefix}ElasticSearch-MasterJVMMemoryPressure${var.alarm_name_postfix}"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = var.alarm_master_jvm_memory_pressure_too_high_periods
datapoints_to_alarm = var.alarm_master_jvm_memory_pressure_too_high_periods
metric_name = "MasterJVMMemoryPressure"
namespace = "AWS/ES"
period = var.alarm_master_jvm_memory_pressure_too_high_period
statistic = "Maximum"
threshold = local.thresholds["MasterJVMMemoryPressureThreshold"]
alarm_description = "Elasticsearch JVM memory pressure is over ${local.thresholds["MasterJVMMemoryPressureThreshold"]} over the last ${floor(var.alarm_master_jvm_memory_pressure_too_high_periods * var.alarm_master_jvm_memory_pressure_too_high_period / 60)} minute(s)"
alarm_actions = [local.aws_sns_topic_arn]
ok_actions = [local.aws_sns_topic_arn]
tags = var.tags
dimensions = {
DomainName = var.domain_name
ClientId = data.aws_caller_identity.default.account_id
}
}
resource "aws_cloudwatch_metric_alarm" "kms_key_error" {
count = var.monitor_kms ? 1 : 0
alarm_name = "${var.alarm_name_prefix}ElasticSearch-KMSKeyError${var.alarm_name_postfix}"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = var.alarm_kms_periods
datapoints_to_alarm = var.alarm_kms_periods
metric_name = "KMSKeyError"
namespace = "AWS/ES"
period = var.alarm_kms_period
statistic = "Maximum"
threshold = "1"
alarm_description = "Elasticsearch KMS Key Error failed over last ${floor(var.alarm_kms_periods * var.alarm_kms_period / 60)} minute(s)"
alarm_actions = [local.aws_sns_topic_arn]
ok_actions = [local.aws_sns_topic_arn]
treat_missing_data = "ignore"
tags = var.tags
dimensions = {
DomainName = var.domain_name
ClientId = data.aws_caller_identity.default.account_id
}
}
resource "aws_cloudwatch_metric_alarm" "kms_key_inaccessible" {
count = var.monitor_kms ? 1 : 0
alarm_name = "${var.alarm_name_prefix}ElasticSearch-KMSKeyInaccessible${var.alarm_name_postfix}"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = var.alarm_kms_periods
datapoints_to_alarm = var.alarm_kms_periods
metric_name = "KMSKeyInaccessible"
namespace = "AWS/ES"
period = var.alarm_kms_period
statistic = "Maximum"
threshold = "1"
alarm_description = "Elasticsearch KMS Key Inaccessible failed over last ${floor(var.alarm_kms_periods * var.alarm_kms_period / 60)} minute(s)"
alarm_actions = [local.aws_sns_topic_arn]
ok_actions = [local.aws_sns_topic_arn]
treat_missing_data = "ignore"
tags = var.tags
dimensions = {
DomainName = var.domain_name
ClientId = data.aws_caller_identity.default.account_id
}
}