Skip to content

vatsalj17/sysmonitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

💻 sysmonitor

A simple, real-time system monitor for Linux. It watches your CPU and RAM usage and turns that data into a live graph.

What does it do?

  • 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.csv file so you can look at it later.
  • Real-time Graphing: Draws a live-updating plot of your resource usage using Matplotlib.

How to get it running

  1. Set up your environment: Make sure you have your virtual environment active.
  2. Install dependencies:
pip install pandas matplotlib
  1. Run the monitor:
python main.py

Project Files

  • 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.

How it works

1. The /proc Pseudo-Filesystem

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/stat provides cumulative totals since boot, a single read is useless for calculating current usage. Your get_cpu_usage() function is clever: it stores PREV_CPU_STATS, waits 2 seconds, reads again, and calculates the difference (the delta).

2. The CPU Usage Formula

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

3. RAM Logic

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.

About

Python-based system monitor that reads live metrics directly from the Linux /proc filesystem. It provides a real-time terminal display and generates a live-updating graph using Matplotlib.

Resources

Stars

Watchers

Forks

Contributors

Languages