-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudwatch.tf
65 lines (60 loc) · 1.51 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
resource "aws_cloudwatch_dashboard" "main" {
dashboard_name = "main-${local.name_suffix}"
dashboard_body = jsonencode({
widgets = [
{
type = "metric"
width = 6
height = 6
properties = {
metrics = [
[
"AWS/Billing",
"EstimatedCharges",
]
]
period = 2592000
stat = "Maximum"
region = "us-east-1"
title = "Total Billing"
}
},
{
type = "metric"
x = 0
y = 0
width = 12
height = 6
properties = {
metrics = [
[
"AWS/EC2",
"CPUUtilization",
"InstanceId",
data.aws_instance.web_server.id
]
]
period = 300
stat = "Average"
region = "ap-northeast-1"
title = "EC2 Instance CPU"
}
},
]
})
}
resource "aws_cloudwatch_metric_alarm" "total_billing" {
alarm_description = "This metric monitors if total billing is over 8 USD or not."
alarm_name = "total-billing"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
metric_name = "EstimatedCharges"
namespace = "AWS/Billing"
provider = aws.us
statistic = "Maximum"
period = "21600"
threshold = var.total_billing
tags = {
Name = "total-billing-${local.name_suffix}"
}
}