-
Notifications
You must be signed in to change notification settings - Fork 10
/
cloudwatch.tf
95 lines (89 loc) · 2.85 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
/**
* Copyright (C) 2018-2019 Expedia Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
*/
resource "aws_cloudwatch_log_group" "waggledance_ecs" {
count = var.wd_instance_type == "ecs" ? 1 : 0
name = local.instance_alias
tags = var.tags
}
resource "aws_cloudwatch_dashboard" "apiary_federation" {
count = var.wd_instance_type == "ecs" ? 1 : 0
dashboard_name = "${local.instance_alias}-${var.aws_region}"
dashboard_body = <<EOF
{
"widgets": [
{
"type":"metric",
"width":12,
"height":6,
"properties":{
"metrics":[
[ "AWS/ECS", "CPUUtilization", "ServiceName", "${local.instance_alias}-service", "ClusterName", "${local.instance_alias}" ]
],
"period":300,
"stat":"Average",
"region":"${var.aws_region}",
"title":"WaggleDance ECS CPU Utilization"
}
},
{
"type":"metric",
"width":12,
"height":6,
"properties":{
"metrics":[
[ "AWS/ECS", "MemoryUtilization", "ServiceName", "${local.instance_alias}-service", "ClusterName", "${local.instance_alias}" ]
],
"period":300,
"stat":"Average",
"region":"${var.aws_region}",
"title":"WaggleDance ECS Memory Utilization"
}
}
]
}
EOF
}
locals {
alerts = [
{
alarm_name = "${local.instance_alias}-cpu"
namespace = "AWS/ECS"
metric_name = "CPUUtilization"
threshold = "80"
},
{
alarm_name = "${local.instance_alias}-memory"
namespace = "AWS/ECS"
metric_name = "MemoryUtilization"
threshold = "70"
},
]
dimensions = [
{
ClusterName = "${local.instance_alias}"
ServiceName = "${local.instance_alias}-service"
},
{
ClusterName = "${local.instance_alias}"
ServiceName = "${local.instance_alias}-service"
},
]
}
resource "aws_cloudwatch_metric_alarm" "waggledance_alert" {
count = var.wd_instance_type == "ecs" ? length(local.alerts) : 0
alarm_name = local.alerts[count.index].alarm_name
comparison_operator = lookup(local.alerts[count.index], "comparison_operator", "GreaterThanOrEqualToThreshold")
metric_name = local.alerts[count.index].metric_name
namespace = local.alerts[count.index].namespace
period = lookup(local.alerts[count.index], "period", "120")
evaluation_periods = lookup(local.alerts[count.index], "evaluation_periods", "2")
statistic = "Average"
threshold = local.alerts[count.index].threshold
#alarm_description = ""
insufficient_data_actions = []
dimensions = local.dimensions[count.index]
alarm_actions = [aws_sns_topic.apiary_federation_ops_sns[0].arn]
}