mirror of
https://forgejo.altau.su/lego/lego-monitoring.git
synced 2026-03-10 04:41:10 +00:00
ram and cpu monitoring
This commit is contained in:
parent
5bbcf95015
commit
4fd3391c70
5 changed files with 93 additions and 8 deletions
|
|
@ -1,6 +1,6 @@
|
|||
from dataclasses import dataclass
|
||||
|
||||
from psutil import sensors_temperatures
|
||||
from psutil import cpu_percent, sensors_temperatures, virtual_memory
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
@ -12,6 +12,20 @@ class TemperatureSensor:
|
|||
critical_temp: float | None = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class CpuSensor:
|
||||
current_load: float
|
||||
highest_load: float = 90
|
||||
critical_load: float = 95
|
||||
|
||||
|
||||
@dataclass
|
||||
class RamSensor:
|
||||
current_avail: int
|
||||
warning_avail: int = 4 * 1024**3
|
||||
critical_avail: int = 2 * 1024**3
|
||||
|
||||
|
||||
class Sensors:
|
||||
@staticmethod
|
||||
def get_temperatures() -> dict[str, list[TemperatureSensor]]:
|
||||
|
|
@ -51,9 +65,28 @@ class Sensors:
|
|||
critical_temp=95.0, # hardcoded because we have R9 7900X
|
||||
)
|
||||
)
|
||||
case "nct6687":
|
||||
for sensor in sensors:
|
||||
temp_sensors[s_type].append(
|
||||
TemperatureSensor(
|
||||
sensor_type=s_type,
|
||||
sensor_label=sensor.label,
|
||||
current_temp=sensor.current,
|
||||
highest_temp=sensor.high or None,
|
||||
critical_temp=sensor.critical or None,
|
||||
)
|
||||
)
|
||||
|
||||
return temp_sensors
|
||||
|
||||
@staticmethod
|
||||
def get_cpu() -> CpuSensor:
|
||||
return CpuSensor(current_load=cpu_percent())
|
||||
|
||||
@staticmethod
|
||||
def get_ram() -> RamSensor:
|
||||
return RamSensor(current_avail=virtual_memory().available)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
for i in Sensors.get_temperatures():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue