Compare commits

21 Commits

Author SHA1 Message Date
Nick Trimborn
ed97c06180 updated dashboard
All checks were successful
Docker Push / build (push) Successful in 42s
2023-07-21 11:21:06 +02:00
b7bc47e2d5 Update metrics.py
All checks were successful
Docker Push / build (push) Successful in 40s
2023-07-20 13:32:20 +00:00
9ac6a3f7da Update metrics.py
All checks were successful
Docker Push / build (push) Successful in 40s
2023-07-20 13:29:51 +00:00
70e44a432c Update metrics.py
All checks were successful
Docker Push / build (push) Successful in 40s
2023-07-20 13:24:58 +00:00
cd2e65544e Update metrics.py
All checks were successful
Docker Push / build (push) Successful in 40s
2023-07-20 13:16:24 +00:00
Nick Trimborn
4e45eb26f4 added error handling back in
All checks were successful
Docker Push / build (push) Successful in 40s
2023-07-20 14:59:23 +02:00
Nick Trimborn
83dc893fbb updated port
All checks were successful
Docker Push / build (push) Successful in 39s
2023-07-20 14:47:16 +02:00
Nick Trimborn
00f5029972 updated to match fork
All checks were successful
Docker Push / build (push) Successful in 40s
2023-07-20 13:07:41 +02:00
Nick Trimborn
36c3489c55 updated workflow
All checks were successful
Docker Push / build (push) Successful in 39s
2023-07-20 11:16:49 +02:00
Nick Trimborn
9213b3900f updated workflow
Some checks failed
Docker Push / build (push) Failing after 32s
2023-07-20 11:13:55 +02:00
Nick Trimborn
c227745639 update meta to match x.x version numbering
Some checks failed
Docker Push / build (push) Failing after 29s
2023-07-20 11:09:34 +02:00
Nick Trimborn
d0fd783e5f updated workflow
Some checks failed
Docker Push / build (push) Failing after 28s
2023-07-20 10:59:04 +02:00
Nick Trimborn
4dc2220ed6 updated workflow
All checks were successful
Docker Push / build (push) Successful in 1m7s
2023-07-20 10:53:37 +02:00
385dd54468 Update .github/workflows/docker-deploy.yaml
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 11s
Docker Push / build (push) Successful in 1m7s
2023-07-20 08:26:43 +00:00
8f2f0db9da Update .github/workflows/docker-deploy.yaml
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 11s
Docker Push / build (push) Successful in 1m7s
2023-07-20 08:23:38 +00:00
97342b3bab Update .github/workflows/docker-deploy.yaml
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 11s
Docker Push / build (push) Failing after 56s
2023-07-20 08:13:57 +00:00
be1bac4d9b updated repo
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 11s
Docker Push / build (push) Successful in 1m7s
2023-07-19 20:02:00 +02:00
f7c499c964 fixed indent
Some checks failed
Docker Push / build (push) Failing after 1m13s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 10s
2023-07-19 19:50:59 +02:00
02d81ce818 fixed indent error
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 11s
2023-07-19 19:48:21 +02:00
e6144a8b99 Merge branch 'main' of https://git.nicktrimborn.de/Nick/tasmota-power-exporter
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 11s
2023-07-19 19:44:41 +02:00
d7ff1fa0bc updated workflow for personal gitea registry 2023-07-19 19:43:45 +02:00
6 changed files with 1472 additions and 1296 deletions

66
.github/workflows/docker-deploy.yaml vendored Normal file
View File

@@ -0,0 +1,66 @@
name: Docker Push
on:
push:
branches:
- 'main'
tags:
- 'v*'
pull_request:
branches:
- 'main'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
# - name: Install cosign
# if: github.event_name != 'pull_request'
# uses: sigstore/cosign-installer@f3c664df7af409cb4873aa5068053ba9d61a57b6 #v2.6.0
# with:
# cosign-release: 'v1.13.1'
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: git.nicktrimborn.de
username: ${{ secrets.ACTION_USER }}
password: ${{ secrets.PASSWORD }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
git.nicktrimborn.de/nick/tasmota-power-exporter
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: |
git.nicktrimborn.de/nick/tasmota-power-exporter:latest
${{ steps.meta.outputs.tags }}
#tags: ${{ steps.meta.outputs.tags }}
#tags: git.nicktrimborn.de/nick/tasmota-power-exporter/tasmota-power-exporter:latest
labels: ${{ steps.meta.outputs.labels }}

View File

@@ -1,4 +1,47 @@
{
"__inputs": [
{
"name": "DS_PROMETHEUS",
"label": "Prometheus",
"description": "",
"type": "datasource",
"pluginId": "prometheus",
"pluginName": "Prometheus"
}
],
"__elements": {},
"__requires": [
{
"type": "panel",
"id": "bargauge",
"name": "Bar gauge",
"version": ""
},
{
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"version": "9.4.3"
},
{
"type": "datasource",
"id": "prometheus",
"name": "Prometheus",
"version": "1.0.0"
},
{
"type": "panel",
"id": "stat",
"name": "Stat",
"version": ""
},
{
"type": "panel",
"id": "timeseries",
"name": "Time series",
"version": ""
}
],
"annotations": {
"list": [
{
@@ -28,14 +71,14 @@
"fiscalYearStartMonth": 0,
"gnetId": 13950,
"graphTooltip": 0,
"id": 9,
"id": null,
"links": [],
"liveNow": false,
"panels": [
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"fieldConfig": {
"defaults": {
@@ -95,29 +138,33 @@
},
"textMode": "value"
},
"pluginVersion": "8.5.0",
"pluginVersion": "9.4.3",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"exemplar": true,
"expr": "tasmota_power_W{}",
"expr": "tasmota_active_power_W{job=~\"$job\"}",
"interval": "",
"legendFormat": "power_W",
"range": true,
"refId": "A"
},
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"exemplar": true,
"expr": "tasmota_current_A{}",
"expr": "tasmota_current_A{job=~\"$job\"}",
"hide": false,
"interval": "",
"legendFormat": "current_A",
"range": true,
"refId": "B"
}
],
@@ -128,7 +175,7 @@
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"fieldConfig": {
"defaults": {
@@ -187,29 +234,33 @@
},
"textMode": "value"
},
"pluginVersion": "8.5.0",
"pluginVersion": "9.4.3",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"exemplar": true,
"expr": "avg_over_time(tasmota_power_W{}[$__range])",
"expr": "avg_over_time(tasmota_active_power_W{job=~\"$job\"}[$__range])",
"interval": "",
"legendFormat": "power_W",
"range": true,
"refId": "A"
},
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"exemplar": true,
"expr": "avg_over_time(tasmota_current_A{}[$__range])",
"expr": "avg_over_time(tasmota_current_A{job=~\"$job\"}[$__range])",
"hide": false,
"interval": "",
"legendFormat": "current_A",
"range": true,
"refId": "B"
}
],
@@ -220,7 +271,7 @@
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"fieldConfig": {
"defaults": {
@@ -263,17 +314,19 @@
"text": {},
"textMode": "auto"
},
"pluginVersion": "8.5.0",
"pluginVersion": "9.4.3",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"exemplar": true,
"expr": "delta(tasmota_energy_kWh_total[$__range])",
"expr": "delta(tasmota_energy_kWh_total{job=~\"$job\"}[$__range])",
"interval": "",
"legendFormat": "",
"range": true,
"refId": "A"
}
],
@@ -284,7 +337,7 @@
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"fieldConfig": {
"defaults": {
@@ -332,17 +385,19 @@
"text": {},
"textMode": "auto"
},
"pluginVersion": "8.5.0",
"pluginVersion": "9.4.3",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"exemplar": true,
"expr": "delta(tasmota_energy_kWh_total[$__range]) * .098",
"expr": "delta(tasmota_energy_kWh_total{job=~\"$job\"}[$__range]) * .276",
"interval": "",
"legendFormat": "",
"range": true,
"refId": "A"
}
],
@@ -353,7 +408,7 @@
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"fieldConfig": {
"defaults": {
@@ -396,18 +451,20 @@
"text": {},
"textMode": "auto"
},
"pluginVersion": "8.5.0",
"pluginVersion": "9.4.3",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"exemplar": true,
"expr": "delta(tasmota_energy_kWh_total[$__range])",
"expr": "delta(tasmota_energy_kWh_total{job=~\"$job\"}[$__range])",
"format": "time_series",
"interval": "",
"legendFormat": "",
"range": true,
"refId": "A"
}
],
@@ -418,7 +475,7 @@
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"fieldConfig": {
"defaults": {
@@ -477,17 +534,19 @@
"text": {},
"textMode": "value"
},
"pluginVersion": "8.5.0",
"pluginVersion": "9.4.3",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"exemplar": true,
"expr": "delta(tasmota_energy_kWh_total[$__range])*.098",
"expr": "delta(tasmota_energy_kWh_total{job=~\"$job\"}[$__range])*.276",
"interval": "",
"legendFormat": "",
"range": true,
"refId": "A"
}
],
@@ -499,7 +558,7 @@
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"fieldConfig": {
"defaults": {
@@ -542,18 +601,20 @@
"text": {},
"textMode": "auto"
},
"pluginVersion": "8.5.0",
"pluginVersion": "9.4.3",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"exemplar": true,
"expr": "delta(tasmota_energy_kWh_total[$__range])",
"expr": "delta(tasmota_energy_kWh_total{job=~\"$job\"}[$__range])",
"format": "time_series",
"interval": "",
"legendFormat": "",
"range": true,
"refId": "A"
}
],
@@ -564,7 +625,7 @@
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"fieldConfig": {
"defaults": {
@@ -623,17 +684,19 @@
"text": {},
"textMode": "value"
},
"pluginVersion": "8.5.0",
"pluginVersion": "9.4.3",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"exemplar": true,
"expr": "delta(tasmota_energy_kWh_total[$__range])*.098",
"expr": "delta(tasmota_energy_kWh_total{job=~\"$job\"}[$__range])*.276",
"interval": "",
"legendFormat": "",
"range": true,
"refId": "A"
}
],
@@ -645,7 +708,7 @@
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"fieldConfig": {
"defaults": {
@@ -704,29 +767,33 @@
},
"textMode": "value"
},
"pluginVersion": "8.5.0",
"pluginVersion": "9.4.3",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"exemplar": true,
"expr": "max_over_time(tasmota_power_W{}[$__range])",
"expr": "max_over_time(tasmota_active_power_W{job=~\"$job\"}[$__range])",
"interval": "",
"legendFormat": "power_W",
"range": true,
"refId": "A"
},
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"exemplar": true,
"expr": "max_over_time(tasmota_current_A{}[$__range])",
"expr": "max_over_time(tasmota_current_A{job=~\"$job\"}[$__range])",
"hide": false,
"interval": "",
"legendFormat": "current_A",
"range": true,
"refId": "B"
}
],
@@ -737,7 +804,7 @@
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"fieldConfig": {
"defaults": {
@@ -784,17 +851,19 @@
},
"textMode": "auto"
},
"pluginVersion": "8.5.0",
"pluginVersion": "9.4.3",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"exemplar": true,
"expr": "max_over_time(tasmota_voltage_V{}[$__range])",
"expr": "max_over_time(tasmota_voltage_V{job=~\"$job\"}[$__range])",
"interval": "",
"legendFormat": "",
"range": true,
"refId": "A"
}
],
@@ -805,7 +874,7 @@
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"fieldConfig": {
"defaults": {
@@ -851,17 +920,19 @@
},
"textMode": "auto"
},
"pluginVersion": "8.5.0",
"pluginVersion": "9.4.3",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"exemplar": true,
"expr": "max_over_time(tasmota_energy_today_kWh_total{}[$__range])",
"expr": "max_over_time(tasmota_energy_today_kWh_total{job=~\"$job\"}[$__range])",
"interval": "",
"legendFormat": "",
"range": true,
"refId": "A"
}
],
@@ -872,7 +943,7 @@
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"description": "",
"fieldConfig": {
@@ -881,6 +952,8 @@
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
@@ -952,7 +1025,8 @@
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom"
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
@@ -964,13 +1038,15 @@
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"exemplar": true,
"expr": "tasmota_power_W{}",
"expr": "tasmota_active_power_W{job=~\"$job\"}",
"format": "time_series",
"interval": "",
"legendFormat": "{{ device }}",
"range": true,
"refId": "A"
}
],
@@ -982,7 +1058,7 @@
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"fieldConfig": {
"defaults": {
@@ -1033,15 +1109,16 @@
"showUnfilled": true,
"text": {}
},
"pluginVersion": "8.5.0",
"pluginVersion": "9.4.3",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"exemplar": true,
"expr": "delta(tasmota_energy_kWh_total[$__range])",
"expr": "delta(tasmota_energy_kWh_total{job=~\"$job\"}[$__range])",
"format": "table",
"instant": false,
"interval": "",
@@ -1057,7 +1134,7 @@
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"description": "",
"fieldConfig": {
@@ -1066,6 +1143,8 @@
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
@@ -1138,7 +1217,8 @@
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom"
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
@@ -1150,7 +1230,7 @@
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"exemplar": true,
"expr": "tasmota_energy_today_kWh_total{}",
@@ -1168,7 +1248,7 @@
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"fieldConfig": {
"defaults": {
@@ -1176,6 +1256,8 @@
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
@@ -1234,7 +1316,8 @@
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom"
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
@@ -1246,12 +1329,14 @@
{
"datasource": {
"type": "prometheus",
"uid": "XOGiKiT7k"
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"exemplar": true,
"expr": "rate(tasmota_power_W[1h])",
"expr": "rate(tasmota_active_power_W{job=~\"$job\"}[1h])",
"interval": "",
"legendFormat": " Rate of Power",
"range": true,
"refId": "A"
}
],
@@ -1260,12 +1345,38 @@
"type": "timeseries"
}
],
"refresh": "10s",
"schemaVersion": 36,
"refresh": "5s",
"revision": 1,
"schemaVersion": 38,
"style": "dark",
"tags": [],
"templating": {
"list": []
"list": [
{
"current": {},
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"definition": "label_values(job)",
"description": "variable to filter plugs by job",
"hide": 0,
"includeAll": true,
"label": "Job",
"multi": false,
"name": "job",
"options": [],
"query": {
"query": "label_values(job)",
"refId": "StandardVariableQuery"
},
"refresh": 1,
"regex": "/^tasmota-/",
"skipUrlSync": false,
"sort": 0,
"type": "query"
}
]
},
"time": {
"from": "now-30d",
@@ -1290,6 +1401,6 @@
"timezone": "",
"title": "Tasmota Plug Usage",
"uid": "_nyxoAfMk3",
"version": 33,
"version": 10,
"weekStart": ""
}

View File

@@ -5,14 +5,15 @@ from os import getenv
from time import sleep
from prometheus_client.core import GaugeMetricFamily, REGISTRY, CounterMetricFamily
from prometheus_client import start_http_server
from loguru import logger
class TasmotaCollector(object):
def __init__(self):
self.ip = getenv('DEVICE_IP')
logger.info("Env variable from DEVICE_NAME used is: " + self.ip)
self.device_name = getenv("DEVICE_NAME").lower()
if not self.ip:
self.ip = "192.168.4.1"
logger.info("Env variable from DEVICE_NAME used is: " + self.device_name)
self.user = getenv('USER')
self.password = getenv('PASSWORD')
@@ -21,7 +22,7 @@ class TasmotaCollector(object):
response = self.fetch()
for key in response:
metric_name = self.device_name + "_" + key.lower().replace(" ", "_")
metric_name = "tasmota_" + key.lower().replace(" ", "_")
metric = response[key].split()[0]
unit = None
if len(response[key].split()) > 1:
@@ -37,7 +38,7 @@ class TasmotaCollector(object):
def fetch(self):
url = 'http://' + self.ip + '/?m=1'
logger.info("Getting Metrics from: " + url)
session = requests.Session()
if self.user and self.password:
@@ -70,12 +71,9 @@ signal.signal(signal.SIGINT, signal_handler)
if __name__ == '__main__':
port = getenv('EXPORTER_PORT')
if not port:
port = 8000
logger.info("Starting HTTP server on port: " + port)
start_http_server(int(port))
REGISTRY.register(TasmotaCollector())
while(True):
sleep(1)

View File

@@ -1,2 +1,3 @@
prometheus_client
requests
loguru