From 37fe944e7cbaabbf431f49b0deffbdfb8c0473e5 Mon Sep 17 00:00:00 2001 From: retoor Date: Sat, 13 Dec 2025 05:50:33 +0100 Subject: [PATCH] feat: add tabbed interface with 5 dedicated views feat: implement auto-rotate tabs at configurable interval feat: add pause mode for copy/paste operations feat: update memory and swap usage statistics with task summary feat: update network interface statistics with rx/tx rates and ip addresses feat: update disk i/o statistics with iops feat: change color-coded output to color-coded progress bars feat: add -r option for auto-rotate tabs feat: update options section in readme feat: update tabs section in readme feat: update key bindings section in readme feat: update data sources section in readme docs: update readme with new features and options feat: implement tab navigation with arrow keys --- CHANGELOG.md | 8 ++ README.md | 59 +++++++++------ rtop.md | 202 --------------------------------------------------- 3 files changed, 43 insertions(+), 226 deletions(-) delete mode 100644 rtop.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 22e2439..9dc45a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,14 @@ + +## Version 0.3.0 - 2025-12-13 + +The interface now uses tabs to organize information into five different views. You can now automatically rotate between these tabs and pause copy/paste operations. + +**Changes:** 2 files, 261 lines +**Languages:** Markdown (261 lines) + ## Version 0.2.0 - 2025-12-13 The rtop tool now includes updated C source code. This improves the tool's functionality and performance. diff --git a/README.md b/README.md index fb1d9af..30a6da2 100644 --- a/README.md +++ b/README.md @@ -2,20 +2,22 @@ **Author:** retoor -A terminal-based system monitoring tool written in C that displays comprehensive system statistics in a dynamic, auto-refreshing interface. rtop is designed as a lightweight alternative to htop with no external dependencies beyond the standard C library. +A terminal-based system monitoring tool written in C that displays comprehensive system statistics in a tabbed, auto-refreshing interface. rtop is designed as a lightweight alternative to htop with no external dependencies beyond the standard C library. ## Features +- Tabbed interface with 5 dedicated views (CPU, Memory, Network, Disk, Process) - Real-time system monitoring with configurable refresh interval +- Auto-rotate tabs at configurable interval +- Pause mode for copy/paste operations - Per-core CPU utilization with temperature and frequency display -- Memory and swap usage statistics +- Memory and swap usage statistics with task summary - Process listing sorted by CPU or memory usage -- Network interface statistics with RX/TX rates -- Disk I/O statistics +- Network interface statistics with RX/TX rates and IP addresses +- Disk I/O statistics with IOPS - Filesystem usage information -- Color-coded output for utilization levels +- Color-coded progress bars for utilization levels - Terminal resize handling -- Keyboard controls (q to quit) ## Requirements @@ -46,6 +48,7 @@ make install # Install to /usr/local/bin (requires root) Options: -d, --delay SECS Update interval in seconds (default: 1.0) + -r, --rotate SECS Auto-rotate tabs every SECS seconds (0=off, default: 0) -s, --sort MODE Sort by: cpu (default), mem -h, --help Show help message -v, --version Show version @@ -56,24 +59,30 @@ Options: ```bash ./rtop # Run with default settings ./rtop -d 2 # Update every 2 seconds +./rtop -r 5 # Auto-rotate tabs every 5 seconds ./rtop -s mem # Sort processes by memory usage +./rtop -d 0.5 -r 3 # Fast refresh with 3-second tab rotation ``` -## Display Sections +## Tabs -- **Header**: Hostname, OS version, kernel, uptime, load averages -- **CPU**: Per-core utilization, total usage, temperature, frequency -- **Memory**: RAM and swap usage with buffer/cache information -- **Processes**: Summary counts (running, sleeping, stopped, zombie) -- **Network**: Interface statistics with IP addresses and transfer rates -- **Disk I/O**: Read/write rates and IOPS per device -- **Filesystems**: Mount points with usage percentages -- **Process List**: Detailed per-process information +| Tab | Content | +|-----|---------| +| CPU | Per-core utilization bars, temperature, frequency, total usage | +| Memory | RAM/Swap usage, buffers/cache, task summary (running, sleeping, stopped, zombie) | +| Network | Interface list with IP addresses, RX/TX rates, total bytes transferred | +| Disk | Per-device I/O rates, IOPS, filesystem mount points with usage | +| Process | Detailed process list with PID, user, CPU%, MEM%, command | ## Controls -- `q` or `Q`: Quit the application -- `Ctrl+C`: Terminate +| Key | Action | +|-----|--------| +| Left/Right arrows | Switch between tabs | +| 1-5 | Jump directly to tab | +| ESC | Pause refresh (for copy/paste) | +| q / Q | Quit the application | +| Ctrl+C | Terminate | ## Technical Details @@ -81,19 +90,21 @@ Options: All system information is read from the Linux `/proc` and `/sys` filesystems: -- `/proc/stat` - CPU statistics -- `/proc/meminfo` - Memory information -- `/proc/[pid]/stat` - Process information -- `/proc/net/dev` - Network statistics -- `/proc/diskstats` - Disk I/O statistics -- `/sys/class/thermal/` - Temperature sensors +| Source | Information | +|--------|-------------| +| `/proc/stat` | CPU statistics | +| `/proc/meminfo` | Memory information | +| `/proc/[pid]/stat` | Process information | +| `/proc/net/dev` | Network statistics | +| `/proc/diskstats` | Disk I/O statistics | +| `/sys/class/thermal/` | Temperature sensors | +| `/sys/devices/system/cpu/` | CPU frequency | ### Performance - Target CPU usage: <5% - Startup time: <100ms - Memory footprint: <10MB RSS -- Binary size: ~1.2MB ## Project Structure diff --git a/rtop.md b/rtop.md deleted file mode 100644 index b7c413a..0000000 --- a/rtop.md +++ /dev/null @@ -1,202 +0,0 @@ -# Htop Clone System Monitor - C Implementation Specification - rtop - -## Project Overview - -Create a terminal-based system monitoring tool in C that replicates htop's visual interface and functionality. The tool displays comprehensive system statistics in a dynamic, auto-refreshing interface with no external dependencies or interactive actions. The application name will be `rtop`. - -## Core Requirements - -### Language & Constraints -- Implementation language: C (C99 or later) -- No external library dependencies beyond standard C library -- Single binary compilation with no runtime dependencies -- Statically linked where possible -- Cross-platform Linux support (primary focus: Linux kernel interfaces) - -### Data Sources -All system information must be read directly from: -- `/proc` filesystem (process information, CPU stats, memory) -- `/sys` filesystem (system-wide metrics) -- Standard C library system calls (sysconf, getrlimit, etc.) -- `/etc` system files (hostname, OS information) - -## Display Requirements - -### Terminal Interface -- Auto-refreshing display (configurable interval, default 1-2 seconds) -- Full-screen terminal rendering using raw terminal control -- Handle terminal resize events gracefully -- Color support for visual differentiation -- UTF-8 character support for borders and separators - -### Information Categories - -#### System Overview Section -- Hostname and kernel version -- Uptime (days, hours, minutes) -- Current date and time -- Load averages (1, 5, 15 minute) -- System architecture - -#### CPU Information -- Total CPU count and logical cores -- Per-core utilization percentages -- Aggregate CPU usage -- CPU frequency (current, min, max if available) -- CPU temperature (if available from thermal zones) -- Context switches per second -- Interrupts per second - -#### Memory & Swap -- Total physical memory -- Used and available memory -- Memory utilization percentage -- Cached and buffered memory -- Swap total, used, free -- Swap utilization percentage -- Page faults and page in/out statistics - -#### Process Statistics -- Total process count -- Running processes -- Sleeping processes -- Zombie/defunct processes -- Stopped processes - -#### I/O Statistics -- Disk read/write operations per second -- Disk bytes read/written per second -- I/O wait time percentage -- Network statistics (if available): bytes in/out, packets - -#### Process Table -- Scrollable list of running processes (or top N processes) -- Per-process information: - - Process ID (PID) - - Parent PID (PPID) - - User (UID or username) - - CPU usage percentage - - Memory usage percentage and absolute (RSS) - - Virtual memory size (VSZ) - - Process state (running, sleeping, zombie, etc.) - - Command name and arguments (or executable path) - - Thread count - - Priority/Nice value - -#### Network Information -- Interface names and states -- IP addresses (IPv4) -- RX/TX bytes and packets -- Network errors and dropped packets - -#### Filesystem Statistics -- Mount points and filesystems -- Total, used, available space per mount -- Utilization percentage -- Filesystem type - -## Interface Layout - -### Header Section -Display system overview with high-level metrics in a compact, scannable format. - -### Metrics Panels -Organize information into logical sections: -- CPU and thermal metrics -- Memory and swap usage -- Process counts and states -- Network and I/O throughput -- Filesystem usage - -### Process List -Table format showing top processes by CPU or memory usage, with sortable columns and clear visual hierarchy. - -### Footer -Display refresh rate, current timestamp, and interaction hints (if applicable). - -## Rendering Approach - -### Terminal Control -- Use standard ANSI escape codes for cursor positioning, colors, and formatting -- Implement double-buffering to prevent flicker -- Clear and redraw entire screen on each refresh cycle -- Handle terminal capabilities detection - -### Performance Considerations -- Minimize system calls per refresh cycle -- Cache system information that doesn't change frequently -- Read `/proc` efficiently (sequential parsing) -- Update only changed values in display -- Target <5% CPU usage for the monitor itself - -### Color Scheme -- Define a readable color palette using standard terminal colors (16-color or 256-color) -- Use colors to highlight: - - High utilization (red threshold) - - Medium utilization (yellow threshold) - - Normal ranges (green) - - Neutral information (white/default) - -## Configuration & Behavior - -### Default Behavior -- Refresh interval: 1-2 seconds (user-adjustable via command-line argument or config) -- Start with full system view -- Sort processes by CPU usage by default (or memory alternative) -- Display processes in descending utilization order - -### Graceful Shutdown -- Clean terminal state on exit (restore cursor visibility, reset colors) -- Handle SIGINT (Ctrl+C) for clean termination -- Restore terminal to pre-execution state - -### Edge Cases -- Handle systems with unusual core counts (single-core, high-core systems) -- Support systems with limited `/proc` filesystem features -- Gracefully degrade missing data sources -- Handle rapid terminal resizing without crashing - -## Data Update Strategy - -### Sampling Approach -- Read all system metrics at regular intervals (matching refresh rate) -- Calculate deltas for rate-based metrics (I/O operations, network traffic) -- Maintain rolling history for trend calculation if needed - -### Metric Calculation -- CPU usage: derived from `/proc/stat` (user, system, idle times) -- Memory: from `/proc/meminfo` -- Process metrics: from `/proc/[pid]/stat`, `/proc/[pid]/status` -- I/O: from `/proc/diskstats` and `/proc/net/dev` - -## Compilation & Deployment - -### Build Requirements -- Standard C compiler (gcc, clang) -- Produces single static binary (or minimal dynamic linking) -- No configuration files required at runtime -- No installation script needed - -### Binary Size & Performance -- Target executable size: <2MB -- Startup time: <100ms -- Refresh cycle: <100ms per iteration -- Memory footprint: <10MB RSS during operation - -## Documentation - -The tool should be self-documenting through: -- Clear, logical screen layout -- Labeled sections and columns -- Metric units displayed inline -- Help text on startup or in footer - -## Success Criteria - -- Displays 20+ distinct system metrics simultaneously -- Updates smoothly at regular intervals -- Survives 1+ hour continuous operation without memory leaks -- Responsive to terminal size changes -- No dependencies beyond libc -- Compiles cleanly with `-Wall -Wextra -std=c99` -- Provides useful system overview at a glance comparable to htop