socktop/README.md

166 lines
4.1 KiB
Markdown
Raw Normal View History

2025-08-08 08:06:43 +00:00
# socktop
2025-08-08 08:03:35 +00:00
2025-08-08 08:06:43 +00:00
**socktop** is a remote system monitor with a rich TUI interface, inspired by `top` and `btop`, that communicates with a lightweight remote agent over WebSockets.
2025-08-08 08:03:35 +00:00
2025-08-08 08:06:43 +00:00
It lets you watch CPU, memory, disks, network, temperatures, and processes on another machine in real-time — from the comfort of your terminal.
2025-08-08 08:03:35 +00:00
2025-08-08 08:08:02 +00:00
![socktop screenshot](socktop-screenshot.png)
2025-08-08 08:03:35 +00:00
---
2025-08-08 08:06:43 +00:00
## Features
2025-08-08 08:03:35 +00:00
2025-08-08 08:06:43 +00:00
- 📡 **Remote monitoring** via WebSocket — lightweight agent sends JSON metrics
- 🖥 **Rich TUI** built with [ratatui](https://github.com/ratatui-org/ratatui)
- 🔍 **Detailed CPU view** — per-core history, current load, and trends
- 📊 **Memory, Swap, Disk usage** — human-readable units, color-coded
- 🌡 **Temperatures** — CPU temperature with visual indicators
- 📈 **Network throughput** — live sparkline graphs with peak tracking
- 🏷 **Top processes table** — PID, name, CPU%, memory, and memory%
- 🎨 Color-coded load, zebra striping for readability
-**Keyboard shortcuts**:
- `q` / `Esc` → Quit
2025-08-08 08:03:35 +00:00
2025-08-08 08:06:43 +00:00
---
2025-08-08 08:03:35 +00:00
2025-08-08 08:06:43 +00:00
## Architecture
2025-08-08 08:03:35 +00:00
2025-08-08 08:06:43 +00:00
`socktop` has **two components**:
2025-08-08 08:03:35 +00:00
2025-08-08 08:06:43 +00:00
1. **Agent** (remote side)
A small Rust WebSocket server that runs on the target machine and gathers metrics via [sysinfo](https://crates.io/crates/sysinfo).
2025-08-08 08:03:35 +00:00
2025-08-08 08:06:43 +00:00
2. **Client** (local side)
The TUI app (`socktop`) that connects to the agents `/ws` endpoint, receives JSON metrics, and renders them.
2025-08-08 08:03:35 +00:00
2025-08-08 08:06:43 +00:00
The two communicate over a persistent WebSocket connection.
2025-08-08 08:03:35 +00:00
---
2025-08-08 08:06:43 +00:00
## Installation
2025-08-08 08:03:35 +00:00
2025-08-08 08:06:43 +00:00
### Prerequisites
- Rust 1.75+ (recommended latest stable)
- Cargo package manager
2025-08-08 08:03:35 +00:00
2025-08-08 08:06:43 +00:00
### Build from source
2025-08-08 08:03:35 +00:00
```bash
2025-08-08 08:06:43 +00:00
git clone https://github.com/YOURNAME/socktop.git
cd socktop
cargo build --release
2025-08-08 08:03:35 +00:00
```
2025-08-08 08:06:43 +00:00
### Install as a cargo binary
```bash
cargo install --path .
```
This will install the `socktop` binary into `~/.cargo/bin`.
2025-08-08 08:03:35 +00:00
---
2025-08-08 08:06:43 +00:00
## Running
2025-08-08 08:03:35 +00:00
2025-08-08 08:06:43 +00:00
### 1. Start the agent on the remote machine
The agent binary listens on a TCP port and serves `/ws`:
2025-08-08 08:03:35 +00:00
2025-08-08 08:06:43 +00:00
```bash
remote_agent 0.0.0.0:8080
```
2025-08-08 08:03:35 +00:00
2025-08-08 08:06:43 +00:00
> **Tip:** You can run the agent under `systemd`, inside a Docker container, or just in a tmux/screen session.
2025-08-08 08:03:35 +00:00
2025-08-08 08:06:43 +00:00
### 2. Connect with the client
From your local machine:
2025-08-08 08:03:35 +00:00
```bash
2025-08-08 08:06:43 +00:00
socktop ws://REMOTE_HOST:8080/ws
```
2025-08-08 08:03:35 +00:00
2025-08-08 08:06:43 +00:00
Example:
```bash
socktop ws://192.168.1.50:8080/ws
2025-08-08 08:03:35 +00:00
```
---
2025-08-08 08:06:43 +00:00
## Usage
When connected, `socktop` displays:
2025-08-08 08:03:35 +00:00
2025-08-08 08:06:43 +00:00
**Left column:**
- **CPU avg graph** — sparkline of recent overall CPU usage
- **Memory gauge** — total and used RAM
- **Swap gauge** — total and used swap
- **Disks** — usage per device (only devices with available space > 0)
- **Network Download/Upload** — sparkline in KB/s, with current & peak values
**Right column:**
- **Per-core history & trends** — each cores recent load, current %, and trend arrow
- **Top processes table** — top 20 processes with PID, name, CPU%, memory usage, and memory%
2025-08-08 08:03:35 +00:00
---
2025-08-08 08:06:43 +00:00
## Keyboard Shortcuts
| Key | Action |
|-------------|------------|
| `q` or `Esc`| Quit |
2025-08-08 08:03:35 +00:00
2025-08-08 08:06:43 +00:00
---
## Example agent JSON
`socktop` expects the agent to send metrics in this shape:
```json
{
"cpu_total": 12.4,
"cpu_per_core": [11.2, 15.7, ...],
"mem_total": 33554432,
"mem_used": 18321408,
"swap_total": 0,
"swap_used": 0,
"process_count": 127,
"hostname": "myserver",
"cpu_temp_c": 42.5,
"disks": [{"name":"nvme0n1p2","total":512000000000,"available":320000000000}],
"networks": [{"name":"eth0","received":12345678,"transmitted":87654321}],
"top_processes": [
{"pid":1234,"name":"nginx","cpu_usage":1.2,"mem_bytes":12345678}
]
}
```
---
## Development
### Run in debug mode:
```bash
cargo run -- ws://127.0.0.1:8080/ws
```
### Code formatting & lint:
2025-08-08 08:03:35 +00:00
```bash
2025-08-08 08:06:43 +00:00
cargo fmt
cargo clippy
2025-08-08 08:03:35 +00:00
```
---
2025-08-08 08:06:43 +00:00
## Roadmap
- [ ] Configurable refresh interval
- [ ] Filter/sort top processes in the TUI
- [ ] Export metrics to file
- [ ] TLS / WSS support
- [ ] Agent authentication
---
## License
MIT License — see [LICENSE](LICENSE).
---
## Acknowledgements
- [`ratatui`](https://github.com/ratatui-org/ratatui) for terminal UI rendering
- [`sysinfo`](https://crates.io/crates/sysinfo) for system metrics
2025-08-08 08:08:02 +00:00
- [`tokio-tungstenite`](https://crates.io/crates/tokio-tungstenite) for WebSocket client/server