Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • stustanet/temperature-daemon
  • roman/temperature-daemon
  • 007638/temperature-daemon
3 results
Show changes
Commits on Source (11)
default: default:
image: debian-python-build:v2 image: debian-build-python:bullseye
# Is performed before the scripts in the stages step # Is performed before the scripts in the stages step
before_script: before_script:
...@@ -16,22 +16,22 @@ before_script: ...@@ -16,22 +16,22 @@ before_script:
# Defines stages which are to be executed # Defines stages which are to be executed
stages: stages:
- build_buster - build_bullseye
- upload_to_repo - upload_to_repo
# Stage "build_buster" # Stage "build_bullseye"
build_buster: build_bullseye:
stage: build_buster stage: build_bullseye
script: script:
- apt update - apt update
- apt install -y python3-stdeb python-all - apt install -y python3-stdeb python-all
- dpkg-buildpackage -us -uc - dpkg-buildpackage -us -uc
- mkdir -p build/ - mkdir -p build/
- mv ../*tempermonitor*.deb build/ - mv ../tempermonitor*.deb build/
- mv ../*tempermonitor*.changes build/ - mv ../tempermonitor*.changes build/
- mv ../*tempermonitor*.tar.gz build/ - mv ../tempermonitor*.tar.gz build/
- mv ../*tempermonitor*.dsc build/ - mv ../tempermonitor*.dsc build/
- mv ../*tempermonitor*.buildinfo build/ - mv ../tempermonitor*.buildinfo build/
# The files which are to be made available in GitLab # The files which are to be made available in GitLab
artifacts: artifacts:
......
tempermonitor (2.1.1) bullseye; urgency=medium
* fix for python 3.11
-- Wolfgang Walter <wolfgang.walter@stusta.de> Sun, 06 Aug 2023 00:21:00 +0200
tempermonitor (2.1.0) bullseye; urgency=medium
* upgrade to bullseye
-- Michael Loipführer <ml@stusta.de> Fri, 12 Nov 2021 18:40:18 +0200
tempermonitor (2.0.6) buster; urgency=medium
* fix missing module
-- Michael Loipführer <ml@stusta.de> Thu, 24 Apr 2020 18:40:18 +0200
tempermonitor (2.0.5) buster; urgency=medium
* fix missing module
-- Michael Loipführer <ml@stusta.de> Thu, 23 Apr 2020 23:40:18 +0200
tempermonitor (2.0.4) buster; urgency=medium
* improve plugin handling
-- Michael Loipführer <ml@stusta.de> Thu, 23 Apr 2020 23:30:18 +0200
tempermonitor (2.0.3) buster; urgency=medium
* rename config file
-- Michael Loipführer <ml@stusta.de> Thu, 23 Apr 2020 23:10:18 +0200
tempermonitor (2.0.2) buster; urgency=medium
* change main function
-- Michael Loipführer <ml@stusta.de> Thu, 23 Apr 2020 23:00:18 +0200
tempermonitor (2.0.1) buster; urgency=medium
* package renaming
-- Michael Loipführer <ml@stusta.de> Thu, 23 Apr 2020 22:55:18 +0200
tempermonitor (2.0.0) buster; urgency=medium tempermonitor (2.0.0) buster; urgency=medium
* Initial debian release * Initial debian release
......
...@@ -5,7 +5,7 @@ Priority: optional ...@@ -5,7 +5,7 @@ Priority: optional
Build-Depends: python3-setuptools, python3-all, debhelper (>= 11) Build-Depends: python3-setuptools, python3-all, debhelper (>= 11)
Standards-Version: 4.2.1 Standards-Version: 4.2.1
Package: python3-tempermonitor Package: tempermonitor
Homepage: https://gitlab.stusta.de/stustanet/temperature-daemon Homepage: https://gitlab.stusta.de/stustanet/temperature-daemon
Vcs-Browser: https://gitlab.stusta.de/stustanet/temperature-daemon Vcs-Browser: https://gitlab.stusta.de/stustanet/temperature-daemon
Vcs-Git: https://gitlab.stusta.de/stustanet/temperature-daemon.git Vcs-Git: https://gitlab.stusta.de/stustanet/temperature-daemon.git
......
...@@ -14,7 +14,7 @@ override_dh_auto_build: ...@@ -14,7 +14,7 @@ override_dh_auto_build:
python3 setup.py build --force python3 setup.py build --force
override_dh_auto_install: override_dh_auto_install:
python3 setup.py install --force --root=debian/python3-tempermonitor --no-compile -O0 --install-layout=deb python3 setup.py install --force --root=debian/tempermonitor --no-compile -O0 --install-layout=deb
override_dh_python2: override_dh_python2:
dh_python2 --no-guessing-versions dh_python2 --no-guessing-versions
......
File moved
from setuptools import setup from setuptools import setup
VERSION = '2.0.0' VERSION = '2.0.6'
def readme(): def readme():
...@@ -26,7 +26,10 @@ setup( ...@@ -26,7 +26,10 @@ setup(
'prometheus_client' 'prometheus_client'
], ],
license='MIT', license='MIT',
packages=['tempermonitor'], packages=[
'tempermonitor',
'tempermonitor.plugins'
],
include_package_data=True, include_package_data=True,
zip_safe=False zip_safe=False
) )
from tempermonitor.tempermonitor import main from tempermonitor.tempermonitor import main
if __name__ == '__main_': main()
main()
from abc import ABCMeta
PLUGINS = dict()
class PluginMeta(ABCMeta):
"""
Metaclass for available container backends.
"""
def __init__(cls, name, bases, classdict):
super().__init__(name, bases, classdict)
PLUGINS[cls.plugin_name()] = cls
class Plugin(metaclass=PluginMeta):
@classmethod
def plugin_name(cls):
return cls.__name__.lower()
@property
def name(self):
return self.__class__.__name__.lower()
# import all plugins so metaclass can populare PLUGINS dict
from . import collectd, mail, prometheus, warnings
import asyncio import asyncio
import time import time
from . import Plugin
def init(monitor):
return PluginCollectd(monitor)
class Collectd(Plugin):
class PluginCollectd:
""" """
Implements a super simple collectd interface for only sending temperature data Implements a super simple collectd interface for only sending temperature data
""" """
def __init__(self, monitor): def __init__(self, monitor):
self.loop = asyncio.get_event_loop()
self.config = monitor.config self.config = monitor.config
self.path = self.config['collectd']['socketpath'] self.path = self.config['collectd']['socketpath']
self._reader, self._writer = (None, None) self._reader, self._writer = (None, None)
self.loop.run_until_complete(self.reconnect()) asyncio.run(self.reconnect())
self.monitor = monitor self.monitor = monitor
...@@ -30,8 +27,7 @@ class PluginCollectd: ...@@ -30,8 +27,7 @@ class PluginCollectd:
self._writer.close() self._writer.close()
self._reader, self._writer = await asyncio.open_unix_connection( self._reader, self._writer = await asyncio.open_unix_connection(
path=self.path, path=self.path)
loop=self.loop)
async def _send(self, identifier, interval, timestamp, value): async def _send(self, identifier, interval, timestamp, value):
""" """
......
...@@ -3,6 +3,8 @@ from email.mime.text import MIMEText ...@@ -3,6 +3,8 @@ from email.mime.text import MIMEText
from email.utils import formatdate from email.utils import formatdate
import smtplib import smtplib
from . import Plugin
UNKNOWN_SENSOR_SUBJECT = "WARNING: Unconfigured Sensor ID: {owid}" UNKNOWN_SENSOR_SUBJECT = "WARNING: Unconfigured Sensor ID: {owid}"
UNKNOWN_SENSOR_BODY = """Hello Guys, UNKNOWN_SENSOR_BODY = """Hello Guys,
...@@ -89,14 +91,7 @@ with love, ...@@ -89,14 +91,7 @@ with love,
Temperator""" Temperator"""
def init(monitor): class Mail(Plugin):
"""
Plugin initialization method to be called from the outside
"""
return PluginMail(monitor)
class PluginMail:
""" """
Handle all the mail sending stuff Handle all the mail sending stuff
""" """
......
import re
import asyncio import asyncio
from prometheus_client import start_http_server, Gauge from prometheus_client import start_http_server, Gauge
from . import Plugin
def init(monitor): stats_name_re = re.compile(r'^temperature-(?P<group>\w+)-(?P<type>\w+)$')
return PluginPrometheus(monitor)
class PluginPrometheus: class Prometheus(Plugin):
def __init__(self, monitor): def __init__(self, monitor):
self.loop = asyncio.get_event_loop() self.loop = asyncio.get_event_loop()
self.config = monitor.config self.config = monitor.config
...@@ -32,20 +32,15 @@ class PluginPrometheus: ...@@ -32,20 +32,15 @@ class PluginPrometheus:
) )
print("started prometheus http server") print("started prometheus http server")
async def update_sensor_values(self, sensor):
"""
update
"""
print("updating prometheus metrics")
self.sensor_metrics.labels(sensor=sensor.name).set(sensor.temperature)
async def send_stats_graph(self, graph, stattype, stattime, statval): async def send_stats_graph(self, graph, stattype, stattime, statval):
""" """
to be called as a plugin callback to export aggregated measurements to be called as a plugin callback to export aggregated measurements
""" """
label_group = stattype.split("-")[1] m = stats_name_re.match(stattype)
label_type = stattype.split("-")[2] if not m:
self.aggregated_metrics.labels(group=label_group, type=label_type).set(statval) return
self.aggregated_metrics.labels(group=m.group('group'), type=m.group('type')).set(statval)
async def sensor_update(self): async def sensor_update(self):
""" """
...@@ -53,4 +48,4 @@ class PluginPrometheus: ...@@ -53,4 +48,4 @@ class PluginPrometheus:
""" """
for sensor in self.monitor.sensors.values(): for sensor in self.monitor.sensors.values():
if sensor.valid: if sensor.valid:
await self.update_sensor_values(sensor) self.sensor_metrics.labels(sensor=sensor.name).set(sensor.temperature)
import time import time
from . import Plugin
def init(monitor):
""" Plugin interface method """
return PluginWarning(monitor)
class Warnings(Plugin):
class PluginWarning:
""" """
Generate all kind of warnings whenever needed and observe the sensor Generate all kind of warnings whenever needed and observe the sensor
if they see a problematic situation in the container if they see a problematic situation in the container
...@@ -107,7 +104,7 @@ class PluginWarning: ...@@ -107,7 +104,7 @@ class PluginWarning:
tempdiff = ceil_avg - floor_avg tempdiff = ceil_avg - floor_avg
await self.monitor.call_plugin( await self.monitor.call_plugin(
"send_stats_graph", graph="stats", "send_stats_graph", graph="stats",
stattype="temperature-floor_ceil_diff", stattime=now, statval=tempdiff) stattype="temperature-floor_ceil-diff", stattime=now, statval=tempdiff)
print("floor: min {:05.2f} max {:05.2f} avg {:05.2f} var {:05.2f}".format( print("floor: min {:05.2f} max {:05.2f} avg {:05.2f} var {:05.2f}".format(
floor_min, floor_max, floor_avg, floor_var)) floor_min, floor_max, floor_avg, floor_var))
......
...@@ -21,12 +21,12 @@ import asyncio ...@@ -21,12 +21,12 @@ import asyncio
import configparser import configparser
import sys import sys
import time import time
import importlib
from datetime import datetime from datetime import datetime
from pathlib import Path
import serial_asyncio import serial_asyncio
import serial import serial
from .plugins import PLUGINS
class Sensor: class Sensor:
""" """
...@@ -254,41 +254,27 @@ class TempMonitor: ...@@ -254,41 +254,27 @@ class TempMonitor:
self._last_store = time.time() self._last_store = time.time()
def setup_plugin(filename, plugin):
"""
Setup and fix plugins
"""
if not getattr(plugin, "name", None):
plugin.name = filename
def main(): def main():
""" """
Start the tempmonitor Start the tempmonitor
""" """
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
configfile = "/etc/temperature/tempermon.ini" configfile = "/etc/tempermonitor.ini"
if len(sys.argv) == 2: if len(sys.argv) == 2:
configfile = sys.argv[1] configfile = sys.argv[1]
print("Configuring temperature monitoring system from {}.".format(configfile)) print(f"Configuring temperature monitoring system from {configfile}.")
monitor = TempMonitor(loop, configfile) monitor = TempMonitor(loop, configfile)
plugin_path = Path(__file__).resolve().parent / "plugins"
print("Loading plugins from {}".format(plugin_path))
active_plugins = monitor.config["general"]["plugins"].split(",") active_plugins = monitor.config["general"]["plugins"].split(",")
print(f"Active plugins: {active_plugins}") print(f"Active plugins: {active_plugins}")
for filename in plugin_path.glob("*.py"): for plugin in active_plugins:
if (plugin_path / filename).exists() and filename.stem in active_plugins: if plugin in PLUGINS:
print("loading {}".format(filename.name)) p = PLUGINS[plugin](monitor)
modname = "plugins." + filename.name.split('.')[0] monitor.plugins.append(p)
module = importlib.import_module(modname) print(f"Loaded plugin: {plugin}")
plugin = module.init(monitor)
setup_plugin(filename, plugin)
monitor.plugins.append(plugin)
print("Loaded: {}".format(plugin.name))
try: try:
loop.run_forever() loop.run_forever()
......