feat: Prometheus /metrics endpoint (ENABLE_METRICS) #4
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/prometheus-metrics"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adds a Prometheus-compatible
/metricsendpoint -- the machine-readable signal stock acng lacks (it has only the HTML report page and log parsing), which is what kept the InRelease-corruption incidents invisible until apt tripped over them.Exposed counters:
Build-guarded. Everything is behind the CMake option
ENABLE_METRICS(default on), which sets#cmakedefine HAVE_PROMETHEUS. With-DENABLE_METRICS=offnone of it compiles and the binary matches stock acng -- same pattern asUSE_SSL/HAVE_CHECKSUM. No new libraries; the text exposition is hand-rolled insrc/metrics.{h,cc}.Integration points:
aclogger.cctransfer(), into dedicated lock-free atomics -- the existingtotalIn/totalOutareexchange(0)-reset by the report page and can't back a monotonic counter.fileitem.ccDlFinish/DlSetError, guarded to count only the real state transition (no double-count on repeat calls).style.css, so a scraper needs no admin password. It exposes only aggregate counters, never cache contents.Verified: the module compiles clean under
-Wall -Wextraand emits valid exposition format (checked standalone); the CI image build + smoke test now also scrapes/metricsand asserts theacng_downloads_totalTYPE line.Next (noted in FORK.md):
acng_downloads_truncated_total-- fetches ending with fewer bytes than the declaredContent-Length, the range-splice/abort precursor that started this whole investigation. Deferred to a follow-up because it needs careful placement in the download path.🤖 Generated with Claude Code
Stock acng exposes no machine-readable metrics -- only the HTML report page and after-the-fact log parsing -- which is what left the InRelease-corruption incidents invisible until apt tripped over them. Adds an unauthenticated /metrics endpoint (Prometheus text exposition) with: acng_bytes_fetched_total (upstream -> acng) acng_bytes_served_total (acng -> clients) acng_downloads_total{result=...} (complete | error) The whole feature is gated behind the CMake option ENABLE_METRICS (default on) -> #cmakedefine HAVE_PROMETHEUS; with it off, none of it compiles and the binary matches stock acng. No new libraries -- the exposition format is hand-rolled in src/metrics.{h,cc}. Counters are dedicated lock-free atomics: the existing totalIn/totalOut are exchange(0)-reset by the report page and can't back a monotonic counter. Increment points: aclogger transfer() for bytes, fileitem DlFinish/DlSetError for the download outcome (guarded to count only the real state transition). The endpoint is an unauthenticated maintenance work type, dispatched like style.css so a scraper needs no admin password; it exposes only aggregate counters, never cache contents. CI smoke test now scrapes /metrics too. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>