@@ -27,44 +27,24 @@ resource "aws_cloudwatch_dashboard" "main" {
2727 }
2828 }
2929 },
30- # EC2 Memory Utilization
3130 {
3231 type = " metric"
3332 properties = {
3433 metrics = [
35- [" CWAgent" , " mem_used_percent" , " AutoScalingGroupName" , var.eb_autoscaling_group_name, { stat = " Average" }]
36- ]
37- period = 300
38- stat = " Average"
39- region = var.aws_region
40- title = " EC2 Memory Utilization (%)"
41- yAxis = {
42- left = {
43- min = 0
44- max = 100
45- }
46- }
47- }
48- },
49- # EB Request Count
50- {
51- type = " metric"
52- properties = {
53- metrics = [
54- [" AWS/ElasticBeanstalk" , " RequestCount" , " EnvironmentName" , var.eb_environment_name, { stat = " Sum" }]
34+ [" AWS/ApplicationELB" , " RequestCount" , " LoadBalancer" , var.alb_arn_suffix, { stat = " Sum" }]
5535 ]
5636 period = 300
5737 stat = " Sum"
5838 region = var.aws_region
5939 title = " Request Count"
6040 }
6141 },
62- # HTTP 5xx Errors
42+ # HTTP 5xx Errors (Target Responses)
6343 {
6444 type = " metric"
6545 properties = {
6646 metrics = [
67- [" AWS/ElasticBeanstalk " , " ApplicationRequests5xx " , " EnvironmentName " , var.eb_environment_name , { stat = " Sum" }]
47+ [" AWS/ApplicationELB " , " HTTPCode_Target_5XX_Count " , " LoadBalancer " , var.alb_arn_suffix , { stat = " Sum" }]
6848 ]
6949 period = 300
7050 stat = " Sum"
@@ -176,68 +156,22 @@ resource "aws_cloudwatch_metric_alarm" "eb_cpu_high" {
176156 }
177157}
178158
179- # High Memory Alarm
180- resource "aws_cloudwatch_metric_alarm" "eb_memory_high" {
181- alarm_name = " ${ var . project_name } -${ var . environment } -eb-memory-high"
182- comparison_operator = " GreaterThanThreshold"
183- evaluation_periods = 2
184- metric_name = " mem_used_percent"
185- namespace = " CWAgent"
186- period = 300
187- statistic = " Average"
188- threshold = 80
189- alarm_description = " This metric monitors EC2 memory utilization"
190- alarm_actions = [var . sns_topic_arn ]
191-
192- dimensions = {
193- AutoScalingGroupName = var.eb_autoscaling_group_name
194- }
195-
196- tags = {
197- Environment = var.environment
198- Project = var.project_name
199- }
200- }
201-
202- # Critical Memory Alarm
203- resource "aws_cloudwatch_metric_alarm" "eb_memory_critical" {
204- alarm_name = " ${ var . project_name } -${ var . environment } -eb-memory-critical"
205- comparison_operator = " GreaterThanThreshold"
206- evaluation_periods = 2
207- metric_name = " mem_used_percent"
208- namespace = " CWAgent"
209- period = 300
210- statistic = " Average"
211- threshold = 90
212- alarm_description = " This metric monitors EC2 memory utilization - CRITICAL"
213- alarm_actions = [var . sns_topic_arn ]
214-
215- dimensions = {
216- AutoScalingGroupName = var.eb_autoscaling_group_name
217- }
218-
219- tags = {
220- Environment = var.environment
221- Project = var.project_name
222- }
223- }
224-
225159# HTTP 5xx Error Rate Alarm
226160# This monitors server errors which indicate application health issues
227- resource "aws_cloudwatch_metric_alarm" "eb_http_5xx_errors " {
228- alarm_name = " ${ var . project_name } -${ var . environment } -eb -http-5xx-high"
161+ resource "aws_cloudwatch_metric_alarm" "alb_http_5xx_errors " {
162+ alarm_name = " ${ var . project_name } -${ var . environment } -alb -http-5xx-high"
229163 comparison_operator = " GreaterThanThreshold"
230164 evaluation_periods = 2
231- metric_name = " ApplicationRequests5xx "
232- namespace = " AWS/ElasticBeanstalk "
165+ metric_name = " HTTPCode_Target_5XX_Count "
166+ namespace = " AWS/ApplicationELB "
233167 period = 300
234168 statistic = " Sum"
235169 threshold = 10 # Alert if more than 10 5xx errors in 5 minutes
236170 alarm_description = " High rate of HTTP 5xx errors indicates application issues"
237171 alarm_actions = [var . sns_topic_arn ]
238172
239173 dimensions = {
240- EnvironmentName = var.eb_environment_name
174+ LoadBalancer = var.alb_arn_suffix
241175 }
242176
243177 tags = {
0 commit comments