Skip to content

Commit

Permalink
Create sanitech_monitoring.tf
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH committed Apr 19, 2024
1 parent 7e99da7 commit e8cb749
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions func/sanitech_monitoring.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
provider "aws" {
region = "us-east-1"
}

resource "aws_cloudwatch_dashboard" "sanitech_monitoring_dashboard" {
dashboard_name = "Sanitech Monitoring Dashboard"

dashboard_body = <<EOF
{
"widgets": [
{
"type": "metric",
"x": 0,
"y": 0,
"width": 12,
"height": 6,
"properties": {
"metrics": [
[
"AWS/EC2",
"CPUUtilization",
"InstanceId",
"i-0123456789abcdef0"
]
],
"period": 300,
"stat": "Average",
"region": "us-east-1",
"title": "EC2 Instance CPU Utilization"
}
},
{
"type": "metric",
"x": 0,
"y": 7,
"width": 12,
"height": 6,
"properties": {
"metrics": [
[
"AWS/EC2",
"NetworkPacketsIn",
"InstanceId",
"i-0123456789abcdef0"
]
],
"period": 300,
"stat": "Sum",
"region": "us-east-1",
"title": "EC2 Instance Network Packets In"
}
},
{
"type": "metric",
"x": 0,
"y": 14,
"width": 12,
"height": 6,
"properties": {
"metrics": [
[
"AWS/EC2",
"NetworkPacketsOut",
"InstanceId",
"i-0123456789abcdef0"
]
],
"period": 300,
"stat": "Sum",
"region": "us-east-1",
"title": "EC2 Instance Network Packets Out"
}
}
]
}
EOF
}

resource "aws_cloudwatch_alarm" "sanitech_ec2_cpu_utilization_high" {
alarm_name = "SanitechEC2CPUTilizationHigh"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = "300"
statistic = "Average"
threshold = "80"
alarm_description = "This metric monitors the CPU utilization of the SaniTech EC2 instance and sends an alert when the average CPU utilization is greater than or equal to 80% for 5 minutes."
alarm_actions = [aws_sns_topic.sanitech_notifications.arn]
}

resource "aws_sns_topic" "sanitech_notifications" {
name = "SanitechNotifications"
}

resource "aws_sns_topic_subscription" "sanitech_admin_notifications" {
topic_arn = aws_sns_topic.sanitech_notifications.arn
protocol = "email"
endpoint = "[email protected]"
}

0 comments on commit e8cb749

Please sign in to comment.