feat(infra): gate observability stack behind var.enable_monitoring (#38)

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 <guga@Goncalos-MacBook-Pro.local>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Gonçalo Rodrigues 2026-06-26 17:44:14 +01:00 committed by GitHub
parent 292b2f46f0
commit 8436295bbc
3 changed files with 13 additions and 1 deletions

View File

@ -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"

View File

@ -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"

View File

@ -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
}