diff --git a/tools/rpi/Dockerfile.basic b/tools/rpi/Dockerfile.basic new file mode 100644 index 000000000..fbbecc5ed --- /dev/null +++ b/tools/rpi/Dockerfile.basic @@ -0,0 +1,18 @@ +FROM python:latest + +LABEL maintainer Simoliv + +USER root + +RUN mkdir /hoymiles_exporter + +COPY . /hoymiles_exporter + +WORKDIR /hoymiles_exporter + +RUN pip3 install --upgrade pip +RUN ls -la +RUN pip3 install -r requirements.txt +RUN pip3 install -r optional-requirements.txt + +CMD python3 -um hoymiles --verbose --log-transactions --config ahoy.yml diff --git a/tools/rpi/README.md b/tools/rpi/README.md index 79bc5cbbb..b683a2946 100644 --- a/tools/rpi/README.md +++ b/tools/rpi/README.md @@ -251,6 +251,65 @@ Use basic command line tools to get an idea what you recorded. For example: A brief example log is supplied in the `example-logs` folder. +Prometheus Exporter +------------------- +Python exporter for https://prometheus.io/ + +install requirements: + +``` +pip install -r optional-requirements.txt +``` + +Systemd service: +---------------- + +in systemd you find a service file to (fe) run the exporter as a systemd service at boot time. + +Adjust the user in it and copy it to /lib/systemd/system + +Activate it: + +``` + sudo systemctl enable hoymiles.service +``` + +Start it + +``` + sudo service hoymiles start +``` + +After that, you should be able to open a website to http://ip-of-your-rpi:9233/ and see some stats + +``` +# HELP python_gc_objects_collected_total Objects collected during gc +# TYPE python_gc_objects_collected_total counter +python_gc_objects_collected_total{generation="0"} 304.0 +python_gc_objects_collected_total{generation="1"} 124.0 +python_gc_objects_collected_total{generation="2"} 0.0 +``` +and on the bottom : + +``` +string_voltage{panel="panel_3"} 39.4 +# HELP string_current DC/Panel current +# TYPE string_current gauge +string_current{panel="panel_3"} 5.73 +# HELP string_power DC/Panel power +# TYPE string_power gauge +string_power{panel="panel_3"} 225.4 +# HELP string_energy_daily DC/Panel energy_daily +# TYPE string_energy_daily gauge +string_energy_daily{panel="panel_3"} 487.0 +``` + + more stats + +I added my dashboard to docker-sup../dashboard folder if you are interested + +![dashboard_example1](docker-supplementals/dashboard/Selection_025.jpg) +![dashboard_example2](docker-supplementals/dashboard/Selection_027.jpg) + diff --git a/tools/rpi/ahoy.yml.example b/tools/rpi/ahoy.yml.example index 9301067f8..428219a61 100644 --- a/tools/rpi/ahoy.yml.example +++ b/tools/rpi/ahoy.yml.example @@ -34,6 +34,11 @@ ahoy: topic: my_DTU_name # Name of DTU - default: hoymiles/{DTU-serial} payload: "LAST-WILL-MESSAGE: Please check my HOST and Process!" + # adding prometheus exporter + prometheus: + disabled: false + port: 9233 + # Influx2 output influxdb: disabled: true diff --git a/tools/rpi/docker-supplementals/dashboard/Selection_025.jpg b/tools/rpi/docker-supplementals/dashboard/Selection_025.jpg new file mode 100644 index 000000000..49be50d58 Binary files /dev/null and b/tools/rpi/docker-supplementals/dashboard/Selection_025.jpg differ diff --git a/tools/rpi/docker-supplementals/dashboard/Selection_027.jpg b/tools/rpi/docker-supplementals/dashboard/Selection_027.jpg new file mode 100644 index 000000000..ae4053a51 Binary files /dev/null and b/tools/rpi/docker-supplementals/dashboard/Selection_027.jpg differ diff --git a/tools/rpi/docker-supplementals/dashboard/SolarEnergy-1667477915632.json b/tools/rpi/docker-supplementals/dashboard/SolarEnergy-1667477915632.json new file mode 100644 index 000000000..ecaff6c4b --- /dev/null +++ b/tools/rpi/docker-supplementals/dashboard/SolarEnergy-1667477915632.json @@ -0,0 +1,1678 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 1, + "id": 1, + "links": [], + "liveNow": false, + "panels": [ + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "text", + "value": null + }, + { + "color": "dark-red", + "value": 180 + }, + { + "color": "dark-green", + "value": 220 + } + ] + }, + "unit": "volt" + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 2, + "x": 0, + "y": 0 + }, + "id": 9, + "options": { + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true + }, + "pluginVersion": "9.2.1", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "editorMode": "code", + "expr": "phase_voltage", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "AC Volts", + "transparent": true, + "type": "gauge" + }, + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "text", + "value": null + }, + { + "color": "dark-red", + "value": 200 + }, + { + "color": "semi-dark-orange", + "value": 400 + }, + { + "color": "dark-yellow", + "value": 500 + }, + { + "color": "green", + "value": 600 + }, + { + "color": "dark-green", + "value": 800 + } + ] + }, + "unit": "watt" + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 2, + "x": 2, + "y": 0 + }, + "id": 10, + "options": { + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true + }, + "pluginVersion": "9.2.1", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "editorMode": "code", + "expr": "phase_power", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "AC Watt", + "transparent": true, + "type": "gauge" + }, + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "text", + "value": null + }, + { + "color": "dark-red", + "value": 2 + }, + { + "color": "dark-yellow", + "value": 3 + }, + { + "color": "light-green", + "value": 4 + }, + { + "color": "dark-green", + "value": 5 + } + ] + }, + "unit": "amp" + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 2, + "x": 4, + "y": 0 + }, + "id": 11, + "options": { + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true + }, + "pluginVersion": "9.2.1", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "editorMode": "code", + "expr": "phase_current", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "AC Ampere", + "transparent": true, + "type": "gauge" + }, + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "text", + "value": null + }, + { + "color": "dark-green", + "value": 45 + }, + { + "color": "#EAB839", + "value": 55 + }, + { + "color": "dark-orange", + "value": 65 + }, + { + "color": "dark-red", + "value": 75 + } + ] + }, + "unit": "celsius" + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 2, + "x": 6, + "y": 0 + }, + "id": 12, + "options": { + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true + }, + "pluginVersion": "9.2.1", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "editorMode": "code", + "expr": "temperature", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "Device Temperature", + "transparent": true, + "type": "gauge" + }, + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "dark-purple", + "value": null + }, + { + "color": "dark-red", + "value": 0.5 + }, + { + "color": "dark-orange", + "value": 0.7 + }, + { + "color": "#EAB839", + "value": 0.8 + }, + { + "color": "dark-green", + "value": 0.9 + } + ] + }, + "unit": "none" + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 2, + "x": 8, + "y": 0 + }, + "id": 15, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "9.2.1", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "editorMode": "code", + "expr": "pf", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "PowerFactor", + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "text", + "value": null + } + ] + }, + "unit": "watth" + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 3, + "x": 10, + "y": 0 + }, + "id": 2, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "9.2.1", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "editorMode": "code", + "expr": "energy_total", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "AC Energy produced", + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "fixed" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "text", + "value": null + } + ] + }, + "unit": "mHz" + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 3, + "x": 13, + "y": 0 + }, + "id": 27, + "options": { + "colorMode": "none", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "value" + }, + "pluginVersion": "9.2.1", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "editorMode": "code", + "expr": "frequency", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "AC Frequency", + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "displayName": "Panel 0", + "mappings": [], + "max": 400, + "min": 50, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "dark-red", + "value": null + }, + { + "color": "dark-orange", + "value": 150 + }, + { + "color": "#EAB839", + "value": 220 + }, + { + "color": "dark-green", + "value": 300 + } + ] + }, + "unit": "watt" + }, + "overrides": [] + }, + "gridPos": { + "h": 1, + "w": 8, + "x": 16, + "y": 0 + }, + "id": 23, + "options": { + "displayMode": "lcd", + "minVizHeight": 5, + "minVizWidth": 0, + "orientation": "horizontal", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showUnfilled": true, + "text": { + "titleSize": 11, + "valueSize": 11 + } + }, + "pluginVersion": "9.2.1", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "editorMode": "code", + "expr": "string_power{panel=\"panel_0\"}", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "transparent": true, + "type": "bargauge" + }, + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "displayName": "Panel 1", + "mappings": [], + "max": 400, + "min": 50, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "dark-red", + "value": null + }, + { + "color": "dark-orange", + "value": 150 + }, + { + "color": "#EAB839", + "value": 220 + }, + { + "color": "dark-green", + "value": 300 + } + ] + }, + "unit": "watt" + }, + "overrides": [] + }, + "gridPos": { + "h": 1, + "w": 8, + "x": 16, + "y": 1 + }, + "id": 24, + "options": { + "displayMode": "lcd", + "minVizHeight": 5, + "minVizWidth": 0, + "orientation": "horizontal", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showUnfilled": true, + "text": { + "titleSize": 11, + "valueSize": 11 + } + }, + "pluginVersion": "9.2.1", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "editorMode": "code", + "expr": "string_power{panel=\"panel_1\"}", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "transparent": true, + "type": "bargauge" + }, + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "displayName": "Panel 2", + "mappings": [], + "max": 400, + "min": 50, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "dark-red", + "value": null + }, + { + "color": "dark-orange", + "value": 150 + }, + { + "color": "#EAB839", + "value": 220 + }, + { + "color": "dark-green", + "value": 300 + } + ] + }, + "unit": "watt" + }, + "overrides": [] + }, + "gridPos": { + "h": 1, + "w": 8, + "x": 16, + "y": 2 + }, + "id": 25, + "options": { + "displayMode": "lcd", + "minVizHeight": 5, + "minVizWidth": 0, + "orientation": "horizontal", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showUnfilled": true, + "text": { + "titleSize": 11, + "valueSize": 11 + } + }, + "pluginVersion": "9.2.1", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "editorMode": "code", + "expr": "string_power{panel=\"panel_2\"}", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "transparent": true, + "type": "bargauge" + }, + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "displayName": "Panel 3", + "mappings": [], + "max": 400, + "min": 50, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "dark-red", + "value": null + }, + { + "color": "dark-orange", + "value": 150 + }, + { + "color": "#EAB839", + "value": 220 + }, + { + "color": "dark-green", + "value": 300 + } + ] + }, + "unit": "watt" + }, + "overrides": [] + }, + "gridPos": { + "h": 1, + "w": 8, + "x": 16, + "y": 3 + }, + "id": 26, + "options": { + "displayMode": "lcd", + "minVizHeight": 5, + "minVizWidth": 0, + "orientation": "horizontal", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showUnfilled": true, + "text": { + "titleSize": 11, + "valueSize": 11 + } + }, + "pluginVersion": "9.2.1", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "editorMode": "code", + "expr": "string_power{panel=\"panel_3\"}", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "transparent": true, + "type": "bargauge" + }, + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 18, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 1, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": true, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "volt" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 6, + "x": 0, + "y": 4 + }, + "id": 20, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": false + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "editorMode": "code", + "expr": "phase_voltage", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "AC Volt", + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 18, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 1, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": true, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "amp" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 6, + "x": 6, + "y": 4 + }, + "id": 21, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": false + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "editorMode": "code", + "expr": "phase_current", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "AC Ampere", + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 18, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 1, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": true, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "watt" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 6, + "x": 12, + "y": 4 + }, + "id": 22, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": false + }, + "tooltip": { + "mode": "multi", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "editorMode": "code", + "expr": "phase_power", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "AC Watt", + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 18, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 1, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": true, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "line+area" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "#EAB839", + "value": 50 + }, + { + "color": "red", + "value": 65 + } + ] + }, + "unit": "celsius" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 6, + "x": 18, + "y": 4 + }, + "id": 28, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": false + }, + "tooltip": { + "mode": "multi", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "editorMode": "code", + "expr": "temperature", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "Temperature", + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 10, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 1, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": true, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "amp" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 6, + "x": 0, + "y": 10 + }, + "id": 14, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": false + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "editorMode": "code", + "expr": "string_current{panel=~\"$panel\"}", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "DC Panel Ampere $panel", + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 13, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 1, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": true, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "volt" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 6, + "x": 6, + "y": 10 + }, + "id": 17, + "options": { + "legend": { + "calcs": [ + "last" + ], + "displayMode": "list", + "placement": "bottom", + "showLegend": false + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "editorMode": "code", + "expr": "string_voltage{panel=~\"$panel\"}", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "DC Panel Voltage $panel", + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 10, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 1, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": true, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "watt" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 6, + "x": 12, + "y": 10 + }, + "id": 16, + "options": { + "legend": { + "calcs": [ + "last" + ], + "displayMode": "list", + "placement": "bottom", + "showLegend": false + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "editorMode": "code", + "expr": "string_power{panel=~\"$panel\"}", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "DC Panel Watt $panel", + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 10, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 1, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": true, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "watth" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 6, + "x": 18, + "y": 10 + }, + "id": 18, + "options": { + "legend": { + "calcs": [ + "last" + ], + "displayMode": "list", + "placement": "bottom", + "showLegend": false + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "editorMode": "code", + "expr": "string_energy_daily{panel=~\"$panel\"}", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "DC Panel Energy Daily $panel", + "transparent": true, + "type": "timeseries" + } + ], + "refresh": "5m", + "schemaVersion": 37, + "style": "dark", + "tags": [], + "templating": { + "list": [ + { + "current": { + "selected": false, + "text": "All", + "value": "$__all" + }, + "datasource": { + "type": "prometheus", + "uid": "3oc1fUWgz" + }, + "definition": "label_values(panel)", + "hide": 0, + "includeAll": true, + "label": "panel", + "multi": false, + "name": "panel", + "options": [], + "query": { + "query": "label_values(panel)", + "refId": "StandardVariableQuery" + }, + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + } + ] + }, + "time": { + "from": "now-3h", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "Solar Energy", + "uid": "lq8Pf8ZRk", + "version": 34, + "weekStart": "" +} \ No newline at end of file diff --git a/tools/rpi/docker-supplementals/docker-compose.yml b/tools/rpi/docker-supplementals/docker-compose.yml new file mode 100644 index 000000000..308ef07d6 --- /dev/null +++ b/tools/rpi/docker-supplementals/docker-compose.yml @@ -0,0 +1,38 @@ +version: '3.3' + +services: + prometheus: + container_name: prometheus + image: prom/prometheus + volumes: + - ./prometheus:/etc/prometheus + networks: + hoymiles_net: + ipv4_address: 172.18.0.3 + ports: + - 9090:9090 + restart: always + + grafana: + container_name: grafana + image: grafana/grafana + ports: + - 3000:3000 + restart: always + volumes: + - grafana-storage:/var/lib/grafana + networks: + hoymiles_net: + ipv4_address: 172.18.0.2 + +volumes: + data: + grafana-storage: + +networks: + hoymiles_net: + ipam: + driver: default + config: + - subnet: "172.18.0.0/24" + diff --git a/tools/rpi/docker-supplementals/prometheus/prometheus.yml b/tools/rpi/docker-supplementals/prometheus/prometheus.yml new file mode 100644 index 000000000..36a35f27f --- /dev/null +++ b/tools/rpi/docker-supplementals/prometheus/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: hoymiles + honor_timestamps: true + scrape_interval: 15s + scrape_timeout: 10s + metrics_path: / + scheme: http + static_configs: + - targets: + - 172.18.0.1:9233 diff --git a/tools/rpi/hoymiles/__main__.py b/tools/rpi/hoymiles/__main__.py index 7de4a1a2e..e34ccc67f 100644 --- a/tools/rpi/hoymiles/__main__.py +++ b/tools/rpi/hoymiles/__main__.py @@ -243,12 +243,14 @@ def poll_inverter(inverter, dtu_ser, do_init, retries): if volkszaehler_client: volkszaehler_client.store_status(result) + if prometheus_client: + prometheus_client.store_status(result) + # check decoder object for output if isinstance(result, hoymiles.decoders.HardwareInfoResponse): if mqtt_client: mqtt_client.store_status(result, topic=inverter.get('mqtt', {}).get('topic', None)) - def mqtt_on_command(client, userdata, message): """ Handle commands to topic @@ -374,6 +376,14 @@ def init_logging(ahoy_config): bucket=influx_config.get('bucket', None), measurement=influx_config.get('measurement', 'hoymiles')) + # create prometheus - client object + prometheus_client = None + prometheus_config = ahoy_config.get('prometheus', {}) + if prometheus_config and not prometheus_config.get('disabled', False): + from .outputs import PrometheusOutputPlugin + prometheus_client = PrometheusOutputPlugin( + prometheus_config) + # create VOLKSZAEHLER - client object volkszaehler_client = None volkszaehler_config = ahoy_config.get('volkszaehler', {}) @@ -402,4 +412,3 @@ def init_logging(ahoy_config): # start main-loop main_loop(ahoy_config) - diff --git a/tools/rpi/hoymiles/outputs.py b/tools/rpi/hoymiles/outputs.py index 11971a856..a7c8e80a3 100644 --- a/tools/rpi/hoymiles/outputs.py +++ b/tools/rpi/hoymiles/outputs.py @@ -33,6 +33,78 @@ def store_status(self, response, **params): """ raise NotImplementedError('The current output plugin does not implement store_status') +try: + from os import path + import yaml + from prometheus_client.core import GaugeMetricFamily, REGISTRY, CounterMetricFamily + from prometheus_client import CollectorRegistry, Gauge + from prometheus_client import Info + from prometheus_client import start_http_server +except ModuleNotFoundError: + pass + +class PrometheusOutputPlugin(OutputPluginFactory): + current_data = None + + def __init__(self, config, **params): + super().__init__(**params) + + start_http_server(config.get('port')) + REGISTRY.register(self) + + def collect(self): + if self.current_data: + yield CounterMetricFamily('energy_total', 'Energy Total', value=self.current_data['energy_total']) + yield GaugeMetricFamily('temperature', 'Device Temperature', value=self.current_data['temperature']) + yield GaugeMetricFamily('pf', 'Power Factor', value=self.current_data['powerfactor']) + yield GaugeMetricFamily('frequency', 'Frequency', value=self.current_data['frequency']) + + # AC Data + phase_id = 0 + phase_gauge = {} + phase_types = [ 'power', 'voltage', 'current' ] + for phase_type in phase_types: + for phase in self.current_data['phases']: + phase_gauge[phase_type] = GaugeMetricFamily(f'phase_{phase_type}', f'AC/Phase {phase_id} Power', labels=['phase']) + phase_gauge[phase_type].add_metric(f'phase_{phase_id}', phase[phase_type]) + yield phase_gauge[phase_type] + phase_id = phase_id + 1 + + # DC Data + string_id = 0 + types = [ "voltage", "current", "power", "energy_daily" ] + + gauge={} + for string in self.current_data['strings']: + gauge['energy_total'] = CounterMetricFamily(f'string_energy_total', f'DC/Panel energy_total', labels=['panel']) + gauge['energy_total'].add_metric([f'panel_{string_id}'], string['energy_total']) + yield gauge['energy_total'] + for type in types: + gauge[type] = GaugeMetricFamily(f'string_{type}', f'DC/Panel {type}', labels=['panel']) + gauge[type].add_metric([f'panel_{string_id}'], string[type]) + yield gauge[type] + string_id = string_id + 1 + + def store_status(self, response, **params): + """ + Publish StatusResponse object + + :param hoymiles.decoders.StatusResponse response: StatusResponse object + :param topic: custom mqtt topic prefix (default: hoymiles/{inverter_ser}) + :type topic: str + + :raises ValueError: when response is not instance of StatusResponse + """ + + if not isinstance(response, StatusResponse): + raise ValueError('Data needs to be instance of StatusResponse') + + data = response.__dict__() + + self.current_data = response.__dict__() + serial = data["inverter_ser"] + self.collect() + class InfluxOutputPlugin(OutputPluginFactory): """ Influx2 output plugin """ api = None diff --git a/tools/rpi/optional-requirements.txt b/tools/rpi/optional-requirements.txt index 19297f02d..5e15dacaa 100644 --- a/tools/rpi/optional-requirements.txt +++ b/tools/rpi/optional-requirements.txt @@ -1 +1,2 @@ influxdb-client>=1.28.0 +prometheus_client diff --git a/tools/rpi/systemd/hoymiles.service b/tools/rpi/systemd/hoymiles.service new file mode 100644 index 000000000..cea0bbaae --- /dev/null +++ b/tools/rpi/systemd/hoymiles.service @@ -0,0 +1,14 @@ +[Unit] +Description=Hoymiles Exporter +After=network.target + +[Service] +WorkingDirectory=/home/rpi/hoymiles_exporter +ExecStart=/usr/bin/bash -c 'cd /home/rpi/hoymiles_exporter ; /usr/bin/python3 -um hoymiles --config ahoy.yml' +User=rpi +KillMode=process +Restart=on-failure + +[Install] +WantedBy=multi-user.target +Alias=hoymiles.service