feat: add Prometheus exporter extension#31645
Draft
tomwilkie wants to merge 10 commits intoKoenkk:devfrom
Draft
Conversation
…tyRemoved, host start
95cb930 to
ec67c30
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.
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.enabledin settings.Metrics exposed:
zigbee2mqtt_build_info— version/commit gaugezigbee2mqtt_device_info— static device metadata (model, vendor, type, power source)zigbee2mqtt_device_link_quality— last known LQI per devicezigbee2mqtt_device_messages_received_total— Zigbee messages received per devicezigbee2mqtt_device_messages_failed_total— Zigbee messages that failed processing (with reason label)zigbee2mqtt_mqtt_messages_published_total/_received_total— MQTT traffic counterszigbee2mqtt_device_joins/leaves/announces/network_address_changes_total— device lifecycle eventsDevice 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.