generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5214 from ministryofjustice/dsos-2618-create-poc-…
…cross-account-cloudwatch Dsos 2618 create poc cross account cloudwatch
- Loading branch information
Showing
25 changed files
with
536 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
274 changes: 274 additions & 0 deletions
274
terraform/environments/hmpps-oem/modules/cloudwatch_dashboard/dashboard.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,274 @@ | ||
resource "aws_cloudwatch_dashboard" "hmpps-oem_cloudwatch_dashboard" { | ||
dashboard_name = "CloudWatch-Default" | ||
dashboard_body = jsonencode(local.dashboard_body) | ||
} | ||
|
||
locals { | ||
|
||
cloudwatch_period = 300 | ||
region = "eu-west-2" | ||
|
||
dashboard_body = { | ||
widgets = [ | ||
local.EC2CPUUtil, | ||
local.EC2MemoryUtil, | ||
local.EC2DiskUsed, | ||
local.LoadBalancerTargetResponseTime, | ||
local.LoadBalancerRequestCount, | ||
local.LoadBalancerHTTP5XXsCount, | ||
local.EBSVolumeDiskIOPS, | ||
local.EBSVolumeDiskThroughput, | ||
local.AllEBSVolumeStats, | ||
local.LBGraphedMetricsHeading, | ||
local.EC2GraphedMetricsHeading, | ||
local.EBSGraphedMetricsHeading, | ||
] | ||
} | ||
|
||
EC2CPUUtil = { | ||
type = "metric" | ||
x = 0 | ||
y = 1 | ||
width = 7 | ||
height = 8 | ||
properties = { | ||
view = "timeSeries" | ||
stacked = false | ||
region = local.region | ||
title = "Top 5 instances by highest CPU Utilization %" | ||
stat = "Maximum" | ||
period = local.cloudwatch_period | ||
metrics = [ | ||
[{ "expression" : "SELECT MAX(CPUUtilization)\nFROM SCHEMA(\"AWS/EC2\", InstanceId)\nGROUP BY InstanceId\nORDER BY MAX() DESC\nLIMIT 5", "label" : "", "id" : "q1" }] | ||
] | ||
} | ||
} | ||
|
||
EC2MemoryUtil = { | ||
type = "metric" | ||
x = 7 | ||
y = 1 | ||
width = 6 | ||
height = 8 | ||
properties = { | ||
view = "bar" | ||
stacked = false | ||
region = local.region | ||
title = "EC2 Memory Utilization %" | ||
stat = "Maximum" | ||
period = local.cloudwatch_period | ||
metrics = [ | ||
[{ "expression" : "SELECT MAX(mem_used_percent) FROM SCHEMA(CWAgent, InstanceId,name,server_type) GROUP BY InstanceId ORDER BY MAX() DESC", "label" : "", "id" : "q1", "yAxis" : "left" }] | ||
] | ||
} | ||
} | ||
|
||
EC2DiskUsed = { | ||
type = "metric" | ||
x = 13 | ||
y = 1 | ||
width = 6 | ||
height = 8 | ||
properties = { | ||
view = "timeSeries" | ||
stacked = false | ||
region = local.region | ||
title = "EC2 Disk Used %" | ||
stat = "Maximum" | ||
period = local.cloudwatch_period | ||
metrics = [ | ||
[{ "expression" : "SELECT MAX(disk_used_percent) FROM SCHEMA(CWAgent, InstanceId) GROUP BY InstanceId ORDER BY MAX() DESC", "label" : "", "id" : "q1" }] | ||
] | ||
} | ||
} | ||
|
||
LoadBalancerTargetResponseTime = { | ||
type = "metric" | ||
x = 0 | ||
y = 10 | ||
width = 7 | ||
height = 8 | ||
properties = { | ||
view = "timeSeries" | ||
stacked = true | ||
region = local.region | ||
title = "LoadBalancer Target Response Time" | ||
stat = "Maximum" | ||
period = local.cloudwatch_period | ||
metrics = [ | ||
[{ "expression" : "SELECT MAX(TargetResponseTime) FROM SCHEMA(\"AWS/ApplicationELB\", LoadBalancer,TargetGroup) GROUP BY TargetGroup ORDER BY MAX() DESC", "label" : "", "id" : "q1" }] | ||
] | ||
} | ||
} | ||
|
||
LoadBalancerRequestCount = { | ||
type = "metric" | ||
x = 7 | ||
y = 10 | ||
width = 6 | ||
height = 8 | ||
properties = { | ||
view = "timeSeries" | ||
stacked = true | ||
region = local.region | ||
title = "LoadBalancer Request Count" | ||
stat = "Maximum" | ||
period = local.cloudwatch_period | ||
metrics = [ | ||
[{ "expression" : "SELECT COUNT(RequestCount) FROM \"AWS/ApplicationELB\" GROUP BY LoadBalancer ORDER BY COUNT() DESC", "label" : "", "id" : "q1" }] | ||
] | ||
} | ||
} | ||
|
||
LoadBalancerHTTP5XXsCount = { | ||
type = "metric" | ||
x = 13 | ||
y = 10 | ||
width = 6 | ||
height = 8 | ||
properties = { | ||
view = "timeSeries" | ||
stacked = true | ||
region = local.region | ||
title = "LoadBalancer HTTP 5XXs Count" | ||
stat = "Maximum" | ||
period = local.cloudwatch_period | ||
metrics = [ | ||
[{ "expression" : "SELECT COUNT(HTTPCode_ELB_5XX_Count) FROM SCHEMA(\"AWS/ApplicationELB\", AvailabilityZone,LoadBalancer,TargetGroup) GROUP BY LoadBalancer ORDER BY COUNT() DESC", "label" : "", "id" : "q1" }] | ||
] | ||
} | ||
} | ||
|
||
EBSVolumeDiskIOPS = { | ||
type = "metric" | ||
x = 0 | ||
y = 19 | ||
width = 12 | ||
height = 6 | ||
properties = { | ||
view = "timeSeries" | ||
stacked = false | ||
region = local.region | ||
title = "EBS Volumes Total IOPs" | ||
stat = "Sum" | ||
period = local.cloudwatch_period | ||
metrics = [ | ||
[{ "expression" : "m1/PERIOD(m1)", "label" : "Read IOPs", "id" : "e1" }], | ||
[{ "expression" : "m2/PERIOD(m2)", "label" : "Write IOPs", "id" : "e2" }], | ||
[{ "expression" : "e1+e2", "label" : "Total IOPs", "id" : "e3" }], | ||
["AWS/EBS", "VolumeReadOps", "VolumeId", "*", { "id" : "m1", "visible" : false }], | ||
["AWS/EBS", "VolumeWriteOps", "VolumeId", "*", { "id" : "m2", "visible" : false }] | ||
] | ||
} | ||
} | ||
|
||
EBSVolumeDiskThroughput = { | ||
type = "metric" | ||
x = 0 | ||
y = 25 | ||
width = 12 | ||
height = 6 | ||
properties = { | ||
view = "timeSeries" | ||
stacked = false | ||
region = local.region | ||
title = "EBS Volumes Throughput" | ||
stat = "Sum" | ||
period = local.cloudwatch_period | ||
metrics = [ | ||
[{ "expression" : "SELECT SUM(VolumeWriteBytes)\nFROM SCHEMA(\"AWS/EBS\", VolumeId)\nGROUP BY VolumeId\nORDER BY SUM() DESC\nLIMIT 10", "label" : "VolumeWriteBytes", "id" : "m3", "stat" : "Sum", "visible" : false }], | ||
[{ "expression" : "SELECT SUM(VolumeReadBytes) FROM SCHEMA(\"AWS/EBS\", VolumeId) GROUP BY VolumeId ORDER BY SUM() DESC LIMIT 10", "label" : "VolumeReadBytes", "id" : "m4", "stat" : "Sum", "visible" : false }], | ||
[{ "expression" : "(m4/(1024*1024))/PERIOD(m4)", "label" : "MB Read Per Second", "id" : "e4" }], | ||
[{ "expression" : "(m3/(1024*1024))/PERIOD(m3)", "label" : "MB Write Per Second", "id" : "e5" }], | ||
[{ "expression" : "e4+e5", "label" : "Total Consumed MB/s", "id" : "e6" }] | ||
] | ||
} | ||
} | ||
|
||
AllEBSVolumeStats = { | ||
type = "explorer" | ||
x = 0 | ||
y = 31 | ||
width = 24 | ||
height = 15 | ||
properties = { | ||
region = local.region | ||
title = "All EBS Volume Stats" | ||
stat = "Sum" | ||
period = local.cloudwatch_period | ||
widgetOptions = { | ||
view = "timeSeries" | ||
stacked = false | ||
rowsPerPage = 50 | ||
widgetsPerRow = 2 | ||
} | ||
labels = [ | ||
{ key : "application", value : "hmpps-oem" } | ||
] | ||
metrics = [ | ||
{ | ||
"metricName" : "VolumeReadBytes", | ||
"resourceType" : "AWS::EC2::Volume", | ||
"stat" : "Sum" | ||
}, | ||
{ | ||
"metricName" : "VolumeWriteBytes", | ||
"resourceType" : "AWS::EC2::Volume", | ||
"stat" : "Sum" | ||
}, | ||
{ | ||
"metricName" : "VolumeIdleTime", | ||
"resourceType" : "AWS::EC2::Volume", | ||
"stat" : "Average" | ||
}, | ||
{ | ||
"metricName" : "VolumeReadOps", | ||
"resourceType" : "AWS::EC2::Volume", | ||
"stat" : "Sum" | ||
}, | ||
{ | ||
"metricName" : "VolumeWriteOps", | ||
"resourceType" : "AWS::EC2::Volume", | ||
"stat" : "Sum" | ||
} | ||
] | ||
} | ||
} | ||
|
||
LBGraphedMetricsHeading = { | ||
type = "text" | ||
x = 0 | ||
y = 9 | ||
width = 24 | ||
height = 1 | ||
properties = { | ||
markdown = "## LoadBalancer Graphed Metrics" | ||
background = "solid" | ||
} | ||
} | ||
|
||
EC2GraphedMetricsHeading = { | ||
type = "text" | ||
x = 0 | ||
y = 0 | ||
width = 24 | ||
height = 1 | ||
properties = { | ||
markdown = "## EC2 Graphed Metrics" | ||
background = "solid" | ||
} | ||
} | ||
|
||
EBSGraphedMetricsHeading = { | ||
type = "text" | ||
x = 0 | ||
y = 18 | ||
width = 24 | ||
height = 1 | ||
properties = { | ||
markdown = "## EBS Volume Graphed Metrics" | ||
background = "solid" | ||
} | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
terraform/environments/hmpps-oem/modules/cloudwatch_dashboard/oam.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
resource "aws_oam_sink" "monitoring_account_oam_sink" { | ||
count = var.options.enable_cloudwatch_monitoring_account ? 1 : 0 | ||
name = "HMPPSOemSink" | ||
} | ||
|
||
resource "aws_oam_sink_policy" "monitoring_account_oam_sink_policy" { | ||
count = var.options.enable_cloudwatch_monitoring_account ? 1 : 0 | ||
sink_identifier = aws_oam_sink.monitoring_account_oam_sink[0].id | ||
|
||
policy = jsonencode ({ | ||
Version = "2012-10-17" | ||
Statement = [ | ||
{ | ||
Action = ["oam:CreateLink", "oam:UpdateLink"] | ||
Effect = "Allow" | ||
Resource = "*" | ||
Principal = { | ||
"AWS" = var.source_account_ids | ||
} | ||
Condition = { | ||
"ForAllValues:StringEquals" = { | ||
"oam:ResourceTypes" = ["AWS::CloudWatch::Metric"] | ||
} | ||
} | ||
} | ||
] | ||
}) | ||
} |
11 changes: 11 additions & 0 deletions
11
terraform/environments/hmpps-oem/modules/cloudwatch_dashboard/variables.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
variable "source_account_ids" { | ||
type = list(string) | ||
default = ["612659970365", "546088120047"] #nomis-test and oasys-test | ||
} | ||
|
||
variable "options" { | ||
description = "Map of options controlling what resources to return" | ||
type = object({ | ||
enable_cloudwatch_monitoring_account = optional(bool, false) | ||
}) | ||
} |
Oops, something went wrong.