-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
550c880
commit aac2c85
Showing
9 changed files
with
276 additions
and
218 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,169 +1,24 @@ | ||
locals { | ||
trusted_advisor_service_limits = { | ||
AutoScaling = [ | ||
"Auto Scaling groups", | ||
"Launch configurations" | ||
] | ||
CloudFormation = [ | ||
"Stacks" | ||
] | ||
DynamoDB = [ | ||
"DynamoDB Read Capacity", | ||
"DynamoDB Write Capacity" | ||
] | ||
EBS = [ | ||
"Active snapshots", | ||
"Cold HDD (sc1) volume storage (TiB)", | ||
"General Purpose SSD (gp2) volume storage (TiB)", | ||
"General Purpose SSD (gp3) volume storage", | ||
"Magnetic (standard) volume storage (TiB)", | ||
"Provisioned IOPS (SSD) storage (TiB)", | ||
"Provisioned IOPS SSD (io2) Volume Storage", | ||
"Provisioned IOPS", | ||
"Throughput Optimized HDD (st1) volume storage (TiB)", | ||
] | ||
EC2 = [ | ||
"Elastic IP addresses (EIPs)", | ||
"On-Demand instances" | ||
] | ||
ELB = [ | ||
"Active Application Load Balancers", | ||
"Active Network Load Balancers", | ||
"Active load balancers", | ||
] | ||
Kinesis = [ | ||
"Shards per region" | ||
] | ||
RDS = [ | ||
"Clusters", | ||
"Cluster parameter groups", | ||
"DB parameter groups", | ||
"DB instances", | ||
"Event subscriptions", | ||
"RDS DB Manual Snapshots", | ||
"Read replicas per master", | ||
"Storage quota (GB)", | ||
"Subnet groups", | ||
"Subnets per subnet group", | ||
] | ||
SES = [ | ||
"Daily sending quota" | ||
] | ||
VPC = [ | ||
"EC2-VPC Elastic IP addresses (EIPs)", | ||
"Internet gateways", | ||
"VPCs", | ||
] | ||
} | ||
|
||
usage_service_limits = { | ||
AutoScaling = { | ||
None = ["NumberOfAutoScalingGroup"] | ||
} | ||
CloudWatch = { | ||
None = ["InsightRule"] | ||
} | ||
DynamoDB = { | ||
None = [ | ||
"AccountProvisionedWriteCapacityUnits", | ||
"AccountProvisionedReadCapacityUnits", | ||
] | ||
} | ||
EC2 = { | ||
"Standard/OnDemand" = ["vCPU"] | ||
"Standard/Spot" = ["vCPU"] | ||
} | ||
"Elastic Load Balancing" = { | ||
None = [ | ||
"TargetGroupsPerApplicationLoadBalancer", | ||
"ListenersPerApplicationLoadBalancer", | ||
"TargetsPerTargetGroupPerRegion", | ||
"TargetsPerAvailabilityZonePerNetworkLoadBalancer", | ||
"TargetsPerApplicationLoadBalancer", | ||
"ListenersPerClassicLoadBalancer", | ||
"RoutingRulesPerApplicationLoadBalancer", | ||
"RegisteredInstancesPerClassicLoadBalancer", | ||
"TargetsPerNetworkLoadBalancer", | ||
"ClassicLoadBalancersPerRegion", | ||
"ListenersPerNetworkLoadBalancer", | ||
"NetworkLoadBalancersENIsPerVPC", | ||
"CertificatesPerApplicationLoadBalancer", | ||
"TargetGroupsPerRegion", | ||
"CertificatesPerNetworkLoadBalancer", | ||
"ApplicationLoadBalancersPerRegion", | ||
"NetworkLoadBalancersPerRegion", | ||
] | ||
} | ||
Firehose = { | ||
None = ["DeliveryStreams"] | ||
} | ||
SNS = { | ||
None = ["NumberOfMessagesPublishedPerAccount"] | ||
usage_widget_header = { | ||
type = "text" | ||
width = 24 | ||
height = 2 | ||
properties = { | ||
"markdown" : "# Usage metrics \n### These metrics come from the `AWS/Usage` namespace [here](https://us-east-1.console.aws.amazon.com/cloudwatch/home?region=us-east-1#metricsV2?graph=~()&query=~'*7bAWS*2fUsage*2cClass*2cResource*2cService*2cType*7d*20AWS*2fUsage*20MetricName*3dResourceCount) \n" | ||
} | ||
} | ||
|
||
metrics_normalized_all = flatten([ | ||
for region in var.regions : [ | ||
for service_name, data in local.usage_service_limits : [ | ||
for class, limits in data : [ | ||
for resource in limits : { | ||
class = class | ||
resource = resource | ||
region = region | ||
service_name = service_name | ||
id = replace(replace(lower(replace(join("", [service_name, class, resource]), "-", "")), " ", ""), "/", "") | ||
label = format("%s (%s): %s", service_name, class, resource) | ||
} | ||
] | ||
] | ||
] | ||
]) | ||
|
||
metrics_normalized_service_region = { | ||
for service_name, data in local.usage_service_limits : service_name => { | ||
for region in var.regions : region => [for metric in local.metrics_normalized_all : metric if metric.region == region && metric.service_name == service_name] | ||
trusted_advisor_widget_header = { | ||
type = "text" | ||
width = 24 | ||
height = 2 | ||
properties = { | ||
"markdown" : "# TrustedAdvisor metrics \n### These metrics come from the `AWS/TrustedAdvisor` namespace [here](https://us-east-1.console.aws.amazon.com/cloudwatch/home?region=us-east-1#metricsV2?graph=~()&query=~'*7bAWS*2fTrustedAdvisor*2cRegion*2cServiceLimit*2cServiceName*7d*20MetricName*3dServiceLimitUsage) \n" | ||
} | ||
} | ||
|
||
dashboard_widgets = flatten([ | ||
for service_name, region_data in local.metrics_normalized_service_region : [ | ||
for region, metrics in region_data : [ | ||
{ | ||
type = "metric" | ||
properties = { | ||
stat = "Sum" | ||
region = region | ||
period = 300 | ||
view = "timeSeries" | ||
title = format("%s: %s", service_name, region) | ||
yAxis = { | ||
left = { | ||
label = "Quota usage percentage" | ||
max = 100 | ||
min = 0 | ||
showUnits = false | ||
} | ||
} | ||
metrics = concat([ | ||
for metric in metrics : flatten([ | ||
[ | ||
"AWS/Usage", "ResourceCount", "Class", metric["class"], "Resource", metric["resource"], "Service", metric["service_name"], "Type", "Resource", | ||
{ id = metric["id"], region = metric["region"], visible = false } | ||
] | ||
]) | ||
], | ||
[for metric in metrics : [ | ||
{ expression = "(${metric.id}/SERVICE_QUOTA(${metric.id}))*100", label = metric["label"], region = metric["region"] } | ||
]] | ||
) | ||
} | ||
} | ||
] | ||
] | ||
]) | ||
} | ||
|
||
resource "aws_cloudwatch_dashboard" "main" { | ||
dashboard_name = "ServiceQuotaUsage" | ||
dashboard_body = jsonencode({ widgets = local.dashboard_widgets }) | ||
dashboard_body = jsonencode({ widgets = concat([local.usage_widget_header], local.usage_dashboard_widgets, [local.trusted_advisor_widget_header], local.trusted_advisor_dashboard_widgets) }) | ||
} |
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,115 @@ | ||
locals { | ||
trusted_advisor_service_limits = { | ||
AutoScaling = [ | ||
"Auto Scaling groups", | ||
"Launch configurations" | ||
] | ||
CloudFormation = [ | ||
"Stacks" | ||
] | ||
DynamoDB = [ | ||
"DynamoDB Read Capacity", | ||
"DynamoDB Write Capacity" | ||
] | ||
EBS = [ | ||
"Active snapshots", | ||
"Cold HDD (sc1) volume storage (TiB)", | ||
"General Purpose SSD (gp2) volume storage (TiB)", | ||
"General Purpose SSD (gp3) volume storage", | ||
"Magnetic (standard) volume storage (TiB)", | ||
"Provisioned IOPS (SSD) storage (TiB)", | ||
"Provisioned IOPS SSD (io2) Volume Storage", | ||
"Provisioned IOPS", | ||
"Throughput Optimized HDD (st1) volume storage (TiB)", | ||
] | ||
EC2 = [ | ||
"Elastic IP addresses (EIPs)", | ||
"On-Demand instances" | ||
] | ||
ELB = [ | ||
"Active Application Load Balancers", | ||
"Active Network Load Balancers", | ||
"Active load balancers", | ||
] | ||
Kinesis = [ | ||
"Shards per region" | ||
] | ||
RDS = [ | ||
"Clusters", | ||
"Cluster parameter groups", | ||
"DB parameter groups", | ||
"DB instances", | ||
"Event subscriptions", | ||
"RDS DB Manual Snapshots", | ||
"Read replicas per master", | ||
"Storage quota (GB)", | ||
"Subnet groups", | ||
"Subnets per subnet group", | ||
] | ||
SES = [ | ||
"Daily sending quota" | ||
] | ||
VPC = [ | ||
"EC2-VPC Elastic IP addresses (EIPs)", | ||
"Internet gateways", | ||
"VPCs", | ||
] | ||
} | ||
|
||
trusted_advisor_metrics_normalized_all = flatten([ | ||
for region in var.regions : [ | ||
for service_name, limits in local.trusted_advisor_service_limits : [ | ||
for resource in limits : { | ||
resource = resource | ||
region = region | ||
service_name = service_name | ||
id = lower(replace(format("%s%s", service_name, resource), "/[\\W_]+/", "")) | ||
label = format("%s: %s", service_name, resource) | ||
} | ||
] | ||
] | ||
]) | ||
|
||
trusted_advisor_metrics_normalized_service_region = { | ||
for service_name, limits in local.trusted_advisor_service_limits : service_name => { | ||
for region in var.regions : region => [for metric in local.trusted_advisor_metrics_normalized_all : metric if metric.region == region && metric.service_name == service_name] | ||
} | ||
} | ||
|
||
trusted_advisor_dashboard_widgets = flatten([ | ||
for service_name, region_data in local.trusted_advisor_metrics_normalized_service_region : [ | ||
for region, metrics in region_data : [ | ||
{ | ||
type = "metric" | ||
properties = { | ||
stat = "Sum" | ||
region = "us-east-1" | ||
period = 300 | ||
view = "timeSeries" | ||
title = format("%s: %s", service_name, region) | ||
yAxis = { | ||
left = { | ||
label = "Quota usage percentage" | ||
min = 0 | ||
max = 100 | ||
showUnits = false | ||
} | ||
} | ||
metrics = concat([ | ||
for metric in metrics : flatten([ | ||
[ | ||
"AWS/TrustedAdvisor", "ServiceLimitUsage", "ServiceName", metric["service_name"], "ServiceLimit", metric["resource"], "Region", metric["region"], | ||
{ id = metric["id"], visible = false } | ||
] | ||
]) | ||
], | ||
[for metric in metrics : [ | ||
{ expression = "${metric.id}*100", label = metric["label"] } | ||
]] | ||
) | ||
} | ||
} | ||
] | ||
] | ||
]) | ||
} |
Oops, something went wrong.