From 4760aa6893f9cc8b7ec32c2267058fa7ecb76977 Mon Sep 17 00:00:00 2001 From: ghill95 Date: Mon, 18 Nov 2024 11:49:01 +0000 Subject: [PATCH] Extend CloudWatch Dashboard to allow EC2 metrics --- .../cloudwatch_dashboard.tf | 54 +++++++++++++++++++ .../cloudwatch-dashboard/variables.tf | 5 ++ 2 files changed, 59 insertions(+) diff --git a/resource-groups/cloudwatch-dashboard/cloudwatch_dashboard.tf b/resource-groups/cloudwatch-dashboard/cloudwatch_dashboard.tf index 1586ef91..da96a94b 100644 --- a/resource-groups/cloudwatch-dashboard/cloudwatch_dashboard.tf +++ b/resource-groups/cloudwatch-dashboard/cloudwatch_dashboard.tf @@ -371,6 +371,60 @@ resource "aws_cloudwatch_dashboard" "cloudwatch_dashboard" { "view": "timeSeries" } }, + { + type: "metric", + properties: { + "metrics": [ + for ec2_instance_id in var.ec2_instance_ids : [ + "AWS/EC2", + "CPUUtilization", + "InstanceId", + ec2_instance_id, + ] + ], + "period": 60 + "region": var.region, + "stacked": false, + "title": "ec2_instances_cpu_utilization", + "view": "timeSeries" + } + }, + { + type: "metric", + properties: { + "metrics": [ + for ec2_instance_id in var.ec2_instance_ids : [ + "AWS/EC2", + "NetworkIn", + "InstanceId", + ec2_instance_id, + ] + ], + "period": 60 + "region": var.region, + "stacked": false, + "title": "ec2_instances_network_in", + "view": "timeSeries" + } + }, + { + type: "metric", + properties: { + "metrics": [ + for ec2_instance_id in var.ec2_instance_ids : [ + "AWS/EC2", + "NetworkOut", + "InstanceId", + ec2_instance_id, + ] + ], + "period": 60 + "region": var.region, + "stacked": false, + "title": "ec2_instances_network_out", + "view": "timeSeries" + } + }, ] } ) diff --git a/resource-groups/cloudwatch-dashboard/variables.tf b/resource-groups/cloudwatch-dashboard/variables.tf index 62e2a37e..aeb13f58 100644 --- a/resource-groups/cloudwatch-dashboard/variables.tf +++ b/resource-groups/cloudwatch-dashboard/variables.tf @@ -13,6 +13,11 @@ variable "region" { type = string } +variable "ec2_instance_ids" { + description = "The ID(s) of the EC2 instances you wish to monitor (must be in list format)" + type = list(string) +} + variable "ecs_service_names" { description = "The name(s) of the ECS Services you wish to monitor (must be in list format)" type = list(string)