Skip to content

Commit

Permalink
Merge pull request #41 from f18m/feature/github-ci
Browse files Browse the repository at this point in the history
Add Github CI pipeline for linting and docker publish
  • Loading branch information
eschava authored Apr 30, 2024
2 parents 5b47c3f + 974697c commit d93a7dd
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 86 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This workflow will build a Python project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python

on: [push]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint code with flake8
run: |
pip install flake8
flake8
# TODO: it would be nice to have the project published on Pypi for easy installation via pip:
#- name: Publish package
# uses: pypa/gh-action-pypi-publish@release/v1
# with:
# password: ${{ secrets.PYPI_API_TOKEN }}


- name: Build and push Docker image
uses: mr-smithers-excellent/docker-build-push@v6
with:
# options related to BUILDing the docker image:
dockerfile: ./Dockerfile
multiPlatform: true
platform: linux/amd64,linux/arm64,linux/arm/v7
image: psmqtt
# options related to PUSHing the docker image:
registry: ghcr.io
username: eschava
password: ${{ secrets.PAT_TOKEN_FOR_GITHUB }}
100 changes: 52 additions & 48 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,50 +1,9 @@
===============
About this fork
===============

I created this fork to allow psmqtt to run on my TerraMaster NAS.
Use it like this::

docker run -d -v <your config file>:/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
=======

**PSMQTT** is a cross-platform utility for reporting system and processes
metrics (CPU, memory, disks, network, smart disk data) to an MQTT broker.
metrics (CPU, memory, disks, network, S.M.A.R.T. disk data) to an MQTT broker.

**PSMQTT** is written in Python and is based on:

Expand All @@ -54,16 +13,48 @@ metrics (CPU, memory, disks, network, smart disk data) to an MQTT broker.
* `recurrent <https://github.com/kvh/recurrent>` to describe reporting schedule.
* `jinja2 <https://github.com/alex-foundation/jinja2>` to format the data.

============
Installation
============
Just install the required Python libraries using `pip <https://pip.pypa.io/en/stable/installing/>`_::
=====================
Installation with pip
=====================

Clone this repository and then install the required Python libraries using `pip <https://pip.pypa.io/en/stable/installing/>`_::

pip install -r requirements.txt

After you can run main file using::
(Note that you should consider installing the required libraries in a Python venv to maintain them isolated from the rest of your Python installation.
See `this page for more info <doc/debian.md>`_.)

Finally you can run **PSMQTT** using::

python psmqtt.py

You may want to install **PSMQTT** as a service/system-daemon, see `this page for more info <doc/service.md>`_.


=====================
Installing on FreeBSD
=====================

python psmqtt.py
See `FreeBSD doc <doc/freebsd.md>`_

=====================
Installing on Windows
=====================

See `Windows doc <doc/windows.md>`_


==================
Deploy with Docker
==================

**PSMQTT** is packaged also a multi-arch Docker image. If your system does not have Python3 installed or
you don't want to install **PSMQTT** Python dependencies in your environment, you can launch
a Docker container::

docker run -d -v <your config file>:/opt/psmqtt/conf/psmqtt.conf \
--privileged --hostname $(hostname) \
ghcr.io/eschava/psmqtt:latest


===============================================
Expand Down Expand Up @@ -367,3 +358,16 @@ Useful tasks
**smart/nvme0/** - all the device 'nvme0' SMART data, requries SUDO

**smart/nvme0/temperature** - 'nvme0' temperature, requires SUDO


======================
Creating a new release
======================

New docker releases will be automatically published by the GitHub CI whenever a new tag is released on the project.
Sometimes however it may be useful to publish a docker release manually.
To push manually a new multi-arch docker version, use::

docker buildx build --platform linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8, --tag ghcr.io/eschava/psmqtt:1.0.2 --build-arg USERNAME=root --push .

(remember to update the tag version)
File renamed without changes.
30 changes: 0 additions & 30 deletions doc/docker.md

This file was deleted.

12 changes: 6 additions & 6 deletions src/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,11 @@ class ProcessesCommandHandler(CommandHandler):
'''
'''

top_cpu_regexp = re.compile("^top_cpu(\[\d+\])*$")
top_memory_regexp = re.compile("^top_memory(\[\d+\])*$")
top_number_regexp = re.compile("^top_[a-z_]+\[(\d+)\]$")
pid_file_regexp = re.compile("^pid\[(.*)\]$")
name_pattern_regexp = re.compile("^name\[(.*)\]$")
top_cpu_regexp = re.compile(r"^top_cpu(\[\d+\])*$")
top_memory_regexp = re.compile(r"^top_memory(\[\d+\])*$")
top_number_regexp = re.compile(r"^top_[a-z_]+\[(\d+)\]$")
pid_file_regexp = re.compile(r"^pid\[(.*)\]$")
name_pattern_regexp = re.compile(r"^name\[(.*)\]$")

def __init__(self) -> None:
super().__init__('processes')
Expand Down Expand Up @@ -537,7 +537,7 @@ def handle(self, params:str) -> Payload:

info = self.device.__getstate__()
if params == '':
return string_from_dict_optionally(info, True) #params.endswith(';')
return string_from_dict_optionally(info, True)
elif params == '*':
return string_from_dict_optionally(info, False)
elif params == '*;':
Expand Down
4 changes: 2 additions & 2 deletions src/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def __init__(self,
self.qos = qos
self.retain = retain
# initialise MQTT broker connection
self.mqttc = paho.Client(paho.CallbackAPIVersion.VERSION1,
client_id, clean_session=clean_session, userdata=self,
self.mqttc = paho.Client(paho.CallbackAPIVersion.VERSION1,
client_id, clean_session=clean_session, userdata=self,
protocol=paho.MQTTv311)
# protocol=paho.MQTTv5
# see http://www.steves-internet-guide.com/python-mqtt-client-changes/
Expand Down

0 comments on commit d93a7dd

Please sign in to comment.