This is a small project that shows a minimal dashboard for a Raspberry Pi (rpi-5) system information: CPU temperature, RAM usage, and Uptime.
It demonstrates simple file I/O (/proc and /sys), a subprocess fallback, and a tiny Flask web server.
Files
system-info.py- Flask app + functions to collect system info.logger.py- System metrics logger for tracking historical data.requirements.txt- Minimal dependency list.
Quick start
- (Optional) create and activate a virtual environment:
python -m venv venv
source venv/bin/activate- Install dependencies:
pip install -r requirements.txt- Run the app:
python system-info.py-
Open a browser on the Pi or another machine on the same LAN to:
http://:5000/
Notes and learning points
- CPU temperature: tries
/sys/class/thermal/thermal_zone0/tempfirst (millidegrees Celsius). Falls back tovcgencmd measure_tempif available. - RAM: reads
/proc/meminfoand computes used/free in MB and percent. - Uptime: reads
/proc/uptimeand formats a simple human-readable string. - The app provides both an HTML dashboard and a JSON endpoint at
/api/statusfor programmatic use. - Historical logging: The
logger.pymodule automatically saves metrics to daily JSON files in thelogs/directory (up to 1000 recent entries per day). - History API: Access historical metrics via
/api/history?hours=N(e.g.,/api/history?hours=24for last 24 hours).
Next steps you might try
- Add graphs using Chart.js to visualize the historical data from
/api/history. - Add authentication if exposing publicly.
- Add unit tests for the parsing functions by mocking
/proc/meminfoand/proc/uptime. - Implement automatic cleanup of old log files to prevent disk space issues.