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:
image: debian-python-build:v2
image: debian-build-python:bullseye
# Is performed before the scripts in the stages step
before_script:
......@@ -16,22 +16,22 @@ before_script:
# Defines stages which are to be executed
stages:
- build_buster
- build_bullseye
- upload_to_repo
# Stage "build_buster"
build_buster:
stage: build_buster
# Stage "build_bullseye"
build_bullseye:
stage: build_bullseye
script:
- apt update
- apt install -y python3-stdeb python-all
- dpkg-buildpackage -us -uc
- mkdir -p build/
- mv ../*tempermonitor*.deb build/
- mv ../*tempermonitor*.changes build/
- mv ../*tempermonitor*.tar.gz build/
- mv ../*tempermonitor*.dsc build/
- mv ../*tempermonitor*.buildinfo build/
- mv ../tempermonitor*.deb build/
- mv ../tempermonitor*.changes build/
- mv ../tempermonitor*.tar.gz build/
- mv ../tempermonitor*.dsc build/
- mv ../tempermonitor*.buildinfo build/
# The files which are to be made available in GitLab
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
* Initial debian release
......
......@@ -5,7 +5,7 @@ Priority: optional
Build-Depends: python3-setuptools, python3-all, debhelper (>= 11)
Standards-Version: 4.2.1
Package: python3-tempermonitor
Package: tempermonitor
Homepage: 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
......
......@@ -14,7 +14,7 @@ override_dh_auto_build:
python3 setup.py build --force
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:
dh_python2 --no-guessing-versions
......
File moved
from setuptools import setup
VERSION = '2.0.0'
VERSION = '2.0.6'
def readme():
......@@ -26,7 +26,10 @@ setup(
'prometheus_client'
],
license='MIT',
packages=['tempermonitor'],
packages=[
'tempermonitor',
'tempermonitor.plugins'
],
include_package_data=True,
zip_safe=False
)
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 time
from . import Plugin
def init(monitor):
return PluginCollectd(monitor)
class PluginCollectd:
class Collectd(Plugin):
"""
Implements a super simple collectd interface for only sending temperature data
"""
def __init__(self, monitor):
self.loop = asyncio.get_event_loop()
self.config = monitor.config
self.path = self.config['collectd']['socketpath']
self._reader, self._writer = (None, None)
self.loop.run_until_complete(self.reconnect())
asyncio.run(self.reconnect())
self.monitor = monitor
......@@ -30,8 +27,7 @@ class PluginCollectd:
self._writer.close()
self._reader, self._writer = await asyncio.open_unix_connection(
path=self.path,
loop=self.loop)
path=self.path)
async def _send(self, identifier, interval, timestamp, value):
"""
......
......@@ -3,6 +3,8 @@ from email.mime.text import MIMEText
from email.utils import formatdate
import smtplib
from . import Plugin
UNKNOWN_SENSOR_SUBJECT = "WARNING: Unconfigured Sensor ID: {owid}"
UNKNOWN_SENSOR_BODY = """Hello Guys,
......@@ -89,14 +91,7 @@ with love,
Temperator"""
def init(monitor):
"""
Plugin initialization method to be called from the outside
"""
return PluginMail(monitor)
class PluginMail:
class Mail(Plugin):
"""
Handle all the mail sending stuff
"""
......
import re
import asyncio
from prometheus_client import start_http_server, Gauge
from . import Plugin
def init(monitor):
return PluginPrometheus(monitor)
stats_name_re = re.compile(r'^temperature-(?P<group>\w+)-(?P<type>\w+)$')
class PluginPrometheus:
class Prometheus(Plugin):
def __init__(self, monitor):
self.loop = asyncio.get_event_loop()
self.config = monitor.config
......@@ -32,20 +32,15 @@ class PluginPrometheus:
)
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):
"""
to be called as a plugin callback to export aggregated measurements
"""
label_group = stattype.split("-")[1]
label_type = stattype.split("-")[2]
self.aggregated_metrics.labels(group=label_group, type=label_type).set(statval)
m = stats_name_re.match(stattype)
if not m:
return
self.aggregated_metrics.labels(group=m.group('group'), type=m.group('type')).set(statval)
async def sensor_update(self):
"""
......@@ -53,4 +48,4 @@ class PluginPrometheus:
"""
for sensor in self.monitor.sensors.values():
if sensor.valid:
await self.update_sensor_values(sensor)
self.sensor_metrics.labels(sensor=sensor.name).set(sensor.temperature)
import time
from . import Plugin
def init(monitor):
""" Plugin interface method """
return PluginWarning(monitor)
class PluginWarning:
class Warnings(Plugin):
"""
Generate all kind of warnings whenever needed and observe the sensor
if they see a problematic situation in the container
......@@ -107,7 +104,7 @@ class PluginWarning:
tempdiff = ceil_avg - floor_avg
await self.monitor.call_plugin(
"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(
floor_min, floor_max, floor_avg, floor_var))
......
......@@ -21,12 +21,12 @@ import asyncio
import configparser
import sys
import time
import importlib
from datetime import datetime
from pathlib import Path
import serial_asyncio
import serial
from .plugins import PLUGINS
class Sensor:
"""
......@@ -254,41 +254,27 @@ class TempMonitor:
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():
"""
Start the tempmonitor
"""
loop = asyncio.get_event_loop()
configfile = "/etc/temperature/tempermon.ini"
configfile = "/etc/tempermonitor.ini"
if len(sys.argv) == 2:
configfile = sys.argv[1]
print("Configuring temperature monitoring system from {}.".format(configfile))
print(f"Configuring temperature monitoring system from {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(",")
print(f"Active plugins: {active_plugins}")
for filename in plugin_path.glob("*.py"):
if (plugin_path / filename).exists() and filename.stem in active_plugins:
print("loading {}".format(filename.name))
modname = "plugins." + filename.name.split('.')[0]
module = importlib.import_module(modname)
plugin = module.init(monitor)
setup_plugin(filename, plugin)
monitor.plugins.append(plugin)
print("Loaded: {}".format(plugin.name))
for plugin in active_plugins:
if plugin in PLUGINS:
p = PLUGINS[plugin](monitor)
monitor.plugins.append(p)
print(f"Loaded plugin: {plugin}")
try:
loop.run_forever()
......