Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
RMcVelia committed Dec 4, 2023
1 parent 8380121 commit c105a3b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
19 changes: 19 additions & 0 deletions aks/application/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
data "azurerm_resource_group" "monitoring" {
count = var.azure_enable_container_monitoring ? 1 : 0

name = "${var.azure_resource_prefix}-${var.service_short}-mn-rg"
}

data "azurerm_monitor_action_group" "main" {
count = var.azure_enable_container_monitoring ? 1 : 0

name = "${var.azure_resource_prefix}-${var.service_name}"
resource_group_name = data.azurerm_resource_group.monitoring[0].name
}

data "azurerm_kubernetes_cluster" "main" {
count = var.azure_enable_container_monitoring ? 1 : 0

name = "${var.cluster_configuration_map.resource_prefix}-aks"
resource_group_name = var.cluster_configuration_map.resource_group_name
}
34 changes: 34 additions & 0 deletions aks/application/resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,37 @@ resource "kubernetes_secret" "ghcr_auth" {
})
}
}

resource "azurerm_monitor_metric_alert" "container_restarts" {
count = var.azure_enable_container_monitoring ? 1 : 0

name = "${local.app_name}-restarts"
resource_group_name = data.azurerm_resource_group.monitoring[0].name
scopes = [data.azurerm_kubernetes_cluster.main[0].id]
description = "Action will be triggered when container restarts greate than 0"
window_size = "PT30M"

criteria {
metric_namespace = "Insights.container/pods"
metric_name = "restartingContainerCount"
aggregation = "Maximum"
operator = "GreaterThan"
threshold = 0

dimension {
name = "controllerName"
operator = "Include"
values = ["${local.app_name}"]
}
}

action {
action_group_id = data.azurerm_monitor_action_group.main[0].id
}

lifecycle {
ignore_changes = [
tags
]
}
}
17 changes: 17 additions & 0 deletions aks/application/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,20 @@ variable "github_personal_access_token" {
default = null
description = "Github Personal Access Token (PAT) of github_username"
}

variable "azure_resource_prefix" {
type = string
default = null
description = "Prefix of Azure resources for the service"
}

variable "service_short" {
type = string
default = null
description = "Short name of the service"
}

variable "azure_enable_container_monitoring" {
type = bool
default = false
}

0 comments on commit c105a3b

Please sign in to comment.