Compare commits

...
2 Commits
Author SHA1 Message Date
Obbart 5fd3f0f08e Merge branch 'main' into projmon 2026-08-24 11:04:13 +02:00
Obbart 4999fd2832 Added hwmon 2026-08-13 16:05:40 +02:00
4 changed files with 147 additions and 0 deletions
+2
View File
@@ -5,11 +5,13 @@ GIT_HASH=$(git rev-parse --short HEAD)
cp ../pyutils/utils.py ../upsmon/
cp ../pyutils/utils.py ../routermon/
cp ../pyutils/utils.py ../projmon/
cp ../pyutils/utils.py ../hwmon/
docker compose build --build-arg BUILD_VER=${GIT_HASH}
rm ../upsmon/utils.py
rm ../routermon/utils.py
rm ../projmon/utils.py
rm ../hwmon/utils.py
docker compose up -d
+47
View File
@@ -97,6 +97,53 @@ services:
- LOG_FILE=/tmp/routermon.log
- LOG_FILE_LVL=WARNING
- LOG_CLI_LVL=INFO
hwmon:
build:
context: ../hwmon
dockerfile: ../hwmon/hwmon.Dockerfile
args:
BUILD_VER:
#image: upsmon:influx3
container_name: edx-hwmon
restart: unless-stopped
depends_on:
- influxdb3
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "5"
environment:
- INTERVAL=5
- INFLUXDB_TOKEN=apiv3_tbEpA8JmIRTfr8Wbw9npD79BcMlFsnV4_jhdt-CdUP53Mos61KBODGaggl2g5oKZZvZrZu3e6mpob6zorhEdbg
- INFLUXDB_URL=http://influxdb3:8181
- INFLUXDB_DATABASE=edelweiss30d
- LOG_FILE=/tmp/hwmon.log
- LOG_FILE_LVL=WARNING
- LOG_CLI_LVL=INFO
# unifi-controller:
# image: lscr.io/linuxserver/unifi-controller:latest
# container_name: edx-unifi
# environment:
# - PUID=1000
# - PGID=1000
# - MEM_LIMIT=1024 #optional
# - MEM_STARTUP=1024 #optional
# volumes:
# - /var/lib/unifi:/config
# ports:
# - 8443:8443
# - 3478:3478/udp
# - 10001:10001/udp
# - 8080:8080
# - 1900:1900/udp #optional
# - 8843:8843 #optional
# - 8880:8880 #optional
# - 6789:6789 #optional
# - 5514:5514/udp #optional
# projmon:
# build:
# context: ../projmon
+12
View File
@@ -0,0 +1,12 @@
FROM python:3.12-alpine
ARG BUILD_VER
RUN apk update && apk upgrade --no-cache
RUN pip install --no-cache-dir psutil influxdb3-python
COPY ./hwmon.py /home/hwmon.py
COPY ./utils.py /home/pyutils/utils.py
ENV VER=${BUILD_VER}
CMD [ "python", "/home/hwmon.py" ]
+86
View File
@@ -0,0 +1,86 @@
import os
import logging
import sys
import time
import psutil
from pyutils.utils import *
from influxdb_client_3 import InfluxDBClient3, Point
# Get environment variables
env = dict(os.environ)
LOGGER: logging.Logger
def main():
INTERVAL = int(env['INTERVAL'])
try:
# Init InfluxDB-v3 Client
write_client = InfluxDBClient3(host=env['INFLUXDB_URL'],
token=env['INFLUXDB_TOKEN'],
database=env['INFLUXDB_DATABASE'])
except Exception as e:
LOGGER.error(e)
return 1
finally:
LOGGER.info(f"InfluxDB Connected: [{env['INFLUXDB_URL']}/{env['INFLUXDB_DATABASE']}]")
##############################
########## MAIN LOOP #########
##############################
handler: SignalHandler = SignalHandler(LOGGER)
while handler.running:
try:
p: Point = Point("hwmon").tag("host", "edelweiss-srv")
for i, cpu_percent in enumerate(psutil.cpu_percent(interval=INTERVAL, percpu=True)):
p.field(f"cpu_{i}", cpu_percent)
p.field("temp", psutil.sensors_temperatures()['k10temp'][0].current)
p.field("ram", psutil.virtual_memory().percent)
write_client.write(p)
LOGGER.debug(f"HW Stats: {p.to_line_protocol()}")
except psutil.Error as e:
LOGGER.error(e)
write_client.close()
time.sleep(10)
return 1
except KeyboardInterrupt:
LOGGER.info("Exiting Loop...")
write_client.close()
return 0
except:
LOGGER.error("An unexpected error occurred")
write_client.close()
time.sleep(10.0)
return 1
#### MAIN LOOP ####
if __name__ == "__main__":
# Logger Constants
LOG_FORMAT = '%(asctime)s| %(levelname)-7s|%(funcName)-10s|%(lineno)-3d: %(message)-50s'
# Enabling Logger
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG)
LOGGER.propagate = False
formatter = logging.Formatter(LOG_FORMAT, None)
levels = logging.getLevelNamesMapping()
# File logging
log_name = os.path.abspath(env['LOG_FILE'])
fh = logging.FileHandler(log_name)
fh.setLevel(levels[env['LOG_FILE_LVL']])
fh.setFormatter(formatter)
LOGGER.addHandler(fh)
# Console logging
cl = logging.StreamHandler(sys.stdout)
cl.setLevel(levels[env['LOG_CLI_LVL']])
cl.setFormatter(formatter)
LOGGER.addHandler(cl)
LOGGER.warning(f"Routermon started on: {time.asctime()}")
LOGGER.info(f"Routermon BUILD: {env.get("VER", "Test")}")
while main():
LOGGER.error("Main thread exited unexpectedly")
time.sleep(15)
sys.exit(0)