Support for non-JSON format messages
batmule opened this issue · 3 comments
I'm trying to parse data from a sensor that sends "raw values", like:
sensors/temperature/28E66D1B000000D4 23.4375
It does not look like that format is supported, or am I missing something? Is JSON the only supported payload format?
Regards,
Flemming
More detail:
2021-07-10T14:36:42+02:00 debug metrics/ingest.go:42 Got message {"topic": "sensors/temperature/28EEE3D31F1602D6", "payload": "18.1250"}
Hello,
if the metrics are pure numbers you might be interested in the metrics_per_topic_config
like in the shelly config: https://github.com/hikhvar/mqtt2prometheus/blob/master/hack/shelly.yaml
In your case I think the correct config is:
mqtt:
server: tcp://mosquitto:1883
topic_path: sensors/+/+
device_id_regex: "sensors/+/(?P<deviceid>.*)"
metric_per_topic_config:
metric_name_regex: "sensors/(?P<metricname>.*)/(?P<deviceid>.*)"
qos: 0
cache:
timeout: 24h
metrics:
- prom_name: temperature
# The name of the metric in a MQTT JSON message
mqtt_name: temperature
# The prometheus help text for this metric
help: shelly temperature reading
# The prometheus type for this metric. Valid values are: "gauge" and "counter"
type: gauge
This feature is rather new and undocumented :-( I currently don't have to time to document this.
This works very nice. Thanks for the quick reply!
(After changing '+' to '.*' in device_id_regex)
For other users:
I have the topics:
- sensors/mq135/DEVICEID
- sensors/temperature/DEVICEID
- sensors/humidity/DEVICEID
- sensors/pressure/DEVICEID
Each have the raw reading as the message content,
i.e.: sensors/temperature/28:80:66:1B:00:00:00:D5 28.4375
Output from mqtt2prometheus (seen from the servername:9641/metrics page) is now of the form:
batmule_temperature_celsius{sensor="28:80:66:1B:00:00:00:D5",topic="sensors/temperature/28:80:66:1B:00:00:00:D5"} 28.375 1626263444138
The metrics part of my config looks like:
metrics:
- prom_name: batmule_temperature_celsius
mqtt_name: temperature
help: Temperature reading in deg C
type: gauge
- prom_name: batmule_pressure_Pa
mqtt_name: pressure
help: Pressure reading in Pa
type: gauge
- prom_name: batmule_humidity_percent
mqtt_name: humidity
help: Humidity reading in percent
type: gauge
- prom_name: batmule_airquality_number
mqtt_name: mq135
help: Air quality metric
type: gauge