Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
feat: support alb_5xx_rate (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwittig committed Apr 3, 2023
1 parent a398e32 commit 08ccf9c
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
54 changes: 53 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ resource "aws_cloudwatch_event_target" "monitoring_jump_start_connection" {
{
"Type": "monitoring-jump-start-tf-connection",
"Module": "alb",
"Version": "1.0.0",
"Version": "1.1.0",
"Partition": "${data.aws_partition.current.partition}",
"AccountId": "${data.aws_caller_identity.current.account_id}",
"Region": "${data.aws_region.current.name}"
Expand Down Expand Up @@ -191,6 +191,58 @@ resource "aws_cloudwatch_metric_alarm" "alb_5xx_count_too_high_anomaly_detection
}
}

resource "aws_cloudwatch_metric_alarm" "alb_5xx_rate_too_high" {
depends_on = [aws_sns_topic_subscription.marbot]
count = (var.alb_5xx_rate == "static" && var.enabled) ? 1 : 0

alarm_name = "marbot-alb-5xx-rate-too-high-${random_id.id8.hex}"
alarm_description = "5XX responses relativ to request from ALB too high. (created by marbot)"
evaluation_periods = var.alb_5xx_rate_evaluation_periods
comparison_operator = "GreaterThanThreshold"
threshold = var.alb_5xx_rate_threshold
alarm_actions = [local.topic_arn]
ok_actions = [local.topic_arn]
treat_missing_data = "notBreaching"
tags = var.tags

metric_query {
id = "alb5xx" # must start with [a-z]
return_data = "false"
metric {
metric_name = "HTTPCode_ELB_5XX_Count"
namespace = "AWS/ApplicationELB"
period = var.alb_5xx_rate_period
stat = "Sum"

dimensions = {
LoadBalancer = var.loadbalancer_fullname
}
}
}

metric_query {
id = "requests"
return_data = "false"
metric {
metric_name = "RequestCount"
namespace = "AWS/ApplicationELB"
period = var.alb_5xx_rate_period
stat = "Sum"

dimensions = {
LoadBalancer = var.loadbalancer_fullname
}
}
}

metric_query {
id = "rate"
expression = "IF(requests<10, 0, alb5xx/requests)"
label = "5XX rate"
return_data = "true"
}
}

resource "aws_cloudwatch_metric_alarm" "alb_rejected_connection_count_too_high" {
depends_on = [aws_sns_topic_subscription.marbot]
count = (var.alb_rejected_connection_count == "static" && var.enabled) ? 1 : 0
Expand Down
26 changes: 26 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,32 @@ variable "alb_5xx_count_evaluation_periods" {



variable "alb_5xx_rate" {
type = string
description = "5XX responses from the ALB relativ to requests (static|off)."
default = "off"
}

variable "alb_5xx_rate_threshold" {
type = number
description = "The maximum rate (in %) of 5XX responses from the ALB (0-100)."
default = 5
}

variable "alb_5xx_rate_period" {
type = number
description = "The period in seconds over which the specified statistic is applied (<= 86400 and multiple of 60)."
default = 300
}

variable "alb_5xx_rate_evaluation_periods" {
type = number
description = "The number of periods over which data is compared to the specified threshold (>= 1 and $period*$evaluation_periods <= 86400)."
default = 1
}



variable "alb_rejected_connection_count" {
type = string
description = "Rejected connections because the ALB had reached its maximum number of connections (static|off)."
Expand Down

0 comments on commit 08ccf9c

Please sign in to comment.