-
Notifications
You must be signed in to change notification settings - Fork 18
/
emr_cluster_report_age.sp
149 lines (128 loc) · 3.14 KB
/
emr_cluster_report_age.sp
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
dashboard "emr_cluster_age_report" {
title = "AWS EMR Cluster Age Report"
documentation = file("./dashboards/emr/docs/emr_cluster_report_age.md")
tags = merge(local.emr_common_tags, {
type = "Report"
category = "Age"
})
container {
card {
query = query.emr_cluster_count
width = 2
}
card {
type = "info"
width = 2
query = query.emr_cluster_24_hours_count
}
card {
type = "info"
width = 2
query = query.emr_cluster_30_days_count
}
card {
type = "info"
width = 2
query = query.emr_cluster_30_90_days_count
}
card {
width = 2
type = "info"
query = query.emr_cluster_90_365_days_count
}
card {
width = 2
type = "info"
query = query.emr_cluster_1_year_count
}
}
table {
column "Account ID" {
display = "none"
}
column "ARN" {
display = "none"
}
column "Cluster ID" {
href = "${dashboard.emr_cluster_detail.url_path}?input.emr_cluster_arn={{.ARN | @uri}}"
}
query = query.emr_cluster_age_table
}
}
query "emr_cluster_24_hours_count" {
sql = <<-EOQ
select
count(*) as value,
'< 24 hours' as label
from
aws_emr_cluster
where
(status -> 'Timeline' ->> 'CreationDateTime')::timestamp > now() - '1 days' :: interval;
EOQ
}
query "emr_cluster_30_days_count" {
sql = <<-EOQ
select
count(*) as value,
'1-30 Days' as label
from
aws_emr_cluster
where
(status -> 'Timeline' ->> 'CreationDateTime')::timestamp between symmetric now() - '1 days' :: interval and now() - '30 days' :: interval;
EOQ
}
query "emr_cluster_30_90_days_count" {
sql = <<-EOQ
select
count(*) as value,
'30-90 Days' as label
from
aws_emr_cluster
where
(status -> 'Timeline' ->> 'CreationDateTime')::timestamp between symmetric now() - '30 days' :: interval and now() - '90 days' :: interval;
EOQ
}
query "emr_cluster_90_365_days_count" {
sql = <<-EOQ
select
count(*) as value,
'90-365 Days' as label
from
aws_emr_cluster
where
(status -> 'Timeline' ->> 'CreationDateTime')::timestamp between symmetric (now() - '90 days'::interval) and (now() - '365 days'::interval);
EOQ
}
query "emr_cluster_1_year_count" {
sql = <<-EOQ
select
count(*) as value,
'> 1 Year' as label
from
aws_emr_cluster
where
(status -> 'Timeline' ->> 'CreationDateTime')::timestamp <= now() - '1 year' :: interval;
EOQ
}
query "emr_cluster_age_table" {
sql = <<-EOQ
select
c.id as "Cluster ID",
c.name as "Name",
now()::date - (c.status -> 'Timeline' ->> 'CreationDateTime')::date as "Age in Days",
c.status -> 'Timeline' ->> 'CreationDateTime' as "Creation Time",
c.state as "State",
a.title as "Account",
c.account_id as "Account ID",
c.region as "Region",
c.cluster_arn as "ARN"
from
aws_emr_cluster as c,
aws_account as a
where
c.account_id = a.account_id
order by
c.status -> 'Timeline' ->> 'CreationDateTime',
c.id;
EOQ
}