From 8436295bbc4c551c2767c4a65e50a6e9c47e1859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Rodrigues?= <95761178+GoncaloRodri@users.noreply.github.com> Date: Fri, 26 Jun 2026 17:44:14 +0100 Subject: [PATCH] feat(infra): gate observability stack behind var.enable_monitoring (#38) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds enable_monitoring variable (default true) that controls whether Prometheus/Grafana, Loki, Fluent Bit, and Jaeger are deployed. Setting it to false saves ~1.5 GB RAM, making the stack viable on a 2–4 GB VPS without touching the application services. Also caps MongoDB WiredTiger cache at 256 MB (--wiredTigerCacheSizeGB=0.25) so it doesn't balloon on memory-constrained hosts. Co-authored-by: Gonçalo Rodrigues Co-authored-by: Claude Sonnet 4.6 --- infrastructure/terraform/mongodb.tf | 1 + infrastructure/terraform/monitoring.tf | 7 ++++++- infrastructure/terraform/variables.tf | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/infrastructure/terraform/mongodb.tf b/infrastructure/terraform/mongodb.tf index c961599..23ef90a 100644 --- a/infrastructure/terraform/mongodb.tf +++ b/infrastructure/terraform/mongodb.tf @@ -77,6 +77,7 @@ resource "kubernetes_stateful_set" "mongodb" { container { name = "mongodb" image = "mongo:8" + args = ["--wiredTigerCacheSizeGB=0.25"] env { name = "MONGO_INITDB_ROOT_USERNAME" diff --git a/infrastructure/terraform/monitoring.tf b/infrastructure/terraform/monitoring.tf index 57262dd..eebf256 100644 --- a/infrastructure/terraform/monitoring.tf +++ b/infrastructure/terraform/monitoring.tf @@ -1,9 +1,11 @@ resource "random_password" "grafana" { + count = var.enable_monitoring ? 1 : 0 length = 24 special = false } resource "helm_release" "kube_prometheus_stack" { + count = var.enable_monitoring ? 1 : 0 name = "kps" namespace = kubernetes_namespace.domains["monitoring"].metadata[0].name repository = "https://prometheus-community.github.io/helm-charts" @@ -16,7 +18,7 @@ resource "helm_release" "kube_prometheus_stack" { enabled = false } grafana = { - adminPassword = random_password.grafana.result + adminPassword = random_password.grafana[0].result ingress = { enabled = true hosts = ["grafana.homelab.local"] @@ -78,6 +80,7 @@ resource "helm_release" "kube_prometheus_stack" { } resource "helm_release" "jaeger" { + count = var.enable_monitoring ? 1 : 0 name = "jaeger" namespace = kubernetes_namespace.domains["monitoring"].metadata[0].name repository = "https://jaegertracing.github.io/helm-charts" @@ -99,6 +102,7 @@ resource "helm_release" "jaeger" { } resource "helm_release" "loki" { + count = var.enable_monitoring ? 1 : 0 name = "loki" namespace = kubernetes_namespace.domains["monitoring"].metadata[0].name repository = "https://grafana.github.io/helm-charts" @@ -175,6 +179,7 @@ resource "helm_release" "loki" { } resource "helm_release" "fluent_bit" { + count = var.enable_monitoring ? 1 : 0 name = "fluent-bit" namespace = kubernetes_namespace.domains["monitoring"].metadata[0].name repository = "https://fluent.github.io/helm-charts" diff --git a/infrastructure/terraform/variables.tf b/infrastructure/terraform/variables.tf index f7c6e1d..6b63255 100644 --- a/infrastructure/terraform/variables.tf +++ b/infrastructure/terraform/variables.tf @@ -3,3 +3,9 @@ variable "enable_gitea" { type = bool default = false } + +variable "enable_monitoring" { + description = "Deploy Prometheus, Grafana, Loki, Jaeger, and Fluent Bit. Set to false on small VMs to save ~1.5 GB RAM." + type = bool + default = true +}