mqtt2prometheus
mqtt2prometheus copied to clipboard
Beginner Issues
Hi
First, I'm seeing a lot of go-related metrics in the output
go_gc_duration_seconds{quantile="0"} 3.2688e-05
I'm new to prometheus, but doesn't spamming it with 100s of extra metrics cause some memory use - or should I configure prom to ignore anything starting with 'go'
Am I missing something?
Second, I'm sending messages like this:
topic: watchdog/esp-garage: Payload: {"message": "Alive"}
I get this on the output:
received_messages{status="storeError",topic="watchdog/esp-garage"} 34
previously I sent non-JSON messages and it was happier, but I didn't see a direct metric for my line.
My configuration is below - any thoughts?
topic_path: watchdog/#
device_id_regex: "(.*/)?(?P<deviceid>.*)"
qos: 0
cache:
timeout: 24h
json_parsing:
- prom_name: watchdog
mqtt_name: message
help: Watchdog message
type: gauge
Thanks
Martin Green
Regarding the error, I think you want put the specific message configuration under metrics: not json_parsing:. If would be helpful if you posted the logs from the service though, as that would have more information.
Regarding the go... metrics, I was actually noticing the same thing @hikhvar. Thoughts on adding a configuration flag to remove those?
Hey,
it's quite normal in the prometheus eco system to have those runtime specific go_... metrics, and I don't see any problems in having them. The canonical mechansim to drop them is via relabeling in the prometheus server: https://medium.com/quiq-blog/prometheus-relabeling-tricks-6ae62c56cbda
Regarding your initial problem: The payload you presented, don't have a number as value. mqtt2prometheus assumes by default, that the values are numbers, because prometheus metrics can only have numeric values. If you want to map a string like here:
{"message": "Alive"}
you must define a mapping. Example:
topic_path: watchdog/#
device_id_regex: "(.*/)?(?P<deviceid>.*)"
qos: 0
cache:
timeout: 24h
json_parsing:
- prom_name: watchdog
mqtt_name: message
help: Watchdog message
type: gauge
string_value_mapping:
map:
Alive: 1
Dead: 0
# Metric value to use if a match cannot be found in the map above.
# If not specified, parsing error will occur.
error_value: -1
Yeah, I ended up doing something similar in my prometheus config and I guess that's just as good a solution as adding a flag, probably easier. If it's helpful, my config looks like,
scrape_configs:
- job_name: mqtt2prometheus
scrape_interval: 10s
static_configs:
- targets:
- "localhost:9641"
metric_relabel_configs:
- source_labels: ["__name__"]
regex: <metrics to keep here>
action: keep
@mgg1010 seems like it wouldn't be a terrible entry in the FAQ of the main Readme if you wanted to add the answer to your question there.