Compare commits

..

No commits in common. "main" and "v0.1" have entirely different histories.
main ... v0.1

8 changed files with 1355 additions and 1601 deletions

View File

@ -1,19 +0,0 @@
name: Gitea Actions Demo
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
on: [push]
jobs:
Explore-Gitea-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!"
- run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
- run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ gitea.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."

View File

@ -1,66 +0,0 @@
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 }}

58
.github/workflows/docker-publish.yml vendored Normal file
View File

@ -0,0 +1,58 @@
name: Docker
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v1
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v2
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ghcr.io/astr0n8t/tasmota-power-exporter:latest
platforms: linux/arm/v7,linux/arm64/v8,linux/amd64

View File

@ -1,106 +0,0 @@
name: Docker
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
on:
schedule:
- cron: '41 11 * * 0'
push:
branches: [ "main" ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches: [ "main" ]
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout repository
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
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: |
ghcr.io/astr0n8t/tasmota-power-exporter:latest
${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/arm/v7,linux/arm64/v8,linux/amd64
# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
COSIGN_EXPERIMENTAL: "true"
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign {}@${{ steps.build-and-push.outputs.digest }}

View File

@ -1,10 +1,9 @@
FROM python:alpine
RUN apk add --no-cache tini
ADD metrics.py /app/metrics.py
ADD requirements.txt /tmp/requirements.txt
RUN pip install -r /tmp/requirements.txt && \
rm -rf /tmp/requirements.txt
ADD metrics.py /metrics.py
ADD requirements.txt /requirements.txt
RUN pip install -r /requirements.txt
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["python" , "/app/metrics.py"]
CMD ["python" , "/metrics.py"]

View File

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

View File

@ -5,15 +5,13 @@ 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()
logger.info("Env variable from DEVICE_NAME used is: " + self.device_name)
if not self.ip:
self.ip = "192.168.4.1"
self.user = getenv('USER')
self.password = getenv('PASSWORD')
@ -38,7 +36,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:
@ -55,8 +53,7 @@ class TasmotaCollector(object):
label = string_values[i].split("{m}")[0]
value = string_values[i].split("{m}")[1].split("{e}")[0]
if "<td" in value:
value = value.replace("</td><td style='text-align:left'>", "")
value = value.replace("</td><td>&nbsp;</td><td>", "")
value = value.replace("</td><td style='text-align:left'>", "").split("</td>")[0]
values[label] = value
except IndexError:
@ -71,9 +68,12 @@ signal.signal(signal.SIGINT, signal_handler)
if __name__ == '__main__':
port = getenv('EXPORTER_PORT')
logger.info("Starting HTTP server on port: " + port)
if not port:
port = 8000
start_http_server(int(port))
REGISTRY.register(TasmotaCollector())
while(True):
sleep(1)

View File

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