prism-system-monitor
A lightweight, continuous monitoring script that gathers real-time hardware telemetry. It is designed to act as a "data provider" for status bar widgets by outputting system health metrics in a structured JSON format. It handles CPU, RAM, Disk, and cross-vendor GPU (Nvidia/AMD) tracking.
How it works
- CPU Tracking: Instead of calling external tools, it reads
/proc/statdirectly. It calculates the delta between "total time" and "idle time" over a 2-second interval to provide an accurate percentage of CPU load. - Temperature Sensing: It utilizes
lm_sensorsandjqto parse hardware sensors. It automatically searches for the highest reported temperature input to identify the primary CPU heat source. - Memory & Storage:
- RAM: Uses the
freecommand, calculating the percentage of used memory relative to total capacity viaawk. - Disk: Queries the root partition (
/) usingdfto track storage consumption.
- RAM: Uses the
- Hybrid GPU Support:
- Nvidia: Uses
nvidia-smito query utilization and temperature if the binary is present. - AMD: Checks the kernel interface at
/sys/class/drm/card0/device/gpu_busy_percentfor usage and queriessensorsfor the "edge" temperature. - Fallback: Returns zeros if no supported discrete GPU is detected.
- Nvidia: Uses
- Streaming Output: The script runs an infinite loop, emitting a single line of minified JSON every 2 seconds.
Dependencies
lm_sensors: Providessensorsfor temperature data.jq: Essential for parsing JSON output from sensors and constructing the final object.procps: Providesfreeandtop.coreutils: Standard logic tools (df,tail,read).nvidia-smi: (Optional) Required for Nvidia GPU tracking.
Usage
This script is intended to be run in the background by a TUI or GUI widget.
prism-system-monitor
Sample JSON Output
{
"cpu": { "usage": 15, "temp": 42 },
"ram": 28,
"disk": 45,
"gpu": { "usage": 10, "temp": 50 }
}