Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| software:applications:mqtt2prometheus [2022/04/13 18:07] – Enregistrement de références yoann | software:applications:mqtt2prometheus [2022/12/20 22:58] (Version actuelle) – yoann | ||
|---|---|---|---|
| Ligne 4: | Ligne 4: | ||
| ====== mqtt2prometheus : Prometheus exporter ====== | ====== mqtt2prometheus : Prometheus exporter ====== | ||
| - | **mqtt2prometheus** est un " | + | **mqtt2prometheus** est un " |
| + | ===== Connexion au Broker MQTT ===== | ||
| + | |||
| + | Le fichier de configuration ''/ | ||
| + | |||
| + | <code yaml> | ||
| + | mqtt: | ||
| + | # The MQTT broker to connect to | ||
| + | server: tcp:// | ||
| + | # Optional: Username and Password for authenticating with the MQTT Server | ||
| + | # user: bob | ||
| + | # password: happylittleclouds | ||
| + | # Optional: for TLS client certificates | ||
| + | # ca_cert: certs/ | ||
| + | # client_cert: | ||
| + | # client_key: certs/ | ||
| + | # Optional: Used to specify ClientID. The default is < | ||
| + | client_id: mqtt_exporter | ||
| + | # The Topic path to subscribe to. Be aware that you have to specify the wildcard. | ||
| + | topic_path: '#' | ||
| + | # Optional: Regular expression to extract the device ID from the topic path. The default regular expression, assumes | ||
| + | # that the last " | ||
| + | # The regular expression must contain a named capture group with the name deviceid | ||
| + | # For example the expression for tasamota based sensors is " | ||
| + | # device_id_regex: | ||
| + | # The MQTT QoS level | ||
| + | qos: 0 | ||
| + | </ | ||
| + | |||
| + | L' | ||
| + | |||
| + | <code bash> | ||
| + | docker-compose logs mosquitto | ||
| + | Attaching to synopush_mqtt_broker | ||
| + | synopush_mqtt_broker | 1671561436: mosquitto version 2.0.14 starting | ||
| + | synopush_mqtt_broker | 1671561436: Config loaded from / | ||
| + | synopush_mqtt_broker | 1671561436: Opening ipv4 listen socket on port 1883. | ||
| + | synopush_mqtt_broker | 1671561436: Opening ipv6 listen socket on port 1883. | ||
| + | synopush_mqtt_broker | 1671561436: mosquitto version 2.0.14 running | ||
| + | synopush_mqtt_broker | 1671561437: New connection from 172.19.0.5: | ||
| + | synopush_mqtt_broker | 1671561437: New client connected from 172.19.0.5: | ||
| + | . . . | ||
| + | </ | ||
| + | |||
| + | Les logs indiquent bien qu'un client nommé " | ||
| + | |||
| + | ===== Exposition des métriques ===== | ||
| + | |||
| + | Les métriques ne seront plus présentées à Prometheus si les valeurs ne sont pas rafraîchies par la réception de message MQTT en deçà de la valeur de **timeout**. | ||
| + | <code yaml> | ||
| + | cache: | ||
| + | # Timeout. Each received metric will be presented for this time if no update is send via MQTT. | ||
| + | # Set the timeout to -1 to disable the deletion of metrics from the cache. The exporter presents the ingest timestamp | ||
| + | # to prometheus. | ||
| + | timeout: 24h | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | Le fichier de configuration permet de définir/ | ||
| + | |||
| + | <code yaml> | ||
| + | # Liste des métriques valides. Seules les métriques listées ci-dessous seront exportées. | ||
| + | metrics: | ||
| + | # Nom de la métrique exposée pour Prometheus | ||
| + | - prom_name: temperature_celsius | ||
| + | # Correspondance avec la valeur du message JSON MQTT | ||
| + | mqtt_name: t | ||
| + | # Description de la métrique | ||
| + | help: temperature ambiante (°C) | ||
| + | # Type de la métrique Prometheus. Valeurs possibles: " | ||
| + | type: gauge | ||
| + | # Nom de la métrique exposée pour Prometheus | ||
| + | - prom_name: humidity_ratio | ||
| + | # Correspondance avec la valeur du message JSON MQTT | ||
| + | mqtt_name: u | ||
| + | # Description de la métrique | ||
| + | help: Humidité relative (%) | ||
| + | # Type de la métrique Prometheus. Valeurs possibles: " | ||
| + | type: gauge | ||
| + | </ | ||
| + | |||
| + | ===== Scraping par Prometheus ===== | ||
| + | |||
| + | Par défaut mqtt2prometheus écoute sur le port **9641**. Vérifier que depuis le conteneur Prometheus, on peut atteindre l' | ||
| + | |||
| + | <code bash> | ||
| + | # ouvre un shell interactif dans le conteneur prometheus | ||
| + | docker-compose exec -u root prometheus /bin/sh | ||
| + | |||
| + | # Récupère et affiche les métriques exposés par mqtt2prometheus dans la console | ||
| + | wget -O - " | ||
| + | </ | ||
| ===== logs ===== | ===== logs ===== | ||
| Ligne 12: | Ligne 104: | ||
| S' | S' | ||
| - | < | ||
| - | const ( | ||
| - | // DebugLevel logs are typically voluminous, and are usually disabled in | ||
| - | // production. | ||
| - | DebugLevel = zapcore.DebugLevel | ||
| - | // InfoLevel is the default logging priority. | ||
| - | InfoLevel = zapcore.InfoLevel | ||
| - | // WarnLevel logs are more important than Info, but don't need individual | ||
| - | // human review. | ||
| - | WarnLevel = zapcore.WarnLevel | ||
| - | // ErrorLevel logs are high-priority. If an application is running smoothly, | ||
| - | // it shouldn' | ||
| - | ErrorLevel = zapcore.ErrorLevel | ||
| - | // DPanicLevel logs are particularly important errors. In development the | ||
| - | // logger panics after writing the message. | ||
| - | DPanicLevel = zapcore.DPanicLevel | ||
| - | // PanicLevel logs a message, then panics. | ||
| - | PanicLevel = zapcore.PanicLevel | ||
| - | // FatalLevel logs a message, then calls os.Exit(1). | ||
| - | FatalLevel = zapcore.FatalLevel | ||
| - | ) | ||
| - | </ | ||
| + | ^ debug | Journaux verbeux le plus souvent désactivé en production. | ||
| + | ^ info | Priorité de journalisation par défaut. | ||
| + | ^ warn | Priorité plus haute que info mais ne nécessitant pas une intervention particulière. | | ||
| + | ^ error | Événements de haute priorité nécessitant une correction. Une application s’exécutant normalement ne doit pas générer d' | ||
| + | ^ dpanic | ||
| + | ^ panic | Journalisation de l' | ||
| + | ^ fatal | Journalisation de l' | ||
| ===== Références ===== | ===== Références ===== | ||
| Ligne 40: | Ligne 117: | ||
| * https:// | * https:// | ||
| * https:// | * https:// | ||
| + | * https:// | ||