mirror of
https://forgejo.altau.su/lego/lego-monitoring.git
synced 2026-03-10 04:41:10 +00:00
Merge branch 'temps-monitor' into 'main'
Temperature Monitoring Closes #1 See merge request lego/lego-monitoring!1
This commit is contained in:
commit
806cf0a953
5 changed files with 67 additions and 8 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1 +1,2 @@
|
||||||
.venv
|
.venv
|
||||||
|
__pycache__
|
||||||
|
|
@ -1 +1 @@
|
||||||
# lego-monitoring
|
# lego-monitoring
|
||||||
|
|
|
||||||
15
main.py
15
main.py
|
|
@ -1,12 +1,15 @@
|
||||||
import psutil
|
from sensors import Sensors
|
||||||
|
from colorama import Fore, Style, Back
|
||||||
|
|
||||||
|
|
||||||
def get_temperatures():
|
def pretty_print():
|
||||||
sensors = psutil.sensors_temperatures()
|
s = Sensors.get_temperatures()
|
||||||
|
|
||||||
for k in sensors:
|
for k, v in s.items():
|
||||||
print(f"{k}: {sensors[k]}")
|
print(f"{Back.CYAN}{k}{Style.RESET_ALL}")
|
||||||
|
|
||||||
|
for sensors in v:
|
||||||
|
print(f"{sensors.sensor_label}: {sensors.current_temp}°C")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
get_temperatures()
|
pretty_print()
|
||||||
|
|
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
|
colorama==0.4.6
|
||||||
psutil==5.9.8
|
psutil==5.9.8
|
||||||
|
|
|
||||||
54
sensors.py
Normal file
54
sensors.py
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from psutil import sensors_temperatures
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class TemperatureSensor:
|
||||||
|
sensor_type: str
|
||||||
|
sensor_label: str
|
||||||
|
current_temp: float
|
||||||
|
highest_temp: float | None = None
|
||||||
|
critical_temp: float | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class Sensors:
|
||||||
|
@staticmethod
|
||||||
|
def get_temperatures() -> dict[str, list[TemperatureSensor]]:
|
||||||
|
psutil_temp_sensors = sensors_temperatures()
|
||||||
|
|
||||||
|
temp_sensors = {}
|
||||||
|
|
||||||
|
for s_type, sensors in psutil_temp_sensors.items():
|
||||||
|
if s_type not in temp_sensors.keys():
|
||||||
|
temp_sensors[s_type] = []
|
||||||
|
match(s_type):
|
||||||
|
case "nvme":
|
||||||
|
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,
|
||||||
|
critical_temp=sensor.critical
|
||||||
|
))
|
||||||
|
case "amdgpu":
|
||||||
|
temp_sensors[s_type].append(TemperatureSensor(
|
||||||
|
sensor_type=s_type,
|
||||||
|
sensor_label="Integrated GPU",
|
||||||
|
current_temp=sensors[0].current,
|
||||||
|
))
|
||||||
|
case "k10temp":
|
||||||
|
temp_sensors[s_type].append(TemperatureSensor(
|
||||||
|
sensor_type=s_type,
|
||||||
|
sensor_label="AMD CPU",
|
||||||
|
current_temp=sensors[0].current,
|
||||||
|
critical_temp=95.0 # hardcoded because we have R9 7900X
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
|
return temp_sensors
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
for i in Sensors.get_temperatures():
|
||||||
|
print(i)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue