kpetremann / mqtt-exporter

Simple generic MQTT Prometheus exporter for IoT working out of the box
https://hub.docker.com/r/kpetrem/mqtt-exporter
MIT License
103 stars 29 forks source link

ZIGBEE2MQTT_AVAILABILITY not working #32

Closed onedr0p closed 2 years ago

onedr0p commented 2 years ago

Hi 👋🏼

I deployed this and I can see metrics coming thru but it seems like ZIGBEE2MQTT_AVAILABILITY=True is not working. I actually still see the _state metrics.

# HELP zigbee2mqtt_state metric generated from MQTT message.
# TYPE zigbee2mqtt_state gauge
zigbee2mqtt_state{topic="zigbee2mqtt_Basement - Back Yard - Door Sensor"} 0.0
zigbee2mqtt_state{topic="zigbee2mqtt_Basement - Door Sensor"} 0.0
image
kpetremann commented 2 years ago

Hi @onedr0p,

Weird, I've just tested and it is working (I've tested for both zigbee2mqtt 1.26.0 and 1.27.0).

I do see the availability metrics: zigbee2mqtt_zigbee_availability{sensor="zigbee2mqtt_garage"} 1.0

Could you please provide the following info:

Thanks

onedr0p commented 2 years ago

Env:

LOG_LEVEL: DEBUG
MQTT_ADDRESS: emqx.default.svc.cluster.local
MQTT_TOPIC: "zigbee2mqtt/#"
MQTT_V5_PROTOCOL: "True"
MQTT_USERNAME: username
MQTT_PASSWORD: password
PROMETHEUS_PORT: 80
PROMETHEUS_PREFIX: zigbee2mqtt_
ZIGBEE2MQTT_AVAILABILITY: "True"

Zigbee2mqtt Version: 1.27.0

Logs:

https://pastebin.com/Ca86YUkK

I can try changing to changing to Availability (simple) but like you said it should work...

kpetremann commented 2 years ago

Thanks for the details. At a first glance, there is no "availability" mention in the logs. There should be whether it has failed to convert or succeeded.

I suspect zigbee2mqtt not exporting the availability metric for some reason.

But I'll have a deeper look at the log.

In the meantime, if you can extract the raw value from MQTT it would be nice. Otherwise, I may just add additional logs in the exporter to show them in debug mode.

kpetremann commented 2 years ago

@onedr0p unfortunately, I am not able to reproduce your issue.

Could you please run the exporter using this branch https://github.com/kpetremann/mqtt-exporter/tree/debug and provide me the logs.

I have simply added the original MQTT messages in the debug log. But I don't necessarily want to merge this.

onedr0p commented 2 years ago

Any chance there's a docker image of that?

kpetremann commented 2 years ago

sure Actually I've added this MQTT message debug mode as an option.

You'll have to set the following environment variables:

It will be pushed to Docker Hub once this GH Action is complete: https://github.com/kpetremann/mqtt-exporter/actions/runs/2935308892

kpetremann commented 2 years ago

The docker image has been pushed to Docker Hub

onedr0p commented 2 years ago

On the topic of docker images would it be possible to push release tags instead of only latest?

I'll try the debug image out soon.

kpetremann commented 2 years ago

On the topic of docker images would it be possible to push release tags instead of only latest?

sure

I'll try the debug image out soon.

Thanks

Also can you confirm that legacy availability payload is disabled? https://www.zigbee2mqtt.io/guide/configuration/device-availability.html#availability-payload

onedr0p commented 2 years ago

Also can you confirm that legacy availability payload is disabled? zigbee2mqtt.io/guide/configuration/device-availability.html#availability-payload

I set that to false

And what do you know with the latest latest latest version it now works :) I have no idea what happened but you did something! lol

kpetremann commented 2 years ago

Oh weird ^^ the change I pushed could not have fixed that. Maybe because of a restart either of the exporter or zigbee2mqtt?

Was it already set to false or did you change it recently?

onedr0p commented 2 years ago

I changed it, maybe that was the fix :)

onedr0p commented 2 years ago

Thanks for the debugging, I'll go ahead and close the issue!

kpetremann commented 2 years ago

oh I see. I confirm this was the root cause for sure.

As stated in the README, legacy mode is not supported.

https://github.com/kpetremann/mqtt-exporter#zigbee2mqtt-device-availability-support Note: Supports only non-legacy mode - see [Device availability advanced](https://www.zigbee2mqtt.io/guide/configuration/device-availability.html#availability-advanced-configuration)

Don't hesitate if you need further assistance or features.

onedr0p commented 2 years ago

I got confused and thought you mean the other setting which I showed in the screenshot.

kpetremann commented 2 years ago

I'll update the readme to make it clearer