collector/plugins/system/temperatures_plugin.py

38 lines
1.1 KiB
Python
Raw Normal View History

2020-04-14 22:49:22 +00:00
from collections import namedtuple
from datetime import datetime
import psutil
from peewee import *
from playhouse.shortcuts import model_to_dict
import config
from database import BaseModel
from plugins.plugin import Plugin
2020-04-14 22:49:22 +00:00
class Temperatures(BaseModel):
2020-04-18 20:52:27 +00:00
time = DateTimeField(index=True, default=datetime.utcnow)
2020-04-14 22:49:22 +00:00
sensor = TextField(null=False)
sensor_label = TextField(null=False)
current = FloatField(null=False) # all values are per second
high = FloatField(null=False)
critical = FloatField(null=False)
class TemperaturesPlugin(Plugin):
models = [Temperatures]
2020-04-17 16:16:58 +00:00
def get_interval(self):
return config.TEMPERATURE_INTERVAL
2020-04-14 22:49:22 +00:00
def execute(self):
for sensor, temps in psutil.sensors_temperatures(config.TEMPERATURE_USE_FAHRENHEIT).items():
for temp in temps:
entry = Temperatures()
entry.sensor = sensor
entry.sensor_label = temp.label
entry.current = temp.current
entry.high = temp.high
entry.critical = temp.critical
entry.save()