From 5137a8f063a5e331fb59ba0cc782a0bc7c8d0cc5 Mon Sep 17 00:00:00 2001 From: Joerg Lehmann Date: Tue, 4 Oct 2022 20:00:45 +0200 Subject: [PATCH] add Grafana Prometheus metric forwarding --- nbit-mqtt/docker-compose.yml | 22 ++++++++++++++++++++++ nbit-mqtt/mqtt2prometheus-config.yaml | 23 +++++++++++++++++++++++ nbit-mqtt/prometheus.yml | 19 +++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 nbit-mqtt/mqtt2prometheus-config.yaml create mode 100644 nbit-mqtt/prometheus.yml diff --git a/nbit-mqtt/docker-compose.yml b/nbit-mqtt/docker-compose.yml index 2e6251c..f1f2bcc 100644 --- a/nbit-mqtt/docker-compose.yml +++ b/nbit-mqtt/docker-compose.yml @@ -18,3 +18,25 @@ services: tty: true volumes: - /home/joerg/nbit-mqtt/data-shellies:/data + + mqtt2prometheus: + image: ghcr.io/hikhvar/mqtt2prometheus:latest + command: + - /mqtt2prometheus + - -log-level + - debug + - -config + - /config.yaml + ports: + - 9641:9641 + volumes: + - type: bind + source: ./mqtt2prometheus-config.yaml + target: /config.yaml + + prometheus: + image: prom/prometheus:latest + volumes: + - type: bind + source: ./prometheus.yml + target: /etc/prometheus/prometheus.yml diff --git a/nbit-mqtt/mqtt2prometheus-config.yaml b/nbit-mqtt/mqtt2prometheus-config.yaml new file mode 100644 index 0000000..7fb0261 --- /dev/null +++ b/nbit-mqtt/mqtt2prometheus-config.yaml @@ -0,0 +1,23 @@ +mqtt: + server: tcp://mqtt.nbit.ch:1883 + user: mqtt + password: mqtt7355@ + topic_path: shellies/events/rpc + device_id_regex: "(.*/)?(?P.*)" + qos: 0 +cache: + timeout: 24h +json_parsing: + separator: . +metrics: + # The name of the metric in prometheus + - prom_name: aenergy_total + # The name of the metric in a MQTT JSON message + mqtt_name: params.switch:0.aenergy.total + # The prometheus help text for this metric + help: total energy + # The prometheus type for this metric. Valid values are: "gauge" and "counter" + type: gauge + # A map of string to string for constant labels. This labels will be attached to every prometheus metric + const_labels: + sensor_type: shelly diff --git a/nbit-mqtt/prometheus.yml b/nbit-mqtt/prometheus.yml new file mode 100644 index 0000000..49e62f6 --- /dev/null +++ b/nbit-mqtt/prometheus.yml @@ -0,0 +1,19 @@ +global: + scrape_interval: 5m + scrape_timeout: 10s + evaluation_interval: 15s +scrape_configs: + - job_name: mqtt2prometheus + honor_timestamps: true + scrape_interval: 5m + scrape_timeout: 10s + metrics_path: /metrics + scheme: http + static_configs: + - targets: + - mqtt2prometheus:9641 +remote_write: + - basic_auth: + password: eyJrIjoiOWJlNzM1ODYzY2JjZmE5MTA5YTcyNzJlNTk3MjllY2U3YjViMDk1NSIsIm4iOiJzdGFjay00NDQyODktZWFzeXN0YXJ0LXByb20tcHVibGlzaGVyIiwiaWQiOjcxNzI1MX0= + username: 589349 + url: https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push