-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalarms.tf
154 lines (106 loc) · 3.98 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
resource "aws_cloudwatch_metric_alarm" "cache_cpu" {
count = var.enabled && !var.use_serverless ? local.num_nodes : 0
alarm_name = "${tolist(aws_elasticache_replication_group.this[0].member_clusters)[count.index]}-cpu-utilization"
alarm_description = "Redis cluster CPU utilization"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = 1
metric_name = "CPUUtilization"
namespace = "AWS/ElastiCache"
period = 300
statistic = "Average"
tags = var.tags
threshold = var.alarm_cpu_threshold_percent
dimensions = {
CacheClusterId = tolist(aws_elasticache_replication_group.this[0].member_clusters)[count.index]
}
alarm_actions = var.alarm_actions
ok_actions = var.ok_actions
depends_on = [
aws_elasticache_replication_group.this
]
}
resource "aws_cloudwatch_metric_alarm" "cache_memory" {
count = var.enabled && !var.use_serverless ? local.num_nodes : 0
alarm_name = "${tolist(aws_elasticache_replication_group.this[0].member_clusters)[count.index]}-freeable-memory"
alarm_description = "Redis cluster freeable memory"
comparison_operator = "LessThanThreshold"
evaluation_periods = 1
metric_name = "FreeableMemory"
namespace = "AWS/ElastiCache"
period = 60
statistic = "Average"
threshold = var.alarm_memory_threshold_bytes
tags = var.tags
dimensions = {
CacheClusterId = tolist(aws_elasticache_replication_group.this[0].member_clusters)[count.index]
}
alarm_actions = var.alarm_actions
ok_actions = var.ok_actions
depends_on = [
aws_elasticache_replication_group.this
]
}
# ElastiCache Serverless
resource "aws_cloudwatch_metric_alarm" "cache_serverless_ecpu" {
count = var.enabled && var.use_serverless ? 1 : 0
alarm_name = "${awscc_elasticache_serverless_cache.this[0].serverless_cache_name}-ecpu-utilization"
alarm_description = "Redis serverless ECPU utilization"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = 1
metric_name = "ElastiCacheProcessingUnits"
namespace = "AWS/ElastiCache"
period = 300
statistic = "Average"
tags = var.tags
threshold = ceil(var.max_ecpu_per_second * var.alarm_ecpu_threshold_percent / 100)
dimensions = {
CacheClusterId = awscc_elasticache_serverless_cache.this[0].serverless_cache_name
}
alarm_actions = var.alarm_actions
ok_actions = var.ok_actions
depends_on = [
awscc_elasticache_serverless_cache.this
]
}
resource "aws_cloudwatch_metric_alarm" "cache_serverless_data" {
count = var.enabled && var.use_serverless ? 1 : 0
alarm_name = "${awscc_elasticache_serverless_cache.this[0].serverless_cache_name}-data-storage"
alarm_description = "Redis serverless data storage"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = 1
metric_name = "BytesUsedForCache"
namespace = "AWS/ElastiCache"
period = 60
statistic = "Average"
threshold = ceil((var.max_data_storage * 1000 * 1000 * 1000) * var.alarm_data_threshold_percent / 100)
tags = var.tags
dimensions = {
CacheClusterId = awscc_elasticache_serverless_cache.this[0].serverless_cache_name
}
alarm_actions = var.alarm_actions
ok_actions = var.ok_actions
depends_on = [
aws_elasticache_replication_group.this
]
}
resource "aws_cloudwatch_metric_alarm" "cache_serverless_throttled_commands" {
count = var.enabled && var.use_serverless ? 1 : 0
alarm_name = "${awscc_elasticache_serverless_cache.this[0].serverless_cache_name}-throttled-commands"
alarm_description = "Redis serverless throttled commands"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = 1
metric_name = "ThrottledCmds"
namespace = "AWS/ElastiCache"
period = 60
statistic = "Average"
threshold = 0
tags = var.tags
dimensions = {
CacheClusterId = awscc_elasticache_serverless_cache.this[0].serverless_cache_name
}
alarm_actions = var.alarm_actions
ok_actions = var.ok_actions
depends_on = [
awscc_elasticache_serverless_cache.this
]
}