Compare commits
30 Commits
Author | SHA1 | Date |
---|---|---|
|
ed97c06180 | |
|
b7bc47e2d5 | |
|
9ac6a3f7da | |
|
70e44a432c | |
|
cd2e65544e | |
|
4e45eb26f4 | |
|
83dc893fbb | |
|
00f5029972 | |
|
36c3489c55 | |
|
9213b3900f | |
|
c227745639 | |
|
d0fd783e5f | |
|
4dc2220ed6 | |
|
385dd54468 | |
|
8f2f0db9da | |
|
97342b3bab | |
|
be1bac4d9b | |
|
f7c499c964 | |
|
02d81ce818 | |
|
e6144a8b99 | |
|
d7ff1fa0bc | |
|
547c294f11 | |
|
2d16d728ab | |
|
3877e91c1b | |
|
5985b2f5e3 | |
|
099f7894ff | |
|
e56a3d6a5f | |
|
2ab8a8402d | |
|
5d4c9662d9 | |
|
5631de230d |
|
@ -0,0 +1,19 @@
|
|||
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 }}."
|
|
@ -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 }}
|
|
@ -1,58 +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:
|
||||
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
|
|
@ -0,0 +1,106 @@
|
|||
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 }}
|
|
@ -1,9 +1,10 @@
|
|||
FROM python:alpine
|
||||
RUN apk add --no-cache tini
|
||||
|
||||
ADD metrics.py /metrics.py
|
||||
ADD requirements.txt /requirements.txt
|
||||
RUN pip install -r /requirements.txt
|
||||
ADD metrics.py /app/metrics.py
|
||||
ADD requirements.txt /tmp/requirements.txt
|
||||
RUN pip install -r /tmp/requirements.txt && \
|
||||
rm -rf /tmp/requirements.txt
|
||||
|
||||
ENTRYPOINT ["/sbin/tini", "--"]
|
||||
CMD ["python" , "/metrics.py"]
|
||||
CMD ["python" , "/app/metrics.py"]
|
||||
|
|
2685
grafana.json
2685
grafana.json
File diff suppressed because it is too large
Load Diff
16
metrics.py
16
metrics.py
|
@ -5,13 +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')
|
||||
if not self.ip:
|
||||
self.ip = "192.168.4.1"
|
||||
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)
|
||||
self.user = getenv('USER')
|
||||
self.password = getenv('PASSWORD')
|
||||
|
||||
|
@ -36,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:
|
||||
|
@ -53,7 +55,8 @@ 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'>", "").split("</td>")[0]
|
||||
value = value.replace("</td><td style='text-align:left'>", "")
|
||||
value = value.replace("</td><td> </td><td>", "")
|
||||
|
||||
values[label] = value
|
||||
except IndexError:
|
||||
|
@ -68,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)
|
||||
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
prometheus_client
|
||||
requests
|
||||
requests
|
||||
loguru
|
Loading…
Reference in New Issue