Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ecs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ Based on [AWS reference architecture](https://github.com/aws-samples/ecs-refarch

The canonical hosted zone ID of the Application Load Balancer (to be used in a Route 53 Alias record)

* `metrics`

ECS cluster Cloudwatch metrics, see [metrics.tf](./metrics.tf) for details

* `name`

Cluster name
Expand Down Expand Up @@ -216,3 +220,7 @@ Based on [AWS reference architecture](https://github.com/aws-samples/ecs-refarch
* `web_service_role_name`

ECS web service task role name

* `widgets`

ECS cluster Cloudwatch dashboard widgets, see [widgets.tf](./widgets.tf) for details
5 changes: 5 additions & 0 deletions ecs/example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ module "dashboard" {

name = "terraform-ecs-example"
widgets = [
module.cluster.widgets.cpu_utilization,
module.cluster.widgets.memory_utilization,
module.cluster.widgets.instances,
module.cluster.widgets.services,
module.cluster.widgets.tasks,
module.cluster.lb_widgets.responses,
module.cluster.lb_widgets.response_percentages,
module.cluster.lb_widgets.target_response_time,
Expand Down
80 changes: 80 additions & 0 deletions ecs/metrics.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
locals {
metrics = {
cpu_utilization = module.metrics_cpu.out_map.utilization
cpu_reservation = module.metrics_cpu.out_map.reservation
memory_utilization = module.metrics_memory.out_map.utilization
memory_reservation = module.metrics_memory.out_map.reservation

instances = module.metrics_count.out_map.instance
services = module.metrics_count.out_map.service
tasks = module.metrics_count.out_map.task
}
}

module "cloudwatch_consts" {
source = "./../cloudwatch/consts"
}

locals {
colors = module.cloudwatch_consts.colors
}

locals {
cluster_dimensions = {
ClusterName = var.create ? aws_ecs_cluster.cluster[0].name : ""
}

metrics_utilization = {
reservation = { name = "Reservation", color = local.colors.grey }
utilization = { name = "Utilization", color = local.colors.orange }
}
}

module "metrics_cpu" {
source = "./../cloudwatch/metric/many"

vars_map = { for k, v in local.metrics_utilization : k => {
namespace = "AWS/ECS"
dimensions = local.cluster_dimensions
name = "CPU${v.name}"
label = "CPU ${lower(v.name)}"
color = v.color
stat = "Average"
period = 60
} }
}

module "metrics_memory" {
source = "./../cloudwatch/metric/many"

vars_map = { for k, v in local.metrics_utilization : k => {
namespace = "AWS/ECS"
dimensions = local.cluster_dimensions
name = "Memory${v.name}"
label = "Memory ${lower(v.name)}"
color = v.color
stat = "Average"
period = 60
} }
}

locals {
metrics_count = {
instance = { name = "ContainerInstance", label = "Instances" }
service = { name = "Service", label = "Services" }
task = { name = "Task", label = "Tasks" }
}
}

module "metrics_count" {
source = "./../cloudwatch/metric/many"

vars_map = { for k, v in local.metrics_count : k => {
namespace = "ECS/ContainerInsights"
dimensions = local.cluster_dimensions
name = "${v.name}Count"
label = v.label
stat = "Average"
period = 60
} }
}
10 changes: 10 additions & 0 deletions ecs/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ output "arn" {
description = "Cluster ARN"
}

output "metrics" {
value = local.metrics
description = "ECS cluster Cloudwatch metrics, see [metrics.tf](./metrics.tf) for details"
}

output "widgets" {
value = local.widgets
description = "ECS cluster Cloudwatch dashboard widgets, see [widgets.tf](./widgets.tf) for details"
}

# network outputs

output "vpc_id" {
Expand Down
56 changes: 56 additions & 0 deletions ecs/widgets.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
locals {
widgets = {
cpu_utilization = module.widget_cpu_utilization
memory_utilization = module.widget_memory_utilization

instances = module.widget_instances
services = module.widget_services
tasks = module.widget_tasks
}
}

module "widget_cpu_utilization" {
source = "./../cloudwatch/metric_widget"

title = "ECS CPU utilization"
left_metrics = [
local.metrics.cpu_reservation,
local.metrics.cpu_utilization,
]
left_range = [0, 100]
}

module "widget_memory_utilization" {
source = "./../cloudwatch/metric_widget"

title = "ECS memory utilization"
left_metrics = [
local.metrics.memory_reservation,
local.metrics.memory_utilization,
]
left_range = [0, 100]
}

module "widget_instances" {
source = "./../cloudwatch/metric_widget"

title = "ECS instances"
left_metrics = [local.metrics.instances]
left_range = [0, null]
}

module "widget_services" {
source = "./../cloudwatch/metric_widget"

title = "ECS services"
left_metrics = [local.metrics.services]
left_range = [0, null]
}

module "widget_tasks" {
source = "./../cloudwatch/metric_widget"

title = "ECS tasks"
left_metrics = [local.metrics.tasks]
left_range = [0, null]
}