feat(metrics): opt-in Prometheus /metrics endpoint + textfile collector - #304
Merged
Conversation
…llector
The Prometheus exposition already existed as the `aegisbpf metrics` CLI (35+
low-cardinality families read from the pinned maps). This makes it scrape-able.
- src/metrics_server.{hpp,cpp}: a minimal opt-in HTTP/1.0 server. Off unless
AEGIS_METRICS_ADDR=<host:port>. Routes GET /metrics and GET /healthz; binds
loopback by default (bind :9635 to expose, restrict via firewall/NetworkPolicy).
No BPF/kernel dependency — the body comes from a callback — so it is unit-tested
over a real loopback socket.
- src/commands_metrics.{cpp,hpp}: refactor the builder out of `cmd_metrics` into a
shared `build_metrics_report(BpfState&, bool)` so the CLI, the textfile collector,
and the HTTP endpoint emit identical output. Add an `aegisbpf_deny_ttl_entries`
gauge (control-API denies awaiting TTL expiry).
- src/daemon.cpp: start the endpoint when AEGIS_METRICS_ADDR is set, reusing the
daemon's already-loaded state (no per-scrape reload). Reads touch only pinned
maps + files, so they run concurrently with the poll loop safely; in-process
counters (pin_heal_*) are intentionally deferred until made scrape-safe.
- packaging/systemd/aegisbpf-metrics.{service,timer}: node_exporter textfile
collector — the no-open-port alternative (atomic temp+rename write every 30s).
- tests/test_metrics_server.cpp: bind-addr parsing + loopback round-trip
(/metrics, /healthz, 404, no-callback 503, non-GET 405).
- docs/METRICS.md (+ index link), CHANGELOG.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ErenAri
force-pushed
the
feat/metrics-endpoint
branch
from
August 11, 2026 20:27
ac8c629 to
6a57a9d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes AegisBPF's Prometheus metrics scrape-able. The exposition already existed as the
aegisbpf metricsCLI (35+ low-cardinality families read from the pinned maps) — this exposes it two ways.1. Built-in HTTP endpoint (opt-in)
src/metrics_server.{hpp,cpp}— minimal HTTP/1.0 server, off unlessAEGIS_METRICS_ADDRis set. RoutesGET /metrics+GET /healthz. No BPF/kernel dependency (body from a callback), so it's unit-tested over a real loopback socket.:9635to expose and restrict with a firewall / KubernetesNetworkPolicy.2. node_exporter textfile collector (no open port)
packaging/systemd/aegisbpf-metrics.{service,timer}— a 30 s timer writes the exposition atomically (temp + rename) to${AEGIS_METRICS_TEXTFILE}for node_exporter to serve.systemctl enable --now aegisbpf-metrics.timer.Refactor + coverage
build_metrics_report(BpfState&, bool)extracted fromcmd_metricsso CLI / textfile / HTTP emit identical output.aegisbpf_deny_ttl_entriesgauge (control-API denies awaiting TTL expiry).pin_heal_*in-process counters intentionally deferred — they're written by the heartbeat thread and would be a TSan-visible race until made atomic. Noted indocs/METRICS.md.Tests / verification
tests/test_metrics_server.cpp— bind-addr parsing + loopback round-trip (/metrics,/healthz, 404, no-callback 503, non-GET 405).aegisbpf+aegisbpf_testbuild clean; MetricsServer/TtlRegistry/SocketApi = 20/20; clang-format, clang-tidy (real.clang-tidyconfig), and cppcheck all clean on changed files.Docs
docs/METRICS.md(endpoint + textfile + metric table) with index link; CHANGELOG under Unreleased.🤖 Generated with Claude Code