Skip to content

Add Prometheus publisher #640

@barcar

Description

@barcar

Is your feature request related to a problem? Please describe.

I'm trying to consume more of my metric data into Prometheus (https://prometheus.io) which seems a bit simpler for a novice that InfluxDB. To simplify my metric flow I've been trying to get metrics from source to Prometheus with the fewest number of hops - a bunch of services (esphome, homebridge, ruuvitag) have simple Prometheus exporters.

I found a Prometheus exporter for Ecowitt (https://github.com/JosephRPalmer/ecowitt-bridge) which would allow me to eliminate MQTT for these metrics but it doesn't have the excellent unit conversion and calculated metric capabilities of Ecowitt2MQTT.

Describe the solution you'd like

Ideally I would like the option in Ecowitt2MQTT to enable an additional Prometheus exporter target which would list all the metrics published to MQTT. This endpoint would listen on an alternate port and the metrics would be updated on each refresh from the weather station.

The config would be simply which port to publish the exporter metrics on.

Additional context

This is a sample of the exporter output from the ecowitt-bridge project:

# TYPE ecowitt_baromabshpa gauge
ecowitt_baromabshpa 1007.8364654999999
# HELP ecowitt_tempc ECOWITT data gauge
# TYPE ecowitt_tempc gauge
ecowitt_tempc 17.800000000000004
# HELP ecowitt_humidity ECOWITT data gauge
# TYPE ecowitt_humidity gauge
ecowitt_humidity 80.0
# HELP ecowitt_winddir ECOWITT data gauge
# TYPE ecowitt_winddir gauge
ecowitt_winddir 290.0
# HELP ecowitt_windspeedmph ECOWITT data gauge
# TYPE ecowitt_windspeedmph gauge
ecowitt_windspeedmph 1.12
# HELP ecowitt_windgustmph ECOWITT data gauge
# TYPE ecowitt_windgustmph gauge
etc

It uses the Python prometheus_client (https://github.com/prometheus/client_python) library and simply builds a dictionary of gauges (one per metric) which is updated when a new metric is received (https://github.com/JosephRPalmer/ecowitt-bridge/blob/main/app/app.py).

The prometheus client is configured to listen on an HTTP port and automatically generates the required format output from the gauge dictionary. I'm thinking the MQTT topic could easily be converted to gauge names.

I would be happy to work on a fork to do this myself but my Python is very basic and I'm not sure where best to integrate this functionality. Would the gauge updating be a new publisher? Or would it just slot into the existing MQTT publisher? Would I just hook into the existing server? Or create an additional server instance?

I'll probably start stumbling around in the dark to try and get this to work for myself but whether the result would be a welcome pull request or of sufficient quality for acceptance is hard to say at this stage.

Anyway - just putting the idea out there... thanks for this project. It's great work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementEnhancement of the code, not introducing new features.help-wantedNeeds a helping hang or expertise in order to resolve

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions