diff --git a/Dockerfile b/Dockerfile index 6e49043..12879ef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,7 @@ +# +# Builder docker +# + FROM public.ecr.aws/docker/library/python:3.11-alpine AS builder RUN apk add build-base linux-headers @@ -18,21 +22,42 @@ RUN rm -rf \ src/*_test.py \ psutil/tests + +# +# Production docker +# + FROM public.ecr.aws/docker/library/python:3.11-alpine -RUN apk add bash + +# when USERNAME=root is provided, the application runs as root within the container, this is useful in case 'pySMART' or any SMART attribute +# has been configured (smartctl requires root permissions) +ARG USERNAME=psmqtt + +LABEL org.opencontainers.image.source=https://github.com/f18m/psmqtt + +RUN apk add bash smartmontools WORKDIR /opt/psmqtt COPY --from=builder /build . + +RUN mkdir ./src COPY *.py ./ +COPY src/*.py ./src COPY psmqtt.service . COPY logging.conf . +RUN mkdir ./conf +COPY psmqtt.conf ./conf + # add user psmqtt to image -RUN addgroup -S psmqtt && adduser -S psmqtt -G psmqtt -RUN chown -R psmqtt:psmqtt /opt/psmqtt +RUN if [[ "$USERNAME" != "root" ]]; then \ + addgroup -S psmqtt && \ + adduser -S ${USERNAME} -G psmqtt && \ + chown -R ${USERNAME}:psmqtt /opt/psmqtt ; \ + fi # process run as psmqtt user -USER psmqtt +USER ${USERNAME} # set conf path ENV PSMQTTCONFIG="/opt/psmqtt/conf/psmqtt.conf" diff --git a/README.rst b/README.rst index 7707224..a050017 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,43 @@ -.. contents:: Table of Contents +=============== +About this fork +=============== + +I created this fork to allow psmqtt to run on my TerraMaster NAS. +Use it like this:: + + docker run -d -v :/opt/psmqtt/conf/psmqtt.conf \ + --privileged --hostname tnas \ + ghcr.io/f18m/psmqtt:1.0.2 + +Example of my psmqtt.conf:: + + mqtt_broker = '192.168.1.8' # default: 'localhost' + mqtt_username = 'psmqtt' + mqtt_password = 'psmqtt' + mqtt_clean_session = False + mqtt_qos = 0 + mqtt_retain = False + mqtt_request_topic = 'request' + + schedule = { + "every 5 sec": [ + "cpu_percent", + "virtual_memory/percent", + "sensors_temperatures/rtk_thermal/*", + 'smart/sdc/temperature', + 'smart/sdd/temperature', + ], + "every 60 minutes": "disk_usage/percent/|", # slash replaced with vertical slash + "every 3 hours": { + "boot_time/{{x|uptime}}": "uptime", + } + } + +To push a new docker version with architecture arm64, use:: + + docker buildx build --platform linux/arm64/v8 --tag ghcr.io/f18m/psmqtt:1.0.2 --build-arg USERNAME=root --push . + +(remember to update the tag version) ======= Summary @@ -11,7 +50,7 @@ metrics (CPU, memory, disks, network, smart disk data) to an MQTT broker. * `paho-mqtt ` to communicate with the MQTT broker; * `psutil ` to collect metrics; -* `pySMART ` to collect SMART data; +* `pySMART ` to collect SMART data; * `recurrent ` to describe reporting schedule. * `jinja2 ` to format the data. diff --git a/psmqtt.conf b/psmqtt.conf index dd3cdea..d966490 100644 --- a/psmqtt.conf +++ b/psmqtt.conf @@ -1,3 +1,8 @@ +# +# PSMQTT configuration file +# NOTE: this is actually imported as a Python file, so it's using Python syntax +# + #import socket mqtt_broker = 'mqtt' # default: 'localhost' diff --git a/requirements.txt b/requirements.txt index 7f40ec2..3234557 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,8 @@ -recurrent -paho-mqtt -python-dateutil -psutil -jinja2 -types-paho-mqtt -pySMART +recurrent>=0.4.1 +paho-mqtt>=1.6.1 +python-dateutil>=2.8.2 +psutil>=5.9.5 +jinja2>=3.1.3 +types-paho-mqtt>=1.6.0.20240321 +# pySMART>=1.3.1.dev8 is required, see https://github.com/truenas/py-SMART/issues/86 +pySMART>=1.3.1.dev8