Rich Python System Dashboard: Build a Powerful Real-Time System Monitor with Python
Monitoring your computer's performance can help you understand how applications use system resources and identify potential performance problems. Instead of opening several system utilities, you can create your own terminal-based dashboard using Python.
In this tutorial, you will learn how to build a Python system dashboard using the Rich and psutil libraries. The application displays CPU usage, memory consumption, disk usage, and system information in a clean terminal interface. It also refreshes automatically, allowing you to monitor changes over time.
What Is a Python System Dashboard?
A system dashboard is a tool that displays important information about a computer in one place. Depending on its features, it can show processor activity, available memory, disk capacity, uptime, and other performance statistics.
Python makes this kind of project accessible because it offers libraries for collecting system information and presenting it in a readable format.
Why Use Rich and psutil?
This project uses two useful Python libraries.
Rich: Rich makes terminal applications more attractive by providing formatted text, tables, panels, colors, and live screen updates.
psutil: psutil provides access to system information, including CPU activity, memory usage, disk statistics, and other process-related data.
Combining these libraries allows you to build a useful monitoring tool without creating a graphical desktop application.
Features of the Dashboard
- Displays current CPU utilization.
- Shows used and available system memory.
- Reports disk space consumption.
- Displays the operating system and computer uptime.
- Refreshes the dashboard automatically.
- Organizes system statistics in a readable terminal table.
Step 1: Install Python Libraries
First, make sure Python 3 is installed on your computer. Open a terminal or command prompt and run:
pip install rich psutil
The Rich library will handle the terminal interface, while psutil will collect the system statistics.
Step 2: Create the Python System Dashboard
Create a Python file named system_dashboard.py. Add the following code to build a dashboard that refreshes every second.
import platform
import time
import psutil
from rich.console import Console
from rich.live import Live
from rich.table import Table
from rich.panel import Panel
from rich.layout import Layout
console = Console()
def format_bytes(size):
"""Convert bytes into a readable size."""
units = ["B", "KB", "MB", "GB", "TB"]
for unit in units:
if size < 1024 or unit == units[-1]:
return f"{size:.1f} {unit}"
size /= 1024
def create_dashboard(start_time):
"""Build a dashboard from current system statistics."""
table = Table(expand=True)
table.add_column("Metric", style="cyan", ratio=1)
table.add_column("Current Value", style="green", ratio=2)
cpu = psutil.cpu_percent(interval=None)
memory = psutil.virtual_memory()
disk = psutil.disk_usage("/")
uptime = int(time.time() - start_time)
hours, remainder = divmod(uptime, 3600)
minutes, seconds = divmod(remainder, 60)
table.add_row("Operating System", platform.system())
table.add_row("Platform", platform.machine())
table.add_row("CPU Usage", f"{cpu:.1f}%")
table.add_row("Memory Used", format_bytes(memory.used))
table.add_row("Memory Usage", f"{memory.percent:.1f}%")
table.add_row("Disk Used", format_bytes(disk.used))
table.add_row("Disk Usage", f"{disk.percent:.1f}%")
table.add_row(
"Dashboard Runtime",
f"{hours:02}:{minutes:02}:{seconds:02}"
)
return Panel(
table,
title="[bold cyan]Python System Monitor[/bold cyan]",
subtitle="Refreshes every second",
border_style="blue"
)
def main():
start_time = time.time()
# Prime the CPU measurement.
psutil.cpu_percent(interval=None)
try:
with Live(
create_dashboard(start_time),
console=console,
refresh_per_second=4,
screen=True
) as live:
while True:
live.update(create_dashboard(start_time))
time.sleep(1)
except KeyboardInterrupt:
console.print("\n[bold yellow]Dashboard stopped.[/bold yellow]")
if __name__ == "__main__":
main()
Step 3: Run the Dashboard
Save your file and execute this command in the same directory:
python system_dashboard.py
The terminal will display a table containing system information and performance statistics. CPU, memory, and disk usage will update as the program refreshes.
To stop the dashboard, press Ctrl+C.
Step 4: Understand How the Code Works
1. Importing the libraries: The program imports psutil for system statistics, Rich for the interface, and standard Python modules for timing and platform information.
2. Formatting file sizes: The format_bytes() function converts raw byte counts into readable units such as KB, MB, and GB.
3. Collecting system statistics: Functions such as cpu_percent(), virtual_memory(), and disk_usage() provide information about the computer's current resource usage.
4. Creating the table: Rich's Table class organizes metrics and values into columns. The Panel class adds a title and a border around the table.
5. Updating the interface: Rich's Live class refreshes the displayed dashboard without requiring a new terminal screen for every update.
6. Handling shutdown: KeyboardInterrupt allows the program to stop gracefully when the user presses Ctrl+C.
Step 5: Customize Your Dashboard
You can extend the project with additional information and features.
- Network statistics: Use psutil.net_io_counters() to display the total bytes sent and received by the computer.
- Battery status: Use psutil.sensors_battery() on supported systems to report battery percentage and charging status.
- Process monitoring: Use psutil.process_iter() to inspect selected running processes.
- Warnings: Add conditional formatting when CPU or memory usage exceeds a chosen threshold.
- Logging: Record periodic resource measurements in a CSV file for later analysis.
Important Compatibility Notes
This project is designed for desktop operating systems that support the required Python libraries. Some metrics may behave differently depending on the operating system, permissions, hardware, or virtualized environment.
The example uses the root disk path "/" for disk statistics, which is suitable for Linux and macOS. On Windows, change the disk usage line to use an available drive such as:
disk = psutil.disk_usage("C:\\")
On systems with multiple disks or partitions, you can expand the application to display each relevant mount point separately.
CPU measurements are approximate and depend on the sampling interval. The dashboard refreshes periodically, so its values should be treated as monitoring estimates rather than perfectly instantaneous measurements.
Common Problems and Solutions
ModuleNotFoundError: Install the missing libraries using pip install rich psutil. If necessary, use python -m pip install rich psutil.
Disk path errors: Use a valid drive or mount point for your operating system.
Dashboard does not refresh: Confirm that the script is still running and that the terminal supports Rich's live display.
Some statistics are unavailable: Check operating-system compatibility and permissions. Not every system exposes every metric in the same way.
Conclusion
Building a real-time system dashboard is an excellent Python project for developers interested in automation, monitoring, and terminal applications. The Rich library makes the interface easier to read, while psutil provides access to useful system statistics.
With a relatively small amount of code, you can monitor CPU activity, memory consumption, disk usage, and basic platform information from one terminal window.
Once the basic dashboard works, consider adding network monitoring, process lists, alerts, historical charts, or configuration options. These improvements can turn a beginner project into a more capable personal system-monitoring tool.