A terminal-based system monitoring application built with Rust, providing real-time insights into CPU, memory, processes, and disk usage.
-
Real-time System Monitoring
- CPU usage (average and per-core)
- Memory and swap usage
- Process monitoring with detailed metrics
- Disk usage across all mounted filesystems
-
Interactive TUI
- Navigate between System Monitor and Disk Usage pages
- Sort processes by CPU, memory, PID, or name
- Sort disks by name, size, used space, available space, or usage percentage
- Search/filter processes and disks
- Kill processes interactively
- NEW: Directory browser with tree-like navigation
- NEW: Browse into mount points and explore filesystem hierarchy
- NEW: Recursive directory size calculation
-
Performance Optimized
- Efficient filtering with query caching
- Minimal memory allocations
- 60 FPS refresh rate for smooth UI
- Modular architecture with separation of concerns
- Rust 1.70 or later
- Linux/Unix environment (uses sysinfo crate)
# Clone the repository
git clone <repository-url>
cd sysmon
# Build release version
cargo build --release
# Run the application
./target/release/sysmonGlobal Controls:
Tab- Switch between System Monitor and Disk Usage pagesq- Quit application/- Enter search modeEsc- Clear search and reset selection↑/↓- Navigate through processes/disks
System Monitor Page:
c- Sort by CPU usagem- Sort by memory usagep- Sort by PIDn- Sort by namek- Kill selected process (with confirmation)
Disk Usage Page (Mount Points View):
s- Sort by sizeu- Sort by used spacea- Sort by available space%- Sort by usage percentagen- Sort by mount point namef- Sort by filesystem typeEnter- Browse into selected mount point
Disk Usage Page (Directory Browser View):
Enter- Navigate into selected directoryBackspace- Go to parent directoryEsc- Return to mount points view
Search Mode:
- Type to filter processes/disks in real-time
EnterorEsc- Exit search modeBackspace- Delete characters
sysmon/
├── src/
│ ├── main.rs # Application entry point, event loop, state management
│ ├── ui.rs # TUI rendering (ratatui-based)
│ └── metrics/
│ ├── mod.rs # Metrics aggregator module
│ ├── system.rs # System metrics (CPU, memory, processes)
│ ├── disk.rs # Disk metrics (mount points, disk info)
│ └── directory.rs # Directory navigator (tree traversal, size calc)
├── Cargo.toml # Project dependencies
├── README.md # This file
└── ARCHITECTURE.md # Detailed architecture documentation
Key Responsibilities:
- Event loop management (60 FPS)
- User input handling
- Application state management
- Terminal setup/cleanup with RAII guard pattern
Key Types:
AppState- Stores current page, sort modes, selections, search stateRawModeGuard- Ensures terminal cleanup on panic (RAII pattern)Direction- Enum for navigation (Up/Down)
Design Patterns:
- RAII for terminal cleanup
- Helper functions (
handle_navigation,reset_selection) for DRY code - Constants for magic numbers (
PROCESS_VISIBLE_ROWS,DISK_VISIBLE_ROWS)
The metrics module has been refactored into separate submodules for better organization and maintainability:
metrics/mod.rs - Aggregator:
Metricsstruct that combines all metric types- Provides unified access to system, disk, and directory metrics
metrics/system.rs - System Metrics:
SystemMetrics- CPU, memory, swap, and process dataProcessInfo- Individual process information- Process filtering and sorting with query caching
- Per-core CPU monitoring
Key Methods:
pub fn update(&mut self, sys: &mut System) // Refresh system metrics
pub fn filter_processes(&mut self, query: &str) -> &[ProcessInfo] // Cached filtering
pub fn apply_sort(&mut self, mode: SortMode) // Sort processes
pub fn memory_usage_percent(&self) -> f64 // Memory usage calculation
pub fn swap_usage_percent(&self) -> f64 // Swap usage calculationmetrics/disk.rs - Disk Metrics:
DiskMetrics- Mount point and filesystem informationDiskInfo- Individual disk/partition data- Disk filtering and sorting
- Byte formatting utilities
Key Methods:
pub fn update_disks(&mut self, disks: &Disks) // Refresh disk metrics
pub fn filter_disks(&mut self, query: &str) -> &[DiskInfo] // Cached filtering
pub fn apply_disk_sort(&mut self, mode: DiskSortMode) // Sort disks
pub fn disk_used_space(disk: &DiskInfo) -> u64 // Calculate used space
pub fn disk_usage_percent(disk: &DiskInfo) -> f64 // Usage percentage
pub fn format_bytes(bytes: u64) -> String // Human-readable sizesmetrics/directory.rs - Directory Navigator:
DirectoryNavigator- Directory tree traversalDirectoryEntry- File/directory metadata with size- Recursive directory size calculation
- Parent directory navigation
Key Methods:
pub fn enter_directory(&mut self, path: PathBuf) -> Result<(), std::io::Error> // Navigate into directory
pub fn exit_to_parent(&mut self) -> Result<(), std::io::Error> // Go to parent
pub fn exit_to_mount_points(&mut self) // Return to mount points view
pub fn filter_entries(&mut self, query: &str) -> &[DirectoryEntry] // Filter entriesOptimizations:
- Filter caching: Only re-filters when query changes
- Returns references (
&[T]) instead of cloning vectors - Implements
Defaulttrait for idiomatic Rust - Saturating arithmetic to prevent overflow in size calculations
Key Responsibilities:
- TUI layout and rendering using
ratatui - Color-coded indicators for resource usage
- Table rendering with sort indicators
- Dynamic filtering display
Layout Structure:
System Monitor:
┌─────────────────────────────────────────────┐
│ SYSTEM MONITOR (Header) │
├─────────────┬───────────────────────────────┤
│ CPU Gauge │ │
│ │ Process Table │
│ CPU Cores │ (PID, Name, CPU%, │
│ │ Memory, Status) │
│ Memory │ │
│ Details │ │
├─────────────┴───────────────────────────────┤
│ Footer (Help Text) │
└─────────────────────────────────────────────┘
Disk Usage (Mount Points View):
┌─────────────────────────────────────────────┐
│ DISK USAGE (Header) │
├─────────────────────────────────────────────┤
│ Summary (Total disks, space, etc.) │
├─────────────────────────────────────────────┤
│ Disk Table (Mount, Device, FS, │
│ Size, Used, Avail, Use%) │
├─────────────────────────────────────────────┤
│ Selected Disk Details │
├─────────────────────────────────────────────┤
│ Footer (Help Text) │
└─────────────────────────────────────────────┘
Disk Usage (Directory Browser View):
┌─────────────────────────────────────────────┐
│ DISK USAGE (Header) │
├─────────────────────────────────────────────┤
│ Summary (Total disks, space, etc.) │
├─────────────────────────────────────────────┤
│ Directory Table (Name, Size) │
│ - Shows ".." for parent directory │
│ - Directories marked with "/" suffix │
│ - Recursive size calculation │
├─────────────────────────────────────────────┤
│ Selected Disk Details │
├─────────────────────────────────────────────┤
│ Footer (Help Text) │
└─────────────────────────────────────────────┘
Color Scheme:
- CPU: Green (<30%) → Yellow (30-60%) → Light Red (60-80%) → Red (>80%)
- Memory: Green (<50%) → Yellow (50-70%) → Light Red (70-85%) → Red (>85%)
- Disk: Green (<50%) → Yellow (50-75%) → Light Red (75-90%) → Red (>90%)
[dependencies]
crossterm = "0.28" # Terminal manipulation
ratatui = "0.29" # TUI framework
sysinfo = "0.32" # System information- All float comparisons use
.unwrap_or(Ordering::Equal)to prevent NaN panics - Terminal cleanup guaranteed via
RawModeGuard(Drop trait) - Graceful degradation for missing/invalid system data
- Minimal allocations with reference returns
- Filter result caching (only re-filters on query change)
- 500ms system update interval vs 16ms UI refresh
- Efficient scroll windowing (only renders visible rows)
- DRY principle: Extracted helpers for navigation and reset logic
- Named structs instead of tuples for readability
- Constants for magic numbers
- Clear separation of concerns (metrics/UI/main loop)
Current Limitations:
- Process kill requires appropriate permissions
- Limited to local system (no remote monitoring)
- Fixed color thresholds (not user-configurable)
Potential Enhancements:
- Network I/O monitoring
- Historical graphs/charts
- Configurable update intervals
- Export metrics to file
- Custom color themes
- Multi-process tracking
- Directory size caching to improve performance on large directories
- File type filtering in directory browser
- Bookmark favorite directories
cargo testRUST_BACKTRACE=1 cargo runcargo build --release --target <your-target>[Your License Here]
Contributions welcome! Please ensure:
- Code passes
cargo clippywith no warnings - Run
cargo fmtbefore committing - Add tests for new features
- Update this README for architectural changes
Built with: