项目作者: aexel90

项目描述 :
Shelly humidity sensor exporter for prometheus
高级语言: Go
项目地址: git://github.com/aexel90/shelly_exporter.git
创建时间: 2021-01-04T16:05:12Z
项目社区:https://github.com/aexel90/shelly_exporter

开源协议:Apache License 2.0

下载


Prometheus Shelly Exporter and Grafana integration

This exporter exports some metrics from Shelly to Prometheus.

Testes with:

Shelly H&T Shelly Plus 2PM

Shelly API

Shelly API: https://shelly-api-docs.shelly.cloud/#shelly-h-amp-t

Shelly cloud API access: https://shelly.cloud/documents/developers/shelly_cloud_api_access.pdf

Test API with HTTP POST:

  1. https://<url>/device/status?auth_key=<auth_key>&id=<id>

Configuration File: shelly-metrics.json

Determine “auth_key”, “id” and “url” of your device via Shelly cloud API access and update in shelly-metrics.json.
“shelly_name” and “name” can be determined on your own.

  1. {
  2. "account":{
  3. "auth_key": "...",
  4. "url": "..."
  5. },
  6. "products": [
  7. {
  8. "type": "ht",
  9. "export": {
  10. "isok": "isok",
  11. "temperature": "data.device_status.tmp.value",
  12. "humidity": "data.device_status.hum.value",
  13. "battery": "data.device_status.bat.value",
  14. "has_update": "data.device_status.update.has_update",
  15. "firmware": "data.device_status.getinfo.fw_info.fw",
  16. "mac": "data.device_status.mac",
  17. "updated": "data.device_status._updated"
  18. },
  19. "devices": [
  20. {
  21. "id": "956b54",
  22. "shelly_name": "S1",
  23. "name": "Indoor"
  24. },
  25. {
  26. "id": "9574a8",
  27. "shelly_name": "S2",
  28. "name": "Outdoor"
  29. }
  30. ]
  31. },
  32. ...

Build

  1. go get github.com/aexel90/shelly_exporter/
  2. cd $GOPATH/src/github.com/aexel90/shelly_exporter
  3. go install

Execution

Usage:

  1. $GOPATH/bin/shelly_exporter -h
  2. Usage of ./shelly_exporter:
  3. -listen-address string
  4. The address to listen on for HTTP requests. (default "127.0.0.1:9784")
  5. -metrics-file string
  6. The JSON file with the metric definitions. (default "shelly-metrics.json")
  7. -test
  8. Test configured metrics

Execute:

  1. $GOPATH/go/bin/shelly_exporter -metrics-file $GOPATH/go/bin/shelly-metrics.json

Testing:

  1. $GOPATH/go/bin/shelly_exporter -metrics-file $GOPATH/go/bin/shelly-metrics.json -test
  2. Metric: shelly_ht_info
  3. - Exporter Result:
  4. - Exporter Result 0:
  5. - humidity="53"
  6. - mac="E09806956B54"
  7. - name="Indoor"
  8. - isok="true"
  9. - shelly_name="S1"
  10. - temperature="22.88"
  11. - battery="85"
  12. - has_update="false"
  13. - firmware=""
  14. - updated="2021-11-23 19:43:54"
  15. - Exporter Result 1:
  16. - has_update="false"
  17. - firmware="20210323-104951/v1.10.1-gf276b51"
  18. - isok="true"
  19. - name="Outdoor"
  20. - temperature="6.38"
  21. ...

Docker

  1. cp shelly-metrics.json.template shelly-metrics.json
  2. vi shelly-metrics.json
  3. docker-compose up -d --build

Grafana Dashboard

weather widget

https://weatherwidget.io/

  1. <!doctype html> <html lang="de">
  2. <head>
  3. </head>
  4. <body>
  5. <a class="weatherwidget-io" href="https://forecast7.com/de/51d0513d74/dresden/" data-label_1="DRESDEN" data-theme="original" data-highcolor="#88d976" >DRESDEN</a>
  6. <script>
  7. !function(d,s,id){
  8. var js,fjs=d.getElementsByTagName(s)[0];
  9. if(!d.getElementById(id)){
  10. js=d.createElement(s);
  11. js.id=id;
  12. js.src='https://weatherwidget.io/js/widget.min.js';
  13. fjs.parentNode.insertBefore(js,fjs);
  14. setInterval('__weatherwidget_init()', 1800000) <!-- refresh widget every 30 minutes (1800000 milliseconds): -->
  15. }
  16. }(document,'script','weatherwidget-io-js');
  17. </script>
  18. </body>
  19. </html>

dashboard

Grafana-ID: 13739
https://grafana.com/grafana/dashboards/13739

grafana.ini

  1. [panels]
  2. # If set to true Grafana will allow script tags in text panels. Not recommended as it enable XSS vulnerabilities.
  3. disable_sanitize_html = true

Grafana
Grafana Rollo