A simple Python script to collect and display system metrics across Windows, macOS, and Linux.
- Cross-platform: Works on Windows, macOS, and Linux
- Automatic fallbacks: Uses
psutilwhen available, otherwise falls back to system commands - Comprehensive metrics: Collects CPU usage, memory usage, disk usage, uptime, and hostname
- Dual output: Displays both JSON report and formatted table
- Python 3.6+
psutil(optional but recommended for better performance)
- Clone or download
system_metrics.py - (Optional) Install psutil for enhanced functionality:
pip install psutil
Run the script directly:
python system_metrics.pyThe script provides two output formats:
- JSON Report: Machine-readable format with all metrics
- Table Report: Human-readable formatted table
System Metrics Collection
==================================================
JSON Report:
==================================================
{
"timestamp": "2025-09-11T10:30:45.123456",
"os": "Linux",
"hostname": "mycomputer",
"cpu_percent": 25.4,
"memory_percent": 67.8,
"disk_percent": 45.2,
"uptime_seconds": 86400.0,
"uptime_formatted": "1d 0h 0m",
"psutil_available": true
}
System Metrics Table:
==================================================
Metric Value
--------------------------------------------------
Timestamp 2025-09-11T10:30:45.123456
OS Linux
Hostname mycomputer
CPU Usage 25.4 %
Memory Usage 67.8 %
Disk Usage 45.2 %
Uptime 1d 0h 0m
Uptime (seconds) 86400.0
psutil Available true
- CPU Usage: Current CPU utilization percentage
- Memory Usage: RAM usage percentage
- Disk Usage: Primary disk usage percentage
- Uptime: System uptime in both seconds and formatted time
- Hostname: System hostname
- OS: Operating system type
When psutil is not available, the script uses:
- Linux:
/proc/stat,/proc/meminfo,/proc/uptime,dfcommand - macOS:
top,vm_stat,sysctl,dfcommands - Windows:
wmiccommands for system information
This project is licensed under the GNU General Public License v3.0 - see the [LICENSE] file for details.