From 0a300339afcf8f6679babfed76d321f553f64e3f Mon Sep 17 00:00:00 2001 From: Christoph Petrausch Date: Thu, 21 May 2020 13:37:50 +0200 Subject: [PATCH] Add complete local development stack --- hack/docker-compose.yml | 23 +++++++++++++ hack/mqtt2prometheus.yaml | 68 +++++++++++++++++++++++++++++++++++++++ hack/prometheus.yml | 30 +++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 hack/docker-compose.yml create mode 100644 hack/mqtt2prometheus.yaml create mode 100644 hack/prometheus.yml diff --git a/hack/docker-compose.yml b/hack/docker-compose.yml new file mode 100644 index 0000000..cad4fad --- /dev/null +++ b/hack/docker-compose.yml @@ -0,0 +1,23 @@ +version: "3.8" +services: + mqtt2prometheus: + build: + context: ../ + dockerfile: Dockerfile + volumes: + - type: bind + source: ./mqtt2prometheus.yaml + target: /config.yaml + mosquitto: + image: eclipse-mosquitto:1.6.9 + ports: + - 1883:1883 + - 9001:9001 + prometheus: + image: prom/prometheus:v2.18.1 + ports: + - 9090:9090 + volumes: + - type: bind + source: ./prometheus.yml + target: /etc/prometheus/prometheus.yml \ No newline at end of file diff --git a/hack/mqtt2prometheus.yaml b/hack/mqtt2prometheus.yaml new file mode 100644 index 0000000..e4e8aef --- /dev/null +++ b/hack/mqtt2prometheus.yaml @@ -0,0 +1,68 @@ +# Settings for the MQTT Client. Currently only these three are supported +mqtt: + # The MQTT broker to connect to + server: tcp://mosquitto:1883 + # Optional: Username and Password for authenticating with the MQTT Server + # user: bob + # password: happylittleclouds + # The Topic path to subscripe to. Actually this will become `$topic_path/+` + topic_path: v1/devices/me + # The MQTT QoS level + qos: 0 +cache: + # Timeout. Each received metric will be presented for this time if no update is send via MQTT + timeout: 2m +# This is a list of valid metrics. Only metrics listed here will be exported +metrics: + # The name of the metric in prometheus + - prom_name: temperature + # The name of the metric in a MQTT JSON message + mqtt_name: temperature + # The prometheus help text for this metric + help: DHT22 temperature reading + # 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: dht22 + # The name of the metric in prometheus + - prom_name: humidity + # The name of the metric in a MQTT JSON message + mqtt_name: humidity + # The prometheus help text for this metric + help: DHT22 humidity reading + # 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: dht22 + # The name of the metric in prometheus + - prom_name: heat_index + # The name of the metric in a MQTT JSON message + mqtt_name: heat_index + # The prometheus help text for this metric + help: DHT22 heatIndex calculation + # 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: dht22 + - prom_name: state + # The name of the metric in a MQTT JSON message + mqtt_name: state + # The prometheus help text for this metric + help: Light state + # 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: ikea + # When specified, enables mapping between string values to metric values. + string_value_mapping: + # A map of string to metric value. + map: + off: 0 + low: 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 diff --git a/hack/prometheus.yml b/hack/prometheus.yml new file mode 100644 index 0000000..d0a69f7 --- /dev/null +++ b/hack/prometheus.yml @@ -0,0 +1,30 @@ +global: + scrape_interval: 15s + scrape_timeout: 10s + evaluation_interval: 15s +alerting: + alertmanagers: + - static_configs: + - targets: [] + scheme: http + timeout: 10s + api_version: v1 +scrape_configs: + - job_name: prometheus + honor_timestamps: true + scrape_interval: 15s + scrape_timeout: 10s + metrics_path: /metrics + scheme: http + static_configs: + - targets: + - localhost:9090 + - job_name: mqtt2prometheus + honor_timestamps: true + scrape_interval: 15s + scrape_timeout: 10s + metrics_path: /metrics + scheme: http + static_configs: + - targets: + - mqtt2prometheus:8002 \ No newline at end of file