From 137055852c05e818ee8c6662876e66bb6431159b Mon Sep 17 00:00:00 2001 From: Halil Bozan Date: Fri, 12 Jul 2024 12:20:20 +0300 Subject: [PATCH] chore: first commit for cloudwatch dashboard module --- modules/aws-cloudwatch-dashboard/main.tf | 153 ++++++++++++++++++ modules/aws-cloudwatch-dashboard/variables.tf | 25 +++ release-please-config.json | 9 ++ 3 files changed, 187 insertions(+) create mode 100644 modules/aws-cloudwatch-dashboard/main.tf create mode 100644 modules/aws-cloudwatch-dashboard/variables.tf diff --git a/modules/aws-cloudwatch-dashboard/main.tf b/modules/aws-cloudwatch-dashboard/main.tf new file mode 100644 index 0000000..502e688 --- /dev/null +++ b/modules/aws-cloudwatch-dashboard/main.tf @@ -0,0 +1,153 @@ +resource "aws_cloudwatch_dashboard" "main" { + dashboard_name = var.name + + dashboard_body = jsonencode({ + widgets = concat( + [ + { + "height": 6, + "width": 6, + "y": 0, + "x": 0, + "type": "metric", + "properties": { + "view": "timeSeries", + "stacked": false, + "metrics": [ + ["AWS/RDS", "CPUUtilization", { "stat": "Maximum", "label": "Top 10 RDS Instances", "id": "q1" }] + ], + "region": var.region, + "title": "Top 10 RDS instances by highest CPU utilization", + "yAxis": { + "left": { + "label": "Percent", + "showUnits": false + } + }, + "stat": "Average", + "period": 300 + } + }, + { + "height": 6, + "width": 6, + "y": 0, + "x": 6, + "type": "metric", + "properties": { + "view": "timeSeries", + "stacked": false, + "metrics": [ + ["AWS/RDS", "FreeableMemory", "DBInstanceIdentifier", "${var.environment}-rds-sql-server", { "period": 60 }] + ], + "region": var.region, + "title": "RDS - FreeableMemory" + } + }, + { + "height": 6, + "width": 6, + "y": 0, + "x": 12, + "type": "metric", + "properties": { + "view": "timeSeries", + "stacked": false, + "metrics": [ + ["AWS/RDS", "DBLoad", "DBInstanceIdentifier", "${var.environment}-rds-sql-server", { "period": 60 }] + ], + "region": var.region, + "title": "RDS - DBLoad" + } + }, + { + "height": 6, + "width": 24, + "y": 18, + "x": 0, + "type": "log", + "properties": { + "query": "SOURCE '/aws/containerinsights/${var.environment}-eks/application' | fields @timestamp, kubernetes.namespace_name, @message, @logStream, @log\n| sort @timestamp desc\n| limit 10000", + "region": var.region, + "stacked": false, + "view": "table", + "title": "EKS Applications - Log group: /aws/containerinsights/${var.environment}-eks/application" + } + }, + { + "height": 6, + "width": 6, + "y": 0, + "x": 18, + "type": "metric", + "properties": { + "view": "timeSeries", + "stacked": false, + "metrics": [ + ["AWS/RDS", "ReadThroughput", "DBInstanceIdentifier", "${var.environment}-rds-sql-server", { "period": 60 }], + [".", "WriteThroughput", ".", ".", { "period": 60 }] + ], + "region": var.region, + "title": "RDS - ReadThroughput, WriteThroughput" + } + }, + { + "height": 6, + "width": 6, + "y": 6, + "x": 0, + "type": "metric", + "properties": { + "view": "timeSeries", + "stacked": false, + "metrics": [ + ["AWS/RDS", "ReadLatency", "DBInstanceIdentifier", "${var.environment}-rds-sql-server", { "period": 60 }], + [".", "WriteLatency", ".", ".", { "period": 60 }] + ], + "region": var.region, + "title": "RDS - ReadLatency, WriteLatency" + } + }, + { + "height": 6, + "width": 6, + "y": 6, + "x": 6, + "type": "metric", + "properties": { + "view": "timeSeries", + "stacked": false, + "metrics": [ + ["AWS/RDS", "ReadIOPS", "DBInstanceIdentifier", "${var.environment}-rds-sql-server", { "period": 60 }], + [".", "WriteIOPS", ".", ".", { "period": 60 }] + ], + "region": var.region, + "title": "RDS - ReadIOPS, WriteIOPS" + } + } + ], + flatten([ + for namespace in var.namespaces : + [ + for app in var.applications : + { + "height": 6, + "width": 6, + "y": floor((index(var.namespaces, namespace) * length(var.applications) + index(var.applications, app)) / 4) * 6, + "x": ((index(var.namespaces, namespace) * length(var.applications) + index(var.applications, app)) % 4) * 6, + "type": "metric", + "properties": { + "view": "timeSeries", + "stacked": false, + "metrics": [ + ["ContainerInsights", "pod_cpu_utilization", "PodName", app, "ClusterName", "${var.environment}-eks", "Namespace", namespace] + ], + "region": var.region, + "title": "${namespace} - ${app} CPU Utilization" + } + } + ] + ]) + ) + }) +} diff --git a/modules/aws-cloudwatch-dashboard/variables.tf b/modules/aws-cloudwatch-dashboard/variables.tf new file mode 100644 index 0000000..78b94be --- /dev/null +++ b/modules/aws-cloudwatch-dashboard/variables.tf @@ -0,0 +1,25 @@ +variable "name" { + description = "The name of the CloudWatch dashboard" + type = string + default = "my-dashboard" +} + +variable "applications" { + description = "List of application names" + type = list(string) +} + +variable "namespaces" { + description = "List of namespace names" + type = list(string) +} + +variable "environment" { + type = string + description = "environment of eks or rds" +} + +variable "region" { + type = string + description = "AWS region" +} \ No newline at end of file diff --git a/release-please-config.json b/release-please-config.json index d89fa59..5d16e16 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -557,6 +557,15 @@ "bump-patch-for-minor-pre-major": false, "draft": false, "prerelease": false + }, + "modules/aws-cloudwatch-dashboard": { + "component": "aws-cloudwatch-dashboard", + "changelog-path": "CHANGELOG.md", + "release-type": "terraform-module", + "bump-minor-pre-major": true, + "bump-patch-for-minor-pre-major": false, + "draft": false, + "prerelease": false } }, "separate-pull-requests": true,