System Lagging Alert, Temperature Alert In Arbitrary Device

Python
System Responsiveness
Temperature Measurement
Alert Thresholds
Notifications
Monitoring Software
Daemon Installation
Learn how to measure system responsiveness and temperature using Python, set alert thresholds for notifications, and install monitoring software as a daemon on various devices.
Published

January 14, 2024


The system sometimes feels lagging, less responsive. The only way to fix is to reboot.

Although monitor task completion time is helpful, but not general enough.

Simple hack:

import subprocess
def measure_system_responsiveness():
start_time = time.time()
subprocess.run(
["echo", "hello"], capture_output=True, encoding='utf-8', check=True
)
end_time = time.time()
exec_time = end_time - start_time
exec_per_second = 1 / exec_time
return exec_per_second

Lagging related package:

apt install nohang oomd psi-notify

Temperature monitoring packages:

pip3 install gpustat
pip3 install pyspectator
apt install lm-sensor # sensors -j

Create temperature statistics (high, low, mean) for all crucial components.

Set alert threshold, only trigger alert if temperature reoccurs for several times.

Send ntfy.sh notification as well as making audible alerts.

Notification shall specify device name, component name, current temperature, threshold, statistics.

Every device shall be equipped with this software as daemon, be it smartphone, MacBook, Linux PC, Windows PC.