Z2M Device Tracker

Prometheus metrics

The app can serve its device and network data for Prometheus to collect, for graphs in Grafana or similar tools. It's off until you set it up.

Turning it on

  1. On the app's Configuration tab, set metrics_token to a long random string, 16 characters or more.
  2. On the same tab, under Network, give port 9099/tcp a host port, for example 9099.
  3. Restart the app.

The endpoint stays off while metrics_token is empty or shorter than 16 characters, or the port isn't mapped. The app's log says so when the token is too short.

With the Docker image, set metrics_token in /data/options.json, publish the port in your compose file ("9099:9099" under ports), and restart the container.

Scrape config

Add a scrape job to Prometheus:

scrape_configs:
  - job_name: z2m_tracker
    authorization:
      credentials: <your metrics_token>
    static_configs:
      - targets: ["homeassistant.local:9099"]

Use your Home Assistant host's name or address (or the Docker host's), and the host port you mapped.

Every request must send the token, or it gets 401. The endpoint serves only /metrics and changes nothing. The data includes device names and areas, so keep the token private.

What it serves

Each active device has these gauges, with ieee, name and network labels. network is the base topic for a Zigbee2MQTT network, zha for ZHA and matter for Matter.

MetricWhat it is
z2m_tracker_device_online1 online, 0 offline. Missing when availability isn't tracked for the device.
z2m_tracker_device_linkqualityLast reported link quality (0–255).
z2m_tracker_device_linkquality_24hAverage link quality over the last 24 hours.
z2m_tracker_device_battery_percentLast reported battery level.
z2m_tracker_device_battery_days_leftEstimated days until the battery runs low. See Batteries.
z2m_tracker_device_last_seen_timestamp_secondsWhen the device last sent anything (Unix time).
z2m_tracker_device_messages_24hMessages received in the last 24 hours.
z2m_tracker_device_uptime_30d_percentShare of the last 30 days the device was online.
z2m_tracker_device_issuesOpen health issues for the device.
z2m_tracker_device_infoAlways 1. Adds type, power_source, vendor, model and area labels.

A gauge with no value, such as battery on a mains device, is left out.

And these totals:

MetricWhat it is
z2m_tracker_network_devicesDevices per network and status. The coordinator isn't counted.
z2m_tracker_network_online1 when that network is online, 0 when it's offline.
z2m_tracker_network_mesh_scoreThe network's mesh score, 0–100, as shown on Health.
z2m_tracker_issuesOpen health issues per check and severity, with check and severity labels.
z2m_tracker_alerts_paused1 while alerts are paused.
z2m_tracker_infoAlways 1, with the app version as a label.

Devices of a network the app no longer listens to are frozen and left out of every metric, including the device counts. See ZHA and Matter.