Skip to content

Commit

Permalink
Added alert frequency monitor metric
Browse files Browse the repository at this point in the history
  • Loading branch information
VenkataChalla554 committed Jul 26, 2024
1 parent 7ffc46f commit ac9168f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
14 changes: 14 additions & 0 deletions aks/postgres/resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ locals {
azure_enable_monitoring = var.use_azure && var.azure_enable_monitoring

kubernetes_name = "${var.service_name}-${var.environment}-postgres${local.name_suffix}"

alert_frequency = local.alert_frequency_map[var.alert_window_size]

alert_frequency_map = {
PT1M = "PT1M"
PT5M = "PT5M"
PT15M = "PT15M"
PT30M = "PT30M"
PT1H = "PT1H"
}

}

# Username & password
Expand Down Expand Up @@ -172,6 +183,7 @@ resource "azurerm_monitor_metric_alert" "memory" {
scopes = [azurerm_postgresql_flexible_server.main[0].id]
description = "Action will be triggered when memory use is greater than 75%"
window_size = var.alert_window_size
frequency = local.alert_frequency

criteria {
metric_namespace = "Microsoft.DBforPostgreSQL/flexibleServers"
Expand Down Expand Up @@ -200,6 +212,7 @@ resource "azurerm_monitor_metric_alert" "cpu" {
scopes = [azurerm_postgresql_flexible_server.main[0].id]
description = "Action will be triggered when cpu use is greater than ${var.azure_cpu_threshold}%"
window_size = var.alert_window_size
frequency = local.alert_frequency

criteria {
metric_namespace = "Microsoft.DBforPostgreSQL/flexibleServers"
Expand Down Expand Up @@ -228,6 +241,7 @@ resource "azurerm_monitor_metric_alert" "storage" {
scopes = [azurerm_postgresql_flexible_server.main[0].id]
description = "Action will be triggered when storage use is greater than ${var.azure_storage_threshold}%"
window_size = var.alert_window_size
frequency = local.alert_frequency

criteria {
metric_namespace = "Microsoft.DBforPostgreSQL/flexibleServers"
Expand Down
14 changes: 11 additions & 3 deletions aks/postgres/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,21 @@ variable "azure_enable_monitoring" {
default = true
}



variable "alert_window_size" {
type = string
nullable = false
default = "PT5M"
type = string
nullable = false
default = "PT5M"
validation {
condition = contains(["PT1M", "PT5M", "PT15M", "PT30M", "PT1H"], var.alert_window_size)
error_message = "The alert_window_size must be one of: PT1M, PT5M, PT15M, PT30M, PT1H."
}
description = "The period of time that is used to monitor alert activity e.g PT1M, PT5M, PT15M, PT30M, PT1H, PT6H or PT12H"
}



variable "azure_maintenance_window" {
type = object({
day_of_week = optional(number)
Expand Down

0 comments on commit ac9168f

Please sign in to comment.