fix: host metrics come from a collector in the host's network, so network traffic is the host's

Merged
HA
10d ago
+141-37

Summary

Found while working on #317. The collector's host_metrics network scraper reported the collector container's own eth0 and lo, not the host's: gopsutil reads /proc/net/dev, and that always shows the reading process's network namespace (net_linux.go). In prod, system_network_io_bytes_total{device="eth0"} said 30.7 KB/s in while the host's real eth0 moved about 300 B/s, and the host's NIC is also called eth0.

Changes

A second collector, host-metrics, runs only the host_metrics receiver with network_mode: host and sends to the main collector on 127.0.0.1:4317. It opens no ports: internal metrics are off and it runs no extensions. The main collector drops the receiver and the host mounts. The System row gets "Network I/O" (without lo and veth*) and "Disk Space Used", the deploy restarts host-metrics when its config changes, and the system diagram shows it.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • CI/CD or tooling changes

Test Plan

  • Backend unit tests pass (cd backend && uv run pytest tests/unit)
  • Frontend unit tests pass (cd frontend && npm run test)
  • Backend E2E tests pass (docker compose exec -T backend sh -c 'uv sync --group test --no-dev --frozen --no-install-project --no-build && pytest tests/e2e')
  • Frontend E2E tests pass (cd frontend && npm run test:e2e)
  • API spec and client regenerated if routes or schemas changed (./deploy.sh openapi, then ./deploy.sh types), never edited by hand
  • Manual testing performed

Validation: locally the agent reported the host's enp1s0f0, wlp2s0, docker0 and bridge, opened no port and used 57 MiB. Both configs pass otelcol validate on 0.163.1, compose config passes, and the disk query gives 40.1% on prod against df's 41%.

Checklist

  • My code follows the project's style guidelines
  • I have run pre-commit run --all-files and all checks pass
  • I have added tests that prove my fix/feature works
  • I have updated documentation if needed
  • My changes don't introduce new warnings

Summary by cubic

Fixes host metrics so network traffic reflects the host's interfaces instead of the collector container's: gopsutil reads /proc/net/dev, which shows the reading process's network namespace. A new host-metrics collector runs the host_metrics receiver with network_mode: host in the host's network namespace and forwards to the main collector on 127.0.0.1:4317.

  • The main collector drops the host_metrics receiver and the /proc and /sys mounts it used for it.
  • Grafana gains "Network I/O" (excluding lo and veth* interfaces) and "Disk Space Used" panels.
  • The deploy restarts host-metrics when its config changes; docs and the system diagram are updated.