forked from crewjam/etcd-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
health.go
70 lines (63 loc) · 2.73 KB
/
health.go
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
package aws
import (
"fmt"
cfn "github.com/crewjam/go-cloudformation"
)
// MakeHealthCheck creates CloudWatch alarms that monitor the health of the cluster.
// Notifications go to the HealthTopic. You should subscribe manually to this topic
// if you care about the health of the cluster.
func MakeHealthCheck(parameters *Parameters, t *cfn.Template) error {
t.AddResource("HealthTopic", cfn.SNSTopic{
DisplayName: cfn.String(fmt.Sprintf("cloudwatch notifications for %s", parameters.DnsName)),
})
t.AddResource("MasterLoadBalancerHealthAlarm", cfn.CloudWatchAlarm{
ActionsEnabled: cfn.Bool(true),
AlarmActions: cfn.StringList(cfn.Ref("HealthTopic").String()),
OKActions: cfn.StringList(cfn.Ref("HealthTopic").String()),
AlarmDescription: cfn.String("master instance health"),
AlarmName: cfn.String("MasterInstanceHealth"),
ComparisonOperator: cfn.String("LessThanThreshold"),
EvaluationPeriods: cfn.String("1"),
Dimensions: &cfn.CloudWatchMetricDimensionList{
cfn.CloudWatchMetricDimension{
Name: cfn.String("LoadBalancerName"),
Value: cfn.Ref("MasterLoadBalancer").String(),
},
},
MetricName: cfn.String("HealthyHostCount"),
Namespace: cfn.String("AWS/ELB"),
Period: cfn.String("60"),
Statistic: cfn.String("Minimum"),
Unit: cfn.String("Count"),
// Note: for scale=3 we should have no fewer than 1 healthy instance
// *PER AVAILABILITY ZONE*. This is confusing, I know.
Threshold: cfn.String("1"),
})
t.Resources["MasterLoadBalancerHealthAlarm"].DependsOn = []string{"HealthTopic"}
// this alarm is triggered (mostly) by the requirement that data be present.
// if it isn't for 300 seconds, then the backups are failing and the check goes
// into the INSUFFICIENT_DATA state and we are alerted.
t.AddResource("MasterBackupHealthAlarm", cfn.CloudWatchAlarm{
ActionsEnabled: cfn.Bool(true),
AlarmActions: cfn.StringList(cfn.Ref("HealthTopic").String()),
InsufficientDataActions: cfn.StringList(cfn.Ref("HealthTopic").String()),
OKActions: cfn.StringList(cfn.Ref("HealthTopic").String()),
AlarmDescription: cfn.String("key backup count"),
AlarmName: cfn.String("MasterBackupKeyCount"),
ComparisonOperator: cfn.String("LessThanThreshold"),
EvaluationPeriods: cfn.String("1"),
Dimensions: &cfn.CloudWatchMetricDimensionList{
cfn.CloudWatchMetricDimension{
Name: cfn.String("AutoScalingGroupName"),
Value: cfn.Ref("MasterAutoscale").String(),
},
},
MetricName: cfn.String("BackupKeyCount"),
Namespace: cfn.String("Local/etcd"),
Period: cfn.String("300"),
Statistic: cfn.String("Minimum"),
Unit: cfn.String("Count"),
Threshold: cfn.String("1"),
})
return nil
}