Skip to content

feat: add Prometheus metrics exporter endpoint (GET /metrics)#34

Open
bolausson wants to merge 2 commits into21cncstudio:mainfrom
bolausson:main
Open

feat: add Prometheus metrics exporter endpoint (GET /metrics)#34
bolausson wants to merge 2 commits into21cncstudio:mainfrom
bolausson:main

Conversation

@bolausson
Copy link

Summary

  • This is implemented with the help of an LLM!
  • Since I don't have the necessary hardware yet, I haven't been able to test the metrics for plausibility
  • Add GET /metrics endpoint exporting ~60 metrics in Prometheus text exposition format
  • Covers all sensor readings, derived values (dew point, absolute humidity, mold risk), DAC/fan control state, network status, and ESP32 system diagnostics (heap, PSRAM, chip temperature, flash sizes, FreeRTOS task count)
  • Invalid/unavailable sensors are omitted rather than zeroed, which is the correct Prometheus semantic for absent data
  • Uses chunked HTTP transfer to keep peak memory usage at ~1.5 KB
  • Flash/sketch size metrics are cached at init to avoid repeated SPI flash reads on every scrape

Files Changed

  • New: src/web/PrometheusExporter.h, src/web/PrometheusExporter.cpp — exporter implementation
  • New: test/test_prometheus_exporter/test_prometheus_exporter.cpp — 10 native unit tests
  • New: docs/prometheus/README.md — full metric reference, scrape config examples, PromQL queries
  • Modified: src/modules/NetworkManager.cpp — route registration and init
  • Modified: platformio.ini — added exporter to native test build filter
  • Modified: README.md — added Prometheus section with quick-start config

Testing

  • Firmware compiles cleanly with zero warnings (pio run -e project_aura)
  • All 35 native unit tests pass (pio test -e native_test), including 10 new tests covering sensor metric serialization, invalid sensor omission, derived metric computation, pressure trend output, and Prometheus format correctness (HELP/TYPE/value ordering)
  • On-device testing was not performed as hardware is not yet available. The endpoint follows the exact same data access patterns as the existing /api/state handler and should be validated with curl http://aura.local/metrics and promtool check metrics once hardware is available

Checklist

  • I have read CONTRIBUTING.md and agree to the CLA.
  • I tested my changes or explained why tests are not applicable.
  • I updated documentation if needed.

Export ~60 metrics in Prometheus text exposition format including all
sensor readings, derived values, DAC/fan state, network status, and
ESP32 system diagnostics (heap, PSRAM, chip temperature, flash sizes,
FreeRTOS task count). Invalid sensors are omitted rather than zeroed.
Flash metrics are cached at init to avoid repeated SPI reads.
@21cncstudio
Copy link
Owner

Thanks a lot for the contribution and for the detailed implementation.
The Prometheus /metrics work looks solid and is very much appreciated.

For now, I’m focusing on core firmware stability and release scope, so this is a bit early for the current roadmap. I’d like to revisit this in a future phase when we expand observability features.

I reviewed the changes locally and the idea is great. It’s just a timing/prioritization decision for this release cycle.

Thanks again for the effort and for putting this together.

@bolausson
Copy link
Author

That is fine.

@21cncstudio 21cncstudio added the enhancement New feature or request label Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants