hikhvar / mqtt2prometheus

MQTT to Prometheus gateway
MIT License
350 stars 69 forks source link

trouble finding the right yaml #99

Open Simoliv opened 1 year ago

Simoliv commented 1 year ago

HI there,

please apologize, I seem to be unable to find thr right settings for the exporter .. But .. the documentation could be a bit clearer IMO, some more examples would helped me maybe.

Can anybody guide me in the right direction ? I am having

hoymiles/111817603175/pf 0.999   
hoymiles/111816703175/frequency 49.97   
hoymiles/111816703175/temperature 57.8    
hoymiles/111816703175/total 275.775   
hoymiles/111816703175/emeter/0/power 636.8   
hoymiles/111816703175/emeter/0/voltage 237.6   
hoymiles/111816703175/emeter/0/current 2.68   
hoymiles/111816703175/emeter-dc/0/total 70.852   
hoymiles/111816703175/emeter-dc/0/power 253.6
hoymiles/111816703175/emeter-dc/0/voltage 38.8
hoymiles/111816703175/emeter-dc/0/current 6.54
hoymiles/111816703175/emeter-dc/1/total 72.247
hoymiles/111816703175/emeter-dc/1/power 262.1
hoymiles/111816703175/emeter-dc/1/voltage 38.8
hoymiles/111816703175/emeter-dc/1/current 6.76
hoymiles/111816703175/emeter-dc/2/total 69.769
hoymiles/111816703175/emeter-dc/2/power 109.2
hoymiles/111816703175/emeter-dc/2/voltage 43.5
hoymiles/111816703175/emeter-dc/2/current 2.51
hoymiles/111816703175/emeter-dc/3/total 62.91
hoymiles/111816703175/emeter-dc/3/power 45.4
hoymiles/111816703175/emeter-dc/3/voltage 43.5
hoymiles/111816703175/emeter-dc/3/current 1.04

in mosquitto, and would like to get that into prometheus .. What does my config.yaml need to look like ? The best I was able to achieve was a

2022-10-16T16:39:43Z error cmd/mqtt2prometheus.go:158 Error while processing message {"error": "could not store metrics '275.798' on topic hoymiles/111816703175/total: failed to extract metric values from topic: failed to find valid metric in topic path"}

and some more of this kind of messages..

any help would really be appreciated, best regards

wmoss commented 1 year ago

I don't think this is documented anywhere, but the default configuration assumes the values coming from mqtt are json. Since you have only single metric values, you need to set metric_per_topic_config in your config.yaml. That expects a single key called metric_name_regex that contains a regex that runs on the topic to produce the metric name. It must have a named group for metricname.

I haven't tested this, but I'm guessing adding something like this might work.

mqtt:
  metric_per_topic_config:
    metric_name_regex: (.*/)?(?P<metricname>.*)

Have a look around config.go for more info.

wmoss commented 1 year ago

Also, have a look at https://github.com/hikhvar/mqtt2prometheus/issues/96, it's a similar issue