- Go 87.6%
- Go Template 8.5%
- Dockerfile 3.9%
|
|
||
|---|---|---|
| .forgejo/workflows | ||
| charts/shelly-prometheus-exporter | ||
| config.go | ||
| Dockerfile | ||
| go.mod | ||
| go.sum | ||
| main.go | ||
| metrics.go | ||
| mqtt.go | ||
| mqtt_test.go | ||
| Readme.md | ||
| renovate.json | ||
Shelly Prometheus Exporter
Subscribes to the MQTT topics of Shelly Gen2+ devices and exposes their status as Prometheus metrics on /metrics.
Configuration
All configuration is done via environment variables.
| Variable | Default | Description |
|---|---|---|
MQTT_BROKER |
(required) | Broker URL, e.g. tcp://192.168.1.10:1883 or ssl://broker:8883 |
MQTT_USERNAME |
Username; leave empty for brokers without authentication | |
MQTT_PASSWORD |
Password | |
MQTT_CLIENT_ID |
shelly-prometheus-exporter |
MQTT client ID |
MQTT_QOS |
0 |
Subscription QoS (0, 1 or 2) |
MQTT_TOPICS |
Comma-separated device topic prefixes, e.g. shellyplussmoke-halle-2,shellyplussmoke-funkzentrale |
|
MQTT_WILDCARD_TOPIC |
Topic prefix with MQTT wildcard, e.g. + (all root-level devices) or shellies/+ |
|
LISTEN_ADDRESS |
:9784 |
HTTP listen address for the metrics endpoint |
LOG_LEVEL |
INFO |
ERROR, WARN, INFO or DEBUG |
LOG_FOLDER |
If set, logs are additionally written to <LOG_FOLDER>/application.log |
At least one of MQTT_TOPICS or MQTT_WILDCARD_TOPIC must be set. For each prefix the exporter subscribes to
<prefix>/online, <prefix>/status/+ and <prefix>/events/rpc. The device label is the last segment of the prefix.
Metrics
| Metric | Labels | Source |
|---|---|---|
shelly_online |
device |
<device>/online |
shelly_cloud_connected |
device |
status/cloud → connected |
shelly_mqtt_connected |
device |
status/mqtt → connected |
shelly_smoke_alarm |
device, id |
status/smoke:<id> → alarm |
shelly_smoke_mute |
device, id |
status/smoke:<id> → mute |
shelly_battery_voltage_volts |
device, id |
status/devicepower:<id> → battery.V |
shelly_battery_percent |
device, id |
status/devicepower:<id> → battery.percent |
shelly_last_message_timestamp_seconds |
device |
Time of the last message from the device |
NotifyStatus events on <device>/events/rpc are applied too, so e.g. a smoke alarm shows up immediately.
To export more values, add an entry to the mappings table in metrics.go.
Example
MQTT_BROKER=tcp://192.168.1.10:1883 MQTT_WILDCARD_TOPIC=+ go run .
Helm
A chart is located in charts/shelly-prometheus-exporter. It deploys the exporter,
a Service and a ServiceMonitor (requires the Prometheus Operator CRDs, disable with serviceMonitor.enabled=false).
Inline connection settings:
helm install shelly-exporter charts/shelly-prometheus-exporter \
--set mqtt.broker=tcp://192.168.1.10:1883 \
--set mqtt.username=exporter --set mqtt.password=secret \
--set mqtt.wildcardTopic=+
Existing secret (keys MQTT_BROKER, optional MQTT_USERNAME / MQTT_PASSWORD, configurable via mqtt.existingSecretKeys):
kubectl create secret generic shelly-mqtt \
--from-literal=MQTT_BROKER=tcp://192.168.1.10:1883 \
--from-literal=MQTT_USERNAME=exporter --from-literal=MQTT_PASSWORD=secret
helm install shelly-exporter charts/shelly-prometheus-exporter \
--set mqtt.existingSecret=shelly-mqtt \
--set 'mqtt.topics={shellyplussmoke-halle-2,shellyplussmoke-funkzentrale}'