-
Notifications
You must be signed in to change notification settings - Fork 4
/
cloudwatch.tf
123 lines (113 loc) · 4.22 KB
/
cloudwatch.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
/*
* CloudWatch configuration.
*/
resource "aws_cloudwatch_metric_alarm" "seed-cpu-alarm" {
count = "${aws_instance.seeds.count}"
alarm_name = "${format("%s-cass-seed-cpu-%02d", var.environment, count.index+1)}"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "5"
namespace = "AWS/EC2"
metric_name = "CPUUtilization"
period = "60"
statistic = "Average"
threshold = "${var.cpu_alarm_threshold}"
dimensions {
InstanceId = "${element(aws_instance.seeds.*.id, count.index)}"
}
alarm_actions = ["${var.cloudwatch_alarm_arn}"]
}
resource "aws_cloudwatch_metric_alarm" "node-cpu-alarm" {
count = "${aws_instance.nodes.count}"
alarm_name = "${format("%s-cass-cpu-%s-%02d", var.environment, element(data.aws_subnet.subnets.*.availability_zone, count.index), count.index/length(var.subnet_ids)+1)}"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "5"
namespace = "AWS/EC2"
metric_name = "CPUUtilization"
period = "60"
statistic = "Average"
threshold = "${var.cpu_alarm_threshold}"
dimensions {
InstanceId = "${element(aws_instance.nodes.*.id, count.index)}"
}
alarm_actions = ["${var.cloudwatch_alarm_arn}"]
}
resource "aws_cloudwatch_metric_alarm" "seed-status-alarm" {
count = "${aws_instance.seeds.count}"
alarm_name = "${format("%s-cass-seed-status-%02d", var.environment, count.index+1)}"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
namespace = "AWS/EC2"
metric_name = "StatusCheckFailed"
period = "60"
statistic = "Average"
threshold = "1"
dimensions {
InstanceId = "${element(aws_instance.seeds.*.id, count.index)}"
}
alarm_actions = ["${var.cloudwatch_alarm_arn}"]
}
resource "aws_cloudwatch_metric_alarm" "node-status-alarm" {
count = "${aws_instance.nodes.count}"
alarm_name = "${format("%s-cass-status-%s-%02d", var.environment, element(data.aws_subnet.subnets.*.availability_zone, count.index), count.index/length(var.subnet_ids)+1)}"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
namespace = "AWS/EC2"
metric_name = "StatusCheckFailed"
period = "60"
statistic = "Average"
threshold = "1"
dimensions {
InstanceId = "${element(aws_instance.nodes.*.id, count.index)}"
}
alarm_actions = ["${var.cloudwatch_alarm_arn}"]
}
resource "aws_cloudwatch_metric_alarm" "seed-process-alarm" {
count = "${aws_instance.seeds.count}"
alarm_name = "${format("%s-cass-seed-proc-%02d", var.environment, count.index+1)}"
comparison_operator = "LessThanThreshold"
evaluation_periods = "1"
namespace = "CMXAM/Cassandra"
metric_name = "CassandraStatus"
period = "60"
statistic = "Minimum"
threshold = "1"
dimensions {
InstanceId = "${element(aws_instance.seeds.*.id, count.index)}"
}
alarm_actions = ["${var.cloudwatch_alarm_arn}"]
}
resource "aws_cloudwatch_metric_alarm" "node-process-alarm" {
count = "${aws_instance.nodes.count}"
alarm_name = "${format("%s-cass-proc-%s-%02d", var.environment, element(data.aws_subnet.subnets.*.availability_zone, count.index), count.index/length(var.subnet_ids)+1)}"
comparison_operator = "LessThanThreshold"
evaluation_periods = "1"
namespace = "CMXAM/Cassandra"
metric_name = "CassandraStatus"
period = "60"
statistic = "Minimum"
threshold = "1"
dimensions {
InstanceId = "${element(aws_instance.nodes.*.id, count.index)}"
}
alarm_actions = ["${var.cloudwatch_alarm_arn}"]
}
resource "aws_cloudwatch_event_rule" "cass-seed-event-rule" {
name = "${var.environment}-cass-seed-event"
description = "Cassandra Seed State Change"
event_pattern = "${data.template_file.seed-state-change.rendered}"
}
resource "aws_cloudwatch_event_target" "cass-seed-event-target" {
target_id = "cassandra-seed"
rule = "${aws_cloudwatch_event_rule.cass-seed-event-rule.name}"
arn = "${var.cloudwatch_alarm_arn}"
}
resource "aws_cloudwatch_event_rule" "cass-event-rule" {
name = "${var.environment}-cass-event"
description = "Cassandra State Change"
event_pattern = "${data.template_file.node-state-change.rendered}"
}
resource "aws_cloudwatch_event_target" "cass-event-target" {
target_id = "cassandra"
rule = "${aws_cloudwatch_event_rule.cass-event-rule.name}"
arn = "${var.cloudwatch_alarm_arn}"
}