diff --git a/bootstrap/edge/templates/docker-compose.yml.tftpl b/bootstrap/edge/templates/docker-compose.yml.tftpl index 73189e5..7f8bf53 100644 --- a/bootstrap/edge/templates/docker-compose.yml.tftpl +++ b/bootstrap/edge/templates/docker-compose.yml.tftpl @@ -56,9 +56,13 @@ services: - squid_logs:/var/log/squid cadvisor: - image: gcr.io/cadvisor/cadvisor:v0.49.1 + image: ghcr.io/google/cadvisor:0.55.1 restart: unless-stopped privileged: true + command: + - --docker_only=true + - --store_container_labels=false + - --whitelisted_container_labels=com.docker.compose.project,com.docker.compose.service ports: - "0.0.0.0:9101:8080/tcp" devices: diff --git a/bootstrap/platform/grafana-dashboards/homelab-overview.json b/bootstrap/platform/grafana-dashboards/homelab-overview.json index 852fa56..e1cac43 100644 --- a/bootstrap/platform/grafana-dashboards/homelab-overview.json +++ b/bootstrap/platform/grafana-dashboards/homelab-overview.json @@ -1,90 +1,127 @@ { "annotations": {"list": []}, + "description": "Host and Kubernetes metrics for the active cluster profile, Debian laptop, Orange Pi, Raspberry Pi and OCI edge. OCI edge is scraped over Tailscale. The same physical host may appear twice when it also runs a Kubernetes node.", "editable": true, "graphTooltip": 1, "id": null, "panels": [ { + "id": 1, "type": "table", "title": "Host exporter status", + "description": "A down target needs exporter, network or Tailscale repair. Kubernetes targets appear when their ServiceMonitor discovers them.", + "gridPos": {"h": 7, "w": 12, "x": 0, "y": 0}, "datasource": {"type": "prometheus", "uid": "prometheus"}, - "fieldConfig": {"defaults": {"color": {"mode": "thresholds"}, "thresholds": {"mode": "absolute", "steps": [{"color": "red", "value": null}, {"color": "green", "value": 1}]}}, "overrides": []}, - "gridPos": {"h": 5, "w": 6, "x": 0, "y": 0}, - "id": 1, - "options": {"colorMode": "value", "graphMode": "area", "justifyMode": "auto", "orientation": "auto", "reduceOptions": {"calcs": ["lastNotNull"], "fields": "", "values": false}, "textMode": "auto"}, - "targets": [{"expr": "sum(up{job=~\"oci-edge-node|oci-email-node|oci-edge-containers|rpi-node|jeannie-self-heal\"})", "refId": "A"}], - "title": "External Monitoring Targets Up", - "type": "stat" + "targets": [{"expr": "up{job=~\".*node-exporter.*|debian-host|pimox-host|rpi-node|oci-edge-node\"}", "format": "table", "instant": true, "refId": "A"}] }, { + "id": 2, "type": "table", "title": "Kubernetes node readiness", + "gridPos": {"h": 7, "w": 12, "x": 12, "y": 0}, + "datasource": {"type": "prometheus", "uid": "prometheus"}, + "targets": [{"expr": "kube_node_status_condition{condition=\"Ready\",status=\"true\"}", "format": "table", "instant": true, "refId": "A"}] + }, + { + "id": 3, "type": "timeseries", "title": "Host CPU used", + "gridPos": {"h": 8, "w": 12, "x": 0, "y": 7}, "datasource": {"type": "prometheus", "uid": "prometheus"}, "fieldConfig": {"defaults": {"unit": "percent", "min": 0, "max": 100}, "overrides": []}, - "gridPos": {"h": 8, "w": 12, "x": 6, "y": 0}, - "id": 2, - "targets": [{"expr": "100 - (avg by (instance, job) (rate(node_cpu_seconds_total{job=~\"oci-edge-node|oci-email-node|rpi-node\",mode=\"idle\"}[5m])) * 100)", "legendFormat": "{{job}} {{instance}}", "refId": "A"}], - "title": "VM CPU Utilization", - "type": "timeseries" + "targets": [{"expr": "(100 * (1 - avg by (job, instance) (rate(node_cpu_seconds_total{job=~\".*node-exporter.*|debian-host|pimox-host|rpi-node|oci-edge-node\",mode=\"idle\"}[5m])))) * on (job, instance) group_left(nodename) node_uname_info", "legendFormat": "{{nodename}} · {{job}}", "refId": "A"}] }, { + "id": 4, "type": "timeseries", "title": "Host memory used", + "gridPos": {"h": 8, "w": 12, "x": 12, "y": 7}, + "datasource": {"type": "prometheus", "uid": "prometheus"}, + "fieldConfig": {"defaults": {"unit": "percent", "min": 0, "max": 100}, "overrides": []}, + "targets": [{"expr": "(100 * (1 - node_memory_MemAvailable_bytes{job=~\".*node-exporter.*|debian-host|pimox-host|rpi-node|oci-edge-node\"} / node_memory_MemTotal_bytes)) * on (job, instance) group_left(nodename) node_uname_info", "legendFormat": "{{nodename}} · {{job}}", "refId": "A"}] + }, + { + "id": 5, "type": "timeseries", "title": "Filesystem used", + "description": "Physical and persistent filesystems; temporary and container mounts are excluded.", + "gridPos": {"h": 8, "w": 12, "x": 0, "y": 15}, + "datasource": {"type": "prometheus", "uid": "prometheus"}, + "fieldConfig": {"defaults": {"unit": "percent", "min": 0, "max": 100}, "overrides": []}, + "targets": [{"expr": "(100 * (1 - node_filesystem_avail_bytes{job=~\".*node-exporter.*|debian-host|pimox-host|rpi-node|oci-edge-node\",fstype!~\"tmpfs|devtmpfs|overlay|squashfs|nsfs|ramfs\",mountpoint!~\"/var/lib/(kubelet|rancher|docker|containerd)/.*\"} / node_filesystem_size_bytes{fstype!~\"tmpfs|devtmpfs|overlay|squashfs|nsfs|ramfs\"})) * on (job, instance) group_left(nodename) node_uname_info", "legendFormat": "{{nodename}} {{mountpoint}} · {{job}}", "refId": "A"}] + }, + { + "id": 6, "type": "timeseries", "title": "Filesystem available", + "gridPos": {"h": 8, "w": 12, "x": 12, "y": 15}, "datasource": {"type": "prometheus", "uid": "prometheus"}, "fieldConfig": {"defaults": {"unit": "bytes", "min": 0}, "overrides": []}, - "gridPos": {"h": 8, "w": 12, "x": 0, "y": 8}, - "id": 3, - "targets": [{"expr": "(1 - node_memory_MemAvailable_bytes{job=~\"oci-edge-node|oci-email-node|rpi-node\"} / node_memory_MemTotal_bytes{job=~\"oci-edge-node|oci-email-node|rpi-node\"}) * node_memory_MemTotal_bytes{job=~\"oci-edge-node|oci-email-node|rpi-node\"}", "legendFormat": "{{job}} {{instance}}", "refId": "A"}], - "title": "VM Memory Used", - "type": "timeseries" + "targets": [{"expr": "node_filesystem_avail_bytes{job=~\".*node-exporter.*|debian-host|pimox-host|rpi-node|oci-edge-node\",fstype!~\"tmpfs|devtmpfs|overlay|squashfs|nsfs|ramfs\",mountpoint!~\"/var/lib/(kubelet|rancher|docker|containerd)/.*\"} * on (job, instance) group_left(nodename) node_uname_info", "legendFormat": "{{nodename}} {{mountpoint}} · {{job}}", "refId": "A"}] }, { + "id": 7, "type": "timeseries", "title": "Network receive", + "gridPos": {"h": 8, "w": 12, "x": 0, "y": 23}, "datasource": {"type": "prometheus", "uid": "prometheus"}, - "fieldConfig": {"defaults": {"unit": "percent", "min": 0, "max": 100}, "overrides": []}, - "gridPos": {"h": 8, "w": 12, "x": 12, "y": 8}, - "id": 4, - "targets": [{"expr": "100 * (1 - node_filesystem_avail_bytes{job=~\"oci-edge-node|oci-email-node|rpi-node\",fstype!~\"tmpfs|overlay|squashfs\"} / node_filesystem_size_bytes{job=~\"oci-edge-node|oci-email-node|rpi-node\",fstype!~\"tmpfs|overlay|squashfs\"})", "legendFormat": "{{job}} {{instance}} {{mountpoint}}", "refId": "A"}], - "title": "VM Filesystem Used", - "type": "timeseries" + "fieldConfig": {"defaults": {"unit": "Bps", "min": 0}, "overrides": []}, + "targets": [{"expr": "rate(node_network_receive_bytes_total{job=~\".*node-exporter.*|debian-host|pimox-host|rpi-node|oci-edge-node\",device!~\"lo|veth.*|cali.*|docker.*|br-.*|tunl.*|vxlan.*|flannel.*\"}[5m]) * on (job, instance) group_left(nodename) node_uname_info", "legendFormat": "{{nodename}} {{device}} · {{job}}", "refId": "A"}] }, { + "id": 8, "type": "timeseries", "title": "Network transmit", + "gridPos": {"h": 8, "w": 12, "x": 12, "y": 23}, + "datasource": {"type": "prometheus", "uid": "prometheus"}, + "fieldConfig": {"defaults": {"unit": "Bps", "min": 0}, "overrides": []}, + "targets": [{"expr": "rate(node_network_transmit_bytes_total{job=~\".*node-exporter.*|debian-host|pimox-host|rpi-node|oci-edge-node\",device!~\"lo|veth.*|cali.*|docker.*|br-.*|tunl.*|vxlan.*|flannel.*\"}[5m]) * on (job, instance) group_left(nodename) node_uname_info", "legendFormat": "{{nodename}} {{device}} · {{job}}", "refId": "A"}] + }, + { + "id": 9, "type": "timeseries", "title": "Kubernetes container CPU", + "gridPos": {"h": 8, "w": 12, "x": 0, "y": 31}, "datasource": {"type": "prometheus", "uid": "prometheus"}, "fieldConfig": {"defaults": {"unit": "cores", "min": 0}, "overrides": []}, - "gridPos": {"h": 8, "w": 12, "x": 0, "y": 16}, - "id": 5, - "targets": [{"expr": "sum by (name) (rate(container_cpu_usage_seconds_total{container!=\"\",image!=\"\"}[5m]))", "legendFormat": "{{name}}", "refId": "A"}], - "title": "Kubernetes Container CPU", - "type": "timeseries" - }, - { - "datasource": {"type": "prometheus", "uid": "prometheus"}, - "fieldConfig": {"defaults": {}, "overrides": []}, - "gridPos": {"h": 8, "w": 12, "x": 12, "y": 16}, - "id": 6, - "targets": [{"expr": "ALERTS{alertstate=\"firing\"}", "legendFormat": "{{alertname}} {{instance}}", "refId": "A"}], - "title": "Firing Alerts", - "type": "table" - }, - { - "datasource": {"type": "prometheus", "uid": "prometheus"}, - "fieldConfig": {"defaults": {}, "overrides": []}, - "gridPos": {"h": 8, "w": 12, "x": 0, "y": 24}, - "id": 7, - "targets": [{"expr": "up{job=~\"oci-edge-node|oci-email-node|oci-edge-containers|rpi-node|jeannie-self-heal|traefik|jeannie-api\"}", "format": "table", "instant": true, "refId": "A"}], - "title": "Service and Exporter Status", - "type": "table" + "targets": [{"expr": "sum by (namespace, pod, container) (rate(container_cpu_usage_seconds_total{job=\"kubelet\",metrics_path=\"/metrics/cadvisor\",container!=\"\",container!=\"POD\",image!=\"\"}[5m]))", "legendFormat": "{{namespace}}/{{pod}} · {{container}}", "refId": "A"}] }, { + "id": 10, "type": "timeseries", "title": "Kubernetes container memory", + "gridPos": {"h": 8, "w": 12, "x": 12, "y": 31}, "datasource": {"type": "prometheus", "uid": "prometheus"}, "fieldConfig": {"defaults": {"unit": "bytes", "min": 0}, "overrides": []}, - "gridPos": {"h": 8, "w": 12, "x": 12, "y": 24}, - "id": 8, - "targets": [{"expr": "sum by (name) (container_memory_working_set_bytes{container!=\"\",image!=\"\"})", "legendFormat": "{{name}}", "refId": "A"}], - "title": "Kubernetes Container Memory", - "type": "timeseries" + "targets": [{"expr": "sum by (namespace, pod, container) (container_memory_working_set_bytes{job=\"kubelet\",metrics_path=\"/metrics/cadvisor\",container!=\"\",container!=\"POD\",image!=\"\"})", "legendFormat": "{{namespace}}/{{pod}} · {{container}}", "refId": "A"}] + }, + { + "id": 11, "type": "timeseries", "title": "Docker Compose CPU by service", + "gridPos": {"h": 8, "w": 12, "x": 0, "y": 39}, + "datasource": {"type": "prometheus", "uid": "prometheus"}, + "fieldConfig": {"defaults": {"unit": "cores", "min": 0}, "overrides": []}, + "targets": [{"expr": "sum by (job, instance, container_label_com_docker_compose_project, container_label_com_docker_compose_service) (rate(container_cpu_usage_seconds_total{job=~\"debian-compose|rpi-compose|oci-edge-containers\",container_label_com_docker_compose_project!=\"\",image!=\"\"}[5m]))", "legendFormat": "{{job}} · {{container_label_com_docker_compose_project}}/{{container_label_com_docker_compose_service}}", "refId": "A"}] + }, + { + "id": 12, "type": "timeseries", "title": "Docker Compose memory by service", + "gridPos": {"h": 8, "w": 12, "x": 12, "y": 39}, + "datasource": {"type": "prometheus", "uid": "prometheus"}, + "fieldConfig": {"defaults": {"unit": "bytes", "min": 0}, "overrides": []}, + "targets": [{"expr": "sum by (job, instance, container_label_com_docker_compose_project, container_label_com_docker_compose_service) (container_memory_working_set_bytes{job=~\"debian-compose|rpi-compose|oci-edge-containers\",container_label_com_docker_compose_project!=\"\",image!=\"\"})", "legendFormat": "{{job}} · {{container_label_com_docker_compose_project}}/{{container_label_com_docker_compose_service}}", "refId": "A"}] + }, + { + "id": 13, "type": "timeseries", "title": "Docker Compose network receive", + "gridPos": {"h": 8, "w": 12, "x": 0, "y": 47}, + "datasource": {"type": "prometheus", "uid": "prometheus"}, + "fieldConfig": {"defaults": {"unit": "Bps", "min": 0}, "overrides": []}, + "targets": [{"expr": "sum by (job, instance, container_label_com_docker_compose_project, container_label_com_docker_compose_service) (rate(container_network_receive_bytes_total{job=~\"debian-compose|rpi-compose|oci-edge-containers\",container_label_com_docker_compose_project!=\"\"}[5m]))", "legendFormat": "{{job}} · {{container_label_com_docker_compose_project}}/{{container_label_com_docker_compose_service}}", "refId": "A"}] + }, + { + "id": 14, "type": "timeseries", "title": "Docker Compose network transmit", + "gridPos": {"h": 8, "w": 12, "x": 12, "y": 47}, + "datasource": {"type": "prometheus", "uid": "prometheus"}, + "fieldConfig": {"defaults": {"unit": "Bps", "min": 0}, "overrides": []}, + "targets": [{"expr": "sum by (job, instance, container_label_com_docker_compose_project, container_label_com_docker_compose_service) (rate(container_network_transmit_bytes_total{job=~\"debian-compose|rpi-compose|oci-edge-containers\",container_label_com_docker_compose_project!=\"\"}[5m]))", "legendFormat": "{{job}} · {{container_label_com_docker_compose_project}}/{{container_label_com_docker_compose_service}}", "refId": "A"}] + }, + { + "id": 15, "type": "table", "title": "Docker Compose exporter status", + "gridPos": {"h": 7, "w": 12, "x": 0, "y": 55}, + "datasource": {"type": "prometheus", "uid": "prometheus"}, + "targets": [{"expr": "up{job=~\"debian-compose|rpi-compose|oci-edge-containers\"}", "format": "table", "instant": true, "refId": "A"}] + }, + { + "id": 16, "type": "table", "title": "Firing alerts", + "gridPos": {"h": 7, "w": 12, "x": 12, "y": 55}, + "datasource": {"type": "prometheus", "uid": "prometheus"}, + "targets": [{"expr": "ALERTS{alertstate=\"firing\"}", "format": "table", "instant": true, "refId": "A"}] } ], "refresh": "30s", "schemaVersion": 39, - "tags": ["homelab", "overview", "oci"], + "tags": ["homelab", "overview", "kubernetes", "oci"], "templating": {"list": []}, "time": {"from": "now-6h", "to": "now"}, - "description": "Unified homelab view for OCI VMs, Raspberry Pi, Kubernetes containers, exporters, and Jeannie alerts. OCI-native VM alarms notify through the managed Notifications topic.", "title": "Homelab Overview", "uid": "homelab-overview", - "version": 1 + "version": 2 } diff --git a/bootstrap/platform/main.tf b/bootstrap/platform/main.tf index 14d95e2..220ede7 100644 --- a/bootstrap/platform/main.tf +++ b/bootstrap/platform/main.tf @@ -2098,11 +2098,27 @@ resource "helm_release" "prometheus_stack" { nodeSelector = local.prometheus_stack_node_selector retention = var.observability.prometheus.retention additionalScrapeConfigs = yamlencode(concat([ + { + job_name = "debian-host" + static_configs = [{ targets = [var.debian_host_metrics_target], labels = { host_group = "debian-laptop" } }] + }, + { + job_name = "pimox-host" + static_configs = [{ targets = [var.pimox_host_metrics_target], labels = { host_group = "orange-pi-hypervisor" } }] + }, + { + job_name = "debian-compose" + static_configs = [{ targets = [var.debian_compose_metrics_target], labels = { host_group = "debian-laptop" } }] + }, + { + job_name = "rpi-compose" + static_configs = [{ targets = [var.rpi_compose_metrics_target], labels = { host_group = "edge-dns-worker" } }] + }, { job_name = "rpi-node" static_configs = [ { - targets = ["192.168.100.89:9100"] + targets = [var.rpi_host_metrics_target] labels = { host_group = "edge-dns-worker" } diff --git a/bootstrap/platform/variables.tf b/bootstrap/platform/variables.tf index 492c81d..2bfba09 100644 --- a/bootstrap/platform/variables.tf +++ b/bootstrap/platform/variables.tf @@ -260,6 +260,36 @@ variable "jeannie_api_metrics_target" { default = "api.lab2025.duckdns.org:443" } +variable "debian_host_metrics_target" { + description = "LAN host:port for the Debian laptop node exporter." + type = string + default = "192.168.100.73:9100" +} + +variable "pimox_host_metrics_target" { + description = "LAN host:port for the Orange Pi hypervisor node exporter." + type = string + default = "192.168.100.80:9100" +} + +variable "rpi_host_metrics_target" { + description = "LAN host:port for the Raspberry Pi node exporter." + type = string + default = "192.168.100.89:9100" +} + +variable "debian_compose_metrics_target" { + description = "LAN host:port for the Debian Docker Compose cAdvisor collector." + type = string + default = "192.168.100.73:9101" +} + +variable "rpi_compose_metrics_target" { + description = "LAN host:port for the Raspberry Pi Docker Compose cAdvisor collector." + type = string + default = "192.168.100.89:9101" +} + variable "oci_edge_metrics_target" { description = "Optional private/restricted host:port for the OCI edge node exporter." type = string diff --git a/docs/app-ops.md b/docs/app-ops.md index fa8d6ce..5bd1c98 100644 --- a/docs/app-ops.md +++ b/docs/app-ops.md @@ -1,5 +1,42 @@ # Application Operations +## Homelab Overview dashboard + +The `Homelab Overview` dashboard (`homelab-overview`) shows host CPU, memory, +filesystems and network interfaces, plus Kubernetes node readiness and +container usage. It uses Kubernetes node-exporter discovery for whichever +cluster profile is active and separate `debian-host`, `pimox-host`, `rpi-node` +and `oci-edge-node` scrape jobs for the laptop, Orange Pi host, Raspberry Pi +and OCI edge. A physical host that is also a Kubernetes node can appear twice; +the job in each legend identifies the source. + +`./jeannie platform monitoring` installs or starts the Debian package +`prometheus-node-exporter` on the laptop and Orange Pi through SSH when needed, +then deploys the scrape jobs and dashboard. A setup failure is reported and the +corresponding target remains down. Set `LAB_MONITORING_MANAGE_HOST_EXPORTERS=false` +to manage those services separately. Port 9100 must be reachable from cluster +pods. The RPi exporter is managed by the RPi services deployment. + +The same command runs a dedicated cAdvisor Compose service on Debian and RPi, +on LAN port 9101, to collect Docker Compose CPU, memory and network metrics by +project and service. Its Docker root mount comes from Docker's live configuration. +The collector needs privileged host and Docker socket access; its exported +container labels are limited to the Compose project and service. Existing +application stacks are not restarted. `LAB_MONITORING_MANAGE_HOST_EXPORTERS=false` +also skips these collectors. The OCI edge stack has its own collector; run +`./jeannie edge` to deploy its updated image and labels. Prometheus +scrapes OCI cAdvisor over Tailscale on TCP/9101; override its endpoint with +`LAB_OCI_EDGE_TAILSCALE_CONTAINER_METRICS_TARGET` when necessary. + +The OCI edge job uses `hosts.oci_edge.tailscale_ip:9100` from `homelab.yml`; +`LAB_OCI_EDGE_TAILSCALE_METRICS_TARGET` overrides it. Prometheus needs a working +route from its node/pod to the tailnet, an authorized Tailscale source, and +access through the edge host firewall. The repository's tailnet policy grants +`tag:homelab-control-plane` and Debian access to ports 9100 and 9101; apply the policy +and tag/join the relevant nodes separately. Email VM monitoring is not part of +this dashboard. A down exporter is shown in the status table, while a target +that was never configured is absent. + ## Profile-aware application delivery Run app operations with the intended profile and its pinned kubeconfig. The diff --git a/docs/templates/app-ops.md.tmpl b/docs/templates/app-ops.md.tmpl index f87f464..1a841b9 100644 --- a/docs/templates/app-ops.md.tmpl +++ b/docs/templates/app-ops.md.tmpl @@ -1,5 +1,42 @@ # Application Operations +## Homelab Overview dashboard + +The `Homelab Overview` dashboard (`homelab-overview`) shows host CPU, memory, +filesystems and network interfaces, plus Kubernetes node readiness and +container usage. It uses Kubernetes node-exporter discovery for whichever +cluster profile is active and separate `debian-host`, `pimox-host`, `rpi-node` +and `oci-edge-node` scrape jobs for the laptop, Orange Pi host, Raspberry Pi +and OCI edge. A physical host that is also a Kubernetes node can appear twice; +the job in each legend identifies the source. + +`./{{ main_script }} platform monitoring` installs or starts the Debian package +`prometheus-node-exporter` on the laptop and Orange Pi through SSH when needed, +then deploys the scrape jobs and dashboard. A setup failure is reported and the +corresponding target remains down. Set `LAB_MONITORING_MANAGE_HOST_EXPORTERS=false` +to manage those services separately. Port 9100 must be reachable from cluster +pods. The RPi exporter is managed by the RPi services deployment. + +The same command runs a dedicated cAdvisor Compose service on Debian and RPi, +on LAN port 9101, to collect Docker Compose CPU, memory and network metrics by +project and service. Its Docker root mount comes from Docker's live configuration. +The collector needs privileged host and Docker socket access; its exported +container labels are limited to the Compose project and service. Existing +application stacks are not restarted. `LAB_MONITORING_MANAGE_HOST_EXPORTERS=false` +also skips these collectors. The OCI edge stack has its own collector; run +`./{{ main_script }} edge` to deploy its updated image and labels. Prometheus +scrapes OCI cAdvisor over Tailscale on TCP/9101; override its endpoint with +`LAB_OCI_EDGE_TAILSCALE_CONTAINER_METRICS_TARGET` when necessary. + +The OCI edge job uses `hosts.oci_edge.tailscale_ip:9100` from `homelab.yml`; +`LAB_OCI_EDGE_TAILSCALE_METRICS_TARGET` overrides it. Prometheus needs a working +route from its node/pod to the tailnet, an authorized Tailscale source, and +access through the edge host firewall. The repository's tailnet policy grants +`tag:homelab-control-plane` and Debian access to ports 9100 and 9101; apply the policy +and tag/join the relevant nodes separately. Email VM monitoring is not part of +this dashboard. A down exporter is shown in the status table, while a target +that was never configured is absent. + ## Profile-aware application delivery Run app operations with the intended profile and its pinned kubeconfig. The diff --git a/infra/tailscale/tailnet-policy.hujson b/infra/tailscale/tailnet-policy.hujson index 1a0a804..bb43ce0 100644 --- a/infra/tailscale/tailnet-policy.hujson +++ b/infra/tailscale/tailnet-policy.hujson @@ -13,7 +13,7 @@ "hosts": { "debian": "100.85.138.30", "rpi4": "100.77.80.72", - "oci-edge": "100.118.255.19", + "oci-edge": "100.122.188.79", "traefik-lan": "192.168.100.240", }, @@ -37,6 +37,13 @@ ], }, + // Prometheus reaches the OCI edge host and container exporters over the tailnet. + { + "action": "accept", + "src": ["tag:homelab-control-plane", "debian"], + "dst": ["oci-edge:9100,9101"], + }, + // Homelab members can reach normal operational surfaces. { "action": "accept", diff --git a/lib/jeannie/env.sh b/lib/jeannie/env.sh index eed5320..59038d8 100644 --- a/lib/jeannie/env.sh +++ b/lib/jeannie/env.sh @@ -297,8 +297,13 @@ export_homelab_inventory_tf_vars() { export_if_unset TF_VAR_additional_server_names "${LAB_ADDITIONAL_SERVER_NAMES_JSON:-}" export_if_unset TF_VAR_jeannie_api_metrics_target "${LAB_JEANNIE_API_METRICS_TARGET:-api.${LAB_DOMAIN:-lab2025.duckdns.org}:443}" export_if_unset TF_VAR_jeannie_api_metrics_token "${JEANNIE_SERVER_TOKEN:-${JEANNIE_REMOTE_TOKEN:-}}" - export_if_unset TF_VAR_oci_edge_metrics_target "${LAB_OCI_EDGE_METRICS_TARGET:-}" - export_if_unset TF_VAR_oci_edge_container_metrics_target "${LAB_OCI_EDGE_CONTAINER_METRICS_TARGET:-}" + export_if_unset TF_VAR_debian_host_metrics_target "${LAB_DEBIAN_LAN_IP:-192.168.100.73}:9100" + export_if_unset TF_VAR_pimox_host_metrics_target "${LAB_PIMOX_HOST:-192.168.100.80}:9100" + export_if_unset TF_VAR_rpi_host_metrics_target "${LAB_RPI_HOST:-192.168.100.89}:9100" + export_if_unset TF_VAR_debian_compose_metrics_target "${LAB_DEBIAN_LAN_IP:-192.168.100.73}:9101" + export_if_unset TF_VAR_rpi_compose_metrics_target "${LAB_RPI_HOST:-192.168.100.89}:9101" + export_if_unset TF_VAR_oci_edge_metrics_target "${LAB_OCI_EDGE_TAILSCALE_METRICS_TARGET:-${LAB_EDGE_TAILSCALE_IP:-100.122.188.79}:9100}" + export_if_unset TF_VAR_oci_edge_container_metrics_target "${LAB_OCI_EDGE_TAILSCALE_CONTAINER_METRICS_TARGET:-${LAB_EDGE_TAILSCALE_IP:-100.122.188.79}:9101}" export_if_unset TF_VAR_oci_email_metrics_target "${LAB_OCI_EMAIL_METRICS_TARGET:-}" export_if_unset TF_VAR_backend_host "${LAB_TRAEFIK_LB_IP:-}" export_if_unset TF_VAR_gitea_backend_host "${LAB_GITEA_BACKEND_HOST:-${LAB_DEBIAN_TAILSCALE_IP:-}}" diff --git a/lib/jeannie/pipeline.sh b/lib/jeannie/pipeline.sh index 0cd99e2..e50d61f 100644 --- a/lib/jeannie/pipeline.sh +++ b/lib/jeannie/pipeline.sh @@ -8113,13 +8113,40 @@ platform_apply() { # values before rendering the monitoring scrape configuration. if declare -F oci_foundation_load_config >/dev/null 2>&1; then oci_foundation_load_config - unset TF_VAR_oci_edge_metrics_target TF_VAR_oci_email_metrics_target + unset TF_VAR_oci_edge_metrics_target TF_VAR_oci_edge_container_metrics_target TF_VAR_oci_email_metrics_target export_homelab_inventory_tf_vars fi local component="${1:-all}" local -a targets=() + if [[ "${component}" == "all" || "${component}" == "monitoring" ]]; then + cluster_runtime_require || return 1 + cluster_context_require || return 1 + if truthy "${LAB_MONITORING_MANAGE_HOST_EXPORTERS:-true}"; then + echo "Preparing node exporters on Debian and the Orange Pi host..." + if ! bash "${REPO_ROOT}/scripts/monitoring-host-exporter.sh"; then + echo "Debian node exporter setup failed; its monitoring target may be down." >&2 + fi + if ! ssh -T -i "${LAB_PIMOX_SSH_KEY_PATH:-${HOME}/.ssh/id_ed25519}" \ + -o BatchMode=yes -o IdentitiesOnly=yes -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new \ + "${LAB_PIMOX_USER:-jv}@${LAB_PIMOX_HOST:-192.168.100.80}" \ + 'bash -s' <"${REPO_ROOT}/scripts/monitoring-host-exporter.sh"; then + echo "Orange Pi node exporter setup failed; its monitoring target may be down." >&2 + fi + if ! bash "${REPO_ROOT}/scripts/monitoring-compose-exporter.sh" "${LAB_DEBIAN_LAN_IP:-192.168.100.73}"; then + echo "Debian Docker Compose metrics setup failed; its monitoring target may be down." >&2 + fi + local rpi_metrics_ip="${LAB_RPI_HOST:-192.168.100.89}" + if [[ ! "${rpi_metrics_ip}" =~ ^[0-9.]+$ ]] || ! ssh -T -i "${LAB_RPI_SSH_KEY_PATH:-${LAB_RASPBERRY_SSH_KEY_PATH:-${HOME}/.ssh/id_ed25519}}" \ + -o BatchMode=yes -o IdentitiesOnly=yes -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new \ + "${LAB_RPI_USER:-jv}@${rpi_metrics_ip}" \ + "bash -s -- '${rpi_metrics_ip}'" <"${REPO_ROOT}/scripts/monitoring-compose-exporter.sh"; then + echo "RPi Docker Compose metrics setup failed; its monitoring target may be down." >&2 + fi + fi + fi + case "${component}" in all) ;; diff --git a/scripts/monitoring-compose-exporter.sh b/scripts/monitoring-compose-exporter.sh new file mode 100644 index 0000000..ba292a5 --- /dev/null +++ b/scripts/monitoring-compose-exporter.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# Run one cAdvisor collector for Docker Compose stacks on this host. +set -euo pipefail +bind_ip="${1:?LAN IP for the metrics listener is required}" +if [[ ! "${bind_ip}" =~ ^[0-9.]+$ ]]; then + echo "Expected an IPv4 LAN address for cAdvisor." >&2 + exit 1 +fi +sudo -n docker info >/dev/null +sudo -n docker compose version >/dev/null +docker_root="$(sudo -n docker info --format '{{.DockerRootDir}}')" +if [[ "${docker_root}" != /* ]] || ! sudo -n test -d "${docker_root}"; then + echo "Docker root directory is not available: ${docker_root}" >&2 + exit 1 +fi +install_dir=/opt/homelab-monitoring +sudo -n install -d -m 0755 "${install_dir}" +sudo -n tee "${install_dir}/docker-compose.yml" >/dev/null <<'COMPOSE' +services: + cadvisor: + image: ghcr.io/google/cadvisor:0.55.1 + container_name: homelab-compose-cadvisor + restart: unless-stopped + privileged: true + command: + - --docker_only=true + - --store_container_labels=false + - --whitelisted_container_labels=com.docker.compose.project,com.docker.compose.service + ports: + - "${CADVISOR_BIND_IP}:9101:8080" + devices: + - /dev/kmsg:/dev/kmsg + volumes: + - /:/rootfs:ro + - /var/run:/var/run:rw + - /sys:/sys:ro + - ${CADVISOR_DOCKER_ROOT}:${CADVISOR_DOCKER_ROOT}:ro + - /dev/disk:/dev/disk:ro +COMPOSE +sudo -n env CADVISOR_BIND_IP="${bind_ip}" CADVISOR_DOCKER_ROOT="${docker_root}" \ + docker compose -p homelab-monitoring -f "${install_dir}/docker-compose.yml" up -d +echo "Docker Compose metrics collector requested at ${bind_ip}:9101." diff --git a/scripts/monitoring-host-exporter.sh b/scripts/monitoring-host-exporter.sh new file mode 100644 index 0000000..e3cc639 --- /dev/null +++ b/scripts/monitoring-host-exporter.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# Install the distribution node exporter on a monitored Debian-family host. +set -euo pipefail + +if curl --max-time 5 -fsS http://127.0.0.1:9100/metrics 2>/dev/null | + grep -F 'node_exporter_build_info' >/dev/null; then + echo "Node exporter is already responding on TCP/9100." + exit 0 +fi + +if ss -ltnH 'sport = :9100' | grep . >/dev/null; then + echo "TCP/9100 is in use but is not a responding node exporter." >&2 + exit 1 +fi + +if ! dpkg-query -W -f='${Status}' prometheus-node-exporter 2>/dev/null | + grep -Fx 'install ok installed' >/dev/null; then + sudo -n apt-get update + sudo -n env DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends prometheus-node-exporter +fi +sudo -n systemctl enable --now prometheus-node-exporter +curl --max-time 10 -fsS http://127.0.0.1:9100/metrics | + grep -F 'node_exporter_build_info' >/dev/null +echo "Node exporter is responding on TCP/9100."