Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: first commit for cloudwatch dashboard module #250

Merged
merged 2 commits into from
Jul 12, 2024
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
153 changes: 153 additions & 0 deletions modules/aws-cloudwatch-dashboard/main.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
])
)
})
}
25 changes: 25 additions & 0 deletions modules/aws-cloudwatch-dashboard/variables.tf
Original file line number Diff line number Diff line change
@@ -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"
}
9 changes: 9 additions & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,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,
Expand Down