A simple, real-time system monitor for Linux. It watches your CPU and RAM usage and turns that data into a live graph.
- Live Stats: Shows how hard each of your CPU cores is working.
- Memory Tracking: Keeps an eye on your RAM usage.
- Logging: Saves all your data to a
log.csvfile so you can look at it later. - Real-time Graphing: Draws a live-updating plot of your resource usage using Matplotlib.
- Set up your environment: Make sure you have your virtual environment active.
- Install dependencies:
pip install pandas matplotlib
- Run the monitor:
python main.py
main.py: The heart of the app. It runs the loop that refreshes the display.data.py: The "engine" that reads raw data from the Linux system.log.py: Handles saving data to a CSV file.plot.py: Handles the live-updating graph window.
The code doesn't ask the OS for stats through a standard API; it reads them from the procfs (/proc). In Linux, the kernel exposes internal data as if they were regular files.
- CPU: I'm reading
/proc/stat. The kernel provides a running total of "jiffies" (clock ticks) the CPU has spent in various states. - The Delta Logic: Because
/proc/statprovides cumulative totals since boot, a single read is useless for calculating current usage. Yourget_cpu_usage()function is clever: it storesPREV_CPU_STATS, waits 2 seconds, reads again, and calculates the difference (the delta).
Using the standard calculation for CPU utilization:
Total Time = Σ (all fields in /proc/stat)
Idle Time = idle + iowait
Usage % = (Total Time − Idle Time) / Total Time × 100
I'm pulling from /proc/meminfo. It’s worth noting that I used MemAvailable instead of MemFree. MemFree only shows totally untouched memory, while MemAvailable accounts for memory that is technically used by the cache but can be instantly reclaimed if needed.