A lightweight Python tool that monitors CPU, RAM, and disk usage on Linux and logs the results.
It can alert you via desktop notifications when thresholds are exceeded.
- Reads CPU usage from
/proc/stat - Reads memory usage from
/proc/meminfo - Checks disk usage with
shutil.disk_usage - Checks the status of systemd services
- Configurable thresholds via
config.json - Optional CSV and JSON export of metrics
- Desktop notifications using
notify-send - Scheduled execution with the
schedulelibrary
- Python 3.6 or higher
- Linux (uses
/procfilesystem andsystemctl) - Python packages:
schedule(install withpip install schedule)
Create a config.json file in the same directory:
{
"thresholds": {
"cpu": 80.0,
"memory": 85.0,
"disk": 80.0
},
"services": ["sshd", "cron", "NetworkManager"]
}Run the script:
python system_monitoring_script.pyThe monitor will check metrics every 5 seconds (adjustable in the code) and print logs.
If any threshold is exceeded, a desktop notification will pop up.
To stop, press Ctrl+C.
schedule - DEBUG - Running job Job(interval=5, unit=seconds, do=job, args=(), kwargs={}) main - INFO - The service sshd is inactive main - INFO - The service cron is active main - INFO - The service NetworkManager is active main - INFO - CPU usage: 8.17% main - INFO - RAM usage: 71.02% main - INFO - Percentage of Disk used: 42.79% main - INFO - Total available Disk: 61.66GB main - INFO - Disk used: 26.38GB main - INFO - Available Disk: 32.11GB