Skip to content

feat: add Prometheus exporter extension#31645

Draft
tomwilkie wants to merge 10 commits intoKoenkk:devfrom
tomwilkie:prometheus-extension
Draft

feat: add Prometheus exporter extension#31645
tomwilkie wants to merge 10 commits intoKoenkk:devfrom
tomwilkie:prometheus-extension

Conversation

@tomwilkie
Copy link
Copy Markdown

@tomwilkie tomwilkie commented Apr 8, 2026

A Prometheus exporter extension for zigbee2mqtt

This PR adds a PrometheusExporter extension that exposes a /metrics HTTP endpoint (default port 9142) for scraping by Prometheus. It is disabled by default and opt-in via prometheus_exporter.enabled in settings.

Metrics exposed:

  • zigbee2mqtt_build_info — version/commit gauge
  • zigbee2mqtt_device_info — static device metadata (model, vendor, type, power source)
  • zigbee2mqtt_device_link_quality — last known LQI per device
  • zigbee2mqtt_device_messages_received_total — Zigbee messages received per device
  • zigbee2mqtt_device_messages_failed_total — Zigbee messages that failed processing (with reason label)
  • zigbee2mqtt_mqtt_messages_published_total / _received_total — MQTT traffic counters
  • zigbee2mqtt_device_joins/leaves/announces/network_address_changes_total — device lifecycle events

Device metrics are pre-populated on startup and cleaned up when a device is removed. The HTTP server binds to an optional host setting; if omitted it listens on all interfaces.

NB I'm not trying to export values from the devices themselves - I do this with the prometheus metrics exposed by home assistant. My intention here is to have historic data on the health of zigbee mesh.

There are a ton of related projects trying to solve this issue, and they all seem to work by listening to the the MQTT events. I did not want to go this route as I'd also like get nodejs process-level metrics, and I want to eventually get much more low-level metrics about retries, failures etc, and I don't think I can do that via mqtt. Not an expert on this topic though, perhaps it is still possible?

There are also previous attempts at an extension that seems to have fizzled out. I've read them and tried to incorporate some of their ideas into this PR. In particular I like the zigbee-herdsman level metrics, and if we're open to it would like to include them in this exporter?

Fixes Koenkk/zigbee2mqtt-user-extensions#5 - I intended to put it into the zigbee2mqtt-user-extensions repo, but with the dependancy on prom-client there seemed to be no clean way to have external extensions install dependancies. I'm not a javascript/node expert, so if this is possible just let me know how.

Not to hide anything, I did use claude code to build this. But I have manually reviewed the code and tweaked it a fair bit.

@tomwilkie tomwilkie force-pushed the prometheus-extension branch from 95cb930 to ec67c30 Compare April 9, 2026 14:44
@tomwilkie tomwilkie changed the base branch from master to dev April 9, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Prometheus Support

1 participant