feat: add disk exporter module and related configurations

- Introduced a new disk exporter module to monitor disk health using SMART data.
- Updated `apps.tf` to include the disk exporter module with necessary parameters.
- Added local variables for smartctl version and checksum in `config.tf`.
- Enhanced `alertmanager.yml` to handle DiskUnhealthy alerts with specific grouping and dispatch settings.
- Created new Prometheus rules for monitoring disk health, including alerts for unhealthy disks.
- Updated Prometheus configuration to scrape metrics from the new disk exporter.
- Enhanced Telegram notification template to include resolved alerts and improved formatting.
- Updated the auth-exporter module to specify the Python image tag correctly.
- Created the disk-exporter module with Kubernetes resources, including deployment, service account, and config map.
- Added necessary Python scripts and requirements for the disk exporter functionality.
This commit is contained in:
2025-10-06 18:41:01 +02:00
parent 0e167d747d
commit 429a94332e
19 changed files with 766 additions and 41 deletions
@@ -0,0 +1,147 @@
resource "kubernetes_service_account" "disk_exporter" {
metadata {
name = "disk-exporter-sa"
namespace = var.namespace
}
}
resource "kubernetes_config_map" "disk_exporter" {
metadata {
name = "disk-exporter-config"
namespace = var.namespace
}
data = {
"exporter.py" = local.exporter_script
"requirements.txt" = local.requirements_txt
}
}
resource "kubernetes_deployment" "disk_exporter" {
metadata {
name = "disk-exporter"
namespace = var.namespace
labels = {
app = "disk-exporter"
}
}
spec {
replicas = 1
selector {
match_labels = {
app = "disk-exporter"
}
}
strategy {
type = "RollingUpdate"
}
template {
metadata {
labels = {
app = "disk-exporter"
}
annotations = {
"checksum/exporter" = local.exporter_checksum
"checksum/requirements" = local.requirements_checksum
}
}
spec {
service_account_name = kubernetes_service_account.disk_exporter.metadata[0].name
automount_service_account_token = false
container {
name = "disk-exporter"
image = "python:${var.tag}"
command = ["sh", "-c", join(" && ", local.commands)]
env {
name = "SMARTCTL_STATIC_VERSION"
value = var.smartctl_static_version
}
env {
name = "SMARTCTL_SHA256"
value = coalesce(var.smartctl_sha256, "")
}
env {
name = "SMARTCTL_CACHE_BASE"
value = "/tmp/smartctl-cache"
}
env {
name = "CHECK_FREQUENCY"
value = tostring(var.check_frequency)
}
env {
name = "STANDBY_MODE"
value = var.standby_mode
}
env {
name = "EXPORTER_PORT"
value = "9100"
}
env {
name = "DEVICE_ROOT"
value = "/dev"
}
port {
container_port = 9100
name = "http-metrics"
}
volume_mount {
name = "exporter-volume"
mount_path = "/exporter"
read_only = true
}
volume_mount {
name = "workdir"
mount_path = "/tmp"
}
security_context {
run_as_user = 0
run_as_group = 0
read_only_root_filesystem = true
privileged = true
}
}
volume {
name = "exporter-volume"
config_map {
name = kubernetes_config_map.disk_exporter.metadata[0].name
}
}
volume {
name = "workdir"
host_path {
path = local.workdir
type = "DirectoryOrCreate"
}
}
}
}
}
}
resource "kubernetes_service" "disk_exporter" {
metadata {
name = "disk-exporter"
namespace = var.namespace
labels = {
app = "disk-exporter"
}
}
spec {
selector = {
app = "disk-exporter"
}
port {
port = 9100
target_port = 9100
protocol = "TCP"
name = "http-metrics"
}
type = "ClusterIP"
}
}