From cd58b6310f5b1728a8ac4246c48dd508960c3ec1 Mon Sep 17 00:00:00 2001 From: Markham Lee Date: Mon, 1 Apr 2024 17:20:15 -0700 Subject: [PATCH] Updated Rockchip3588 monitoring: refined Dockerfile, code refactoring to use shared files --- .../influx_client.py | 14 +------- hardware_monitoring/rockchip3588/Dockerfile | 27 ++++++++++++++ .../rockchip3588/container/Dockerfile | 8 ----- .../rockchip3588/{container => }/main.py | 36 ++++++++----------- .../{container => }/requirements.txt | 0 .../{container => }/rockchip_3588.py | 0 6 files changed, 42 insertions(+), 43 deletions(-) rename hardware_monitoring/{rockchip3588/container => hw_monitoring_libraries}/influx_client.py (78%) create mode 100644 hardware_monitoring/rockchip3588/Dockerfile delete mode 100644 hardware_monitoring/rockchip3588/container/Dockerfile rename hardware_monitoring/rockchip3588/{container => }/main.py (75%) rename hardware_monitoring/rockchip3588/{container => }/requirements.txt (100%) rename hardware_monitoring/rockchip3588/{container => }/rockchip_3588.py (100%) diff --git a/hardware_monitoring/rockchip3588/container/influx_client.py b/hardware_monitoring/hw_monitoring_libraries/influx_client.py similarity index 78% rename from hardware_monitoring/rockchip3588/container/influx_client.py rename to hardware_monitoring/hw_monitoring_libraries/influx_client.py index 355c901..d45b5c6 100644 --- a/hardware_monitoring/rockchip3588/container/influx_client.py +++ b/hardware_monitoring/hw_monitoring_libraries/influx_client.py @@ -4,21 +4,9 @@ # convert the payload that's appended to the base to json, otherwise you # will DB write errors. The standard data = {"key": "value"} Python dict # is fine. - -import logging +from hw_monitoring_libraries.logging_util import logger from influxdb_client import InfluxDBClient # noqa E402 from influxdb_client.client.write_api import SYNCHRONOUS # noqa E402 -from sys import stdout - -# set up/configure logging with stdout so it can be picked up by K8s -logger = logging.getLogger('utilities_logger') -logger.setLevel(logging.DEBUG) - -handler = logging.StreamHandler(stdout) -handler.setLevel(logging.DEBUG) -formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(filename)s - %(message)s') # noqa: E501 -handler.setFormatter(formatter) -logger.addHandler(handler) class InfluxClient(): diff --git a/hardware_monitoring/rockchip3588/Dockerfile b/hardware_monitoring/rockchip3588/Dockerfile new file mode 100644 index 0000000..029d14d --- /dev/null +++ b/hardware_monitoring/rockchip3588/Dockerfile @@ -0,0 +1,27 @@ +# temp stage +FROM python:3.12.2-slim as build + +WORKDIR /app + +RUN apt-get update -y && apt-get install -y gcc python3-dev + +COPY /hw_monitoring_libraries/requirements.txt . + +RUN pip wheel --no-cache-dir --no-deps --wheel-dir /app/wheels -r requirements.txt + + +# final stage +FROM python:3.12-slim + +COPY ./hw_monitoring_libraries ./hw_monitoring_libraries + +WORKDIR /hw_telemetry + +COPY --from=builder /app/wheels /wheels +COPY --from=builder /app/requirements.txt . + +RUN pip install --no-cache /wheels/* + +COPY ./rockchip3588 ./ + +ENTRYPOINT ["python3", "/hw_telemetry/main.py"] \ No newline at end of file diff --git a/hardware_monitoring/rockchip3588/container/Dockerfile b/hardware_monitoring/rockchip3588/container/Dockerfile deleted file mode 100644 index 084da5d..0000000 --- a/hardware_monitoring/rockchip3588/container/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM python:3.12.2-slim as build - -RUN apt-get update -y && apt-get install -y gcc python3-dev - -COPY requirements.txt rockchip_3588.py main.py influx_client.py / -RUN pip install -r /requirements.txt - -CMD python3 main.py \ No newline at end of file diff --git a/hardware_monitoring/rockchip3588/container/main.py b/hardware_monitoring/rockchip3588/main.py similarity index 75% rename from hardware_monitoring/rockchip3588/container/main.py rename to hardware_monitoring/rockchip3588/main.py index 2279a4d..04e125b 100644 --- a/hardware_monitoring/rockchip3588/container/main.py +++ b/hardware_monitoring/rockchip3588/main.py @@ -1,31 +1,23 @@ -#!/usr/bin/env python # Markham Lee (C) 2023 - 2024 -# K3s-Data-Platform-IoT -# https://github.com/MarkhamLee/kubernetes-k3s-data-platform-IoT -# This script "should work" on any device running a Rockchip 3588 -# System on Chip (SOC). But it was specifically built and tested on -# an Orange Pi 5 Plus Running Joshua Riek's Ubuntu Distro for -# RockChip 3588 Devices: -# https://github.com/Joshua-Riek/ubuntu-rockchip - - -import time +# kubernetes-k3s-data-and-IoT-platform +# https://github.com/MarkhamLee/kubernetes-k3s-data-and-IoT-platform +# HW monitoring Script for an Orange Pi 5+, meant to extend the +# monitoring capabilities in K8s, tracking: CPU, NVME and GPU temps +# & utilization data. This script "should work" on any device running +# a Rockchip 3588 System on Chip (SOC). But it was specifically built and +# tested on an Orange Pi 5 Plus Running Joshua Riek's Ubuntu Distro for +# RockChip 3588 Devices: https://github.com/Joshua-Riek/ubuntu-rockchip import gc import os -import logging -from sys import stdout +import sys +import time from rockchip_3588 import RockChipData -from influx_client import InfluxClient -# set up/configure logging with stdout so it can be picked up by K8s -logger = logging.getLogger('rockchip_telemetry_logger') -logger.setLevel(logging.DEBUG) +parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +sys.path.append(parent_dir) -handler = logging.StreamHandler(stdout) -handler.setLevel(logging.DEBUG) -formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(filename)s - %(message)s') # noqa: E501 -handler.setFormatter(formatter) -logger.addHandler(handler) +from hw_monitoring_libraries.logging_util import logger # noqa: E402 +from hw_monitoring_libraries.influx_client import InfluxClient # noqa: E402 # instantiate InfluxDB class influxdb_write = InfluxClient() diff --git a/hardware_monitoring/rockchip3588/container/requirements.txt b/hardware_monitoring/rockchip3588/requirements.txt similarity index 100% rename from hardware_monitoring/rockchip3588/container/requirements.txt rename to hardware_monitoring/rockchip3588/requirements.txt diff --git a/hardware_monitoring/rockchip3588/container/rockchip_3588.py b/hardware_monitoring/rockchip3588/rockchip_3588.py similarity index 100% rename from hardware_monitoring/rockchip3588/container/rockchip_3588.py rename to hardware_monitoring/rockchip3588/rockchip_3588.py