2025-08-08 01:06:43 -07:00
# socktop
2025-08-08 01:03:35 -07:00
2025-08-12 15:52:46 -07:00
socktop is a remote system monitor with a rich TUI, inspired by top/btop, talking to a lightweight agent over WebSockets.
2025-08-08 01:03:35 -07:00
2025-08-12 15:52:46 -07:00
- Linux agent: near-zero CPU when idle (request-driven, no always-on sampler)
- TUI: smooth graphs, sortable process table, scrollbars, readable colors
2025-08-08 01:03:35 -07:00
2025-08-12 17:02:01 -07:00

2025-08-08 01:03:35 -07:00
---
2025-08-08 01:06:43 -07:00
## Features
2025-08-08 01:03:35 -07:00
2025-08-12 15:52:46 -07:00
- Remote monitoring via WebSocket (JSON over WS)
2025-08-16 01:23:20 -07:00
- Optional WSS (TLS): agent auto‑ generates a self‑ signed cert on first run; client pins the cert via --tls-ca/-t
2025-08-12 15:52:46 -07:00
- TUI built with ratatui
- CPU
- Overall sparkline + per-core mini bars
- Accurate per-process CPU% (Linux /proc deltas), normalized to 0– 100%
- Memory/Swap gauges with human units
- Disks: per-device usage
- Network: per-interface throughput with sparklines and peak markers
- Temperatures: CPU (optional)
- Top processes (top 50)
- PID, name, CPU%, memory, and memory%
- Click-to-sort by CPU% or Mem (descending)
- Scrollbar and mouse/keyboard scrolling
- Total process count shown in the header
- Only top-level processes listed (threads hidden) — matches btop/top
- Optional GPU metrics (can be disabled)
- Optional auth token for the agent
2025-08-08 01:03:35 -07:00
2025-08-08 01:06:43 -07:00
---
2025-08-08 01:03:35 -07:00
2025-08-12 15:52:46 -07:00
## Prerequisites: Install Rust (rustup)
2025-08-08 12:41:32 -07:00
2025-08-12 15:52:46 -07:00
Rust is fast, safe, and cross‑ platform. Installing it will make your machine better. Consider yourself privileged.
2025-08-08 01:03:35 -07:00
2025-08-12 15:52:46 -07:00
Linux/macOS:
2025-08-08 13:22:57 -07:00
``` bash
2025-08-08 13:14:33 -07:00
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
2025-08-12 15:52:46 -07:00
# load cargo for this shell
source " $HOME /.cargo/env "
# ensure stable is up to date
rustup update stable
rustc --version
cargo --version
# after install you may need to reload your shell, e.g.:
exec bash # or: exec zsh / exec fish
2025-08-08 13:22:57 -07:00
```
2025-08-08 13:14:33 -07:00
2025-08-12 15:52:46 -07:00
Windows (for the brave): install from https://rustup.rs with the MSVC toolchain. Yes, you’ ll need Visual Studio Build Tools. You chose Windows — enjoy the ride.
2025-08-11 13:38:26 -07:00
2025-08-15 19:21:34 -07:00
### Raspberry Pi / Ubuntu / PopOS (required)
2025-08-12 16:48:35 -07:00
Install GPU support with apt command below
``` bash
sudo apt-get update
sudo apt-get install libdrm-dev libdrm-amdgpu1
```
2025-08-12 15:52:46 -07:00
---
2025-08-11 13:38:26 -07:00
2025-08-12 15:52:46 -07:00
## Architecture
2025-08-11 13:38:26 -07:00
2025-08-12 15:52:46 -07:00
Two components:
2025-08-11 13:38:26 -07:00
2025-08-12 15:52:46 -07:00
1) Agent (remote): small Rust WS server using sysinfo + /proc. It collects on demand when the client asks (fast metrics ~500 ms, processes ~2 s, disks ~5 s). No background loop when nobody is connected.
2025-08-11 13:38:26 -07:00
2025-08-16 01:23:20 -07:00
2) Client (local): TUI that connects to ws://HOST:PORT/ws (or wss://HOST:PORT/ws when TLS is enabled) and renders updates.
2025-08-11 13:38:26 -07:00
2025-08-12 15:52:46 -07:00
---
2025-08-11 13:38:26 -07:00
2025-08-12 15:52:46 -07:00
## Quick start
2025-08-11 13:38:26 -07:00
2025-08-12 15:52:46 -07:00
- Build both binaries:
2025-08-11 13:38:26 -07:00
2025-08-08 01:03:35 -07:00
``` bash
2025-08-08 13:09:53 -07:00
git clone https://github.com/jasonwitty/socktop.git
2025-08-08 01:06:43 -07:00
cd socktop
cargo build --release
2025-08-08 01:03:35 -07:00
```
2025-08-12 15:52:46 -07:00
- Start the agent on the target machine (default port 3000):
2025-08-08 01:03:35 -07:00
2025-08-08 01:06:43 -07:00
``` bash
2025-08-12 15:52:46 -07:00
./target/release/socktop_agent --port 3000
2025-08-08 01:06:43 -07:00
```
2025-08-08 01:03:35 -07:00
2025-08-12 15:52:46 -07:00
- Connect with the TUI from your local machine:
2025-08-08 01:03:35 -07:00
``` bash
2025-08-12 15:52:46 -07:00
./target/release/socktop ws://REMOTE_HOST:3000/ws
2025-08-08 01:06:43 -07:00
```
2025-08-08 01:03:35 -07:00
2025-08-12 15:52:46 -07:00
Tip: Add ?token=... if you enable auth (see Security).
2025-08-08 01:03:35 -07:00
2025-08-16 01:23:20 -07:00
TLS quick start (optional, recommended on untrusted networks):
- Start the agent with TLS enabled (default TLS port 8443). On first run it will generate a self‑ signed certificate and key under your config directory.
``` bash
./target/release/socktop_agent --enableSSL --port 8443 # or: -p 8443
# First run prints the cert and key paths, e.g.:
# socktop_agent: generated self-signed TLS certificate at /home/you/.config/socktop_agent/tls/cert.pem
# socktop_agent: private key at /home/you/.config/socktop_agent/tls/key.pem
```
- Copy the certificate file to the client machine (keep the key private on the server):
``` bash
scp /home/you/.config/socktop_agent/tls/cert.pem you@client:/tmp/socktop-agent-ca.pem
```
- Connect with the TUI, pinning the server cert:
``` bash
./target/release/socktop --tls-ca /tmp/socktop-agent-ca.pem wss://REMOTE_HOST:8443/ws
# Note: if you pass --tls-ca but use ws://, the client auto-upgrades to wss://
```
2025-08-08 01:03:35 -07:00
---
2025-08-12 15:52:46 -07:00
## Install (from crates.io)
2025-08-08 01:06:43 -07:00
2025-08-12 15:52:46 -07:00
You don’ t need to clone this repo to use socktop. Install the published binaries with cargo:
2025-08-09 22:40:44 -07:00
``` bash
2025-08-12 15:52:46 -07:00
# TUI (client)
cargo install socktop
# Agent (server)
cargo install socktop_agent
2025-08-09 22:40:44 -07:00
```
2025-08-12 15:52:46 -07:00
This drops socktop and socktop_agent into ~/.cargo/bin (add it to PATH).
2025-08-09 22:40:44 -07:00
2025-08-12 15:52:46 -07:00
Notes:
- After installing Rust via rustup, reload your shell (e.g., exec bash) so cargo is on PATH.
- Windows: you can also grab prebuilt EXEs from GitHub Actions artifacts if rustup scares you. It shouldn’ t. Be brave.
2025-08-09 22:40:44 -07:00
2025-08-12 15:52:46 -07:00
Option B: System-wide agent (Linux)
2025-08-09 22:40:44 -07:00
``` bash
2025-08-12 15:52:46 -07:00
# If you installed with cargo, binaries are in ~/.cargo/bin
sudo install -o root -g root -m 0755 " $HOME /.cargo/bin/socktop_agent " /usr/local/bin/socktop_agent
# Install and enable the systemd service (example unit in docs/)
2025-08-09 22:40:44 -07:00
sudo install -o root -g root -m 0644 docs/socktop-agent.service /etc/systemd/system/socktop-agent.service
sudo systemctl daemon-reload
2025-08-12 15:52:46 -07:00
sudo systemctl enable --now socktop-agent
2025-08-09 22:40:44 -07:00
```
2025-08-12 15:52:46 -07:00
---
2025-08-09 22:40:44 -07:00
2025-08-12 15:52:46 -07:00
## Usage
2025-08-09 22:40:44 -07:00
2025-08-12 15:52:46 -07:00
Agent (server):
2025-08-09 22:40:44 -07:00
``` bash
2025-08-12 15:52:46 -07:00
socktop_agent --port 3000
# or env: SOCKTOP_PORT=3000 socktop_agent
# optional auth: SOCKTOP_TOKEN=changeme socktop_agent
2025-08-16 01:23:20 -07:00
# enable TLS (self‑ signed cert, default port 8443; you can also use -p):
socktop_agent --enableSSL --port 8443
2025-08-09 22:40:44 -07:00
```
2025-08-12 15:52:46 -07:00
Client (TUI):
2025-08-09 22:40:44 -07:00
``` bash
2025-08-12 15:52:46 -07:00
socktop ws://HOST:3000/ws
# with token:
socktop "ws://HOST:3000/ws?token=changeme"
2025-08-16 01:23:20 -07:00
# TLS with pinned server certificate (recommended over the internet):
socktop --tls-ca /path/to/cert.pem wss://HOST:8443/ws
# shorthand:
socktop -t /path/to/cert.pem wss://HOST:8443/ws
# Note: providing --tls-ca/-t automatically upgrades ws:// to wss:// if you forget
2025-08-09 22:40:44 -07:00
```
2025-08-12 15:52:46 -07:00
Intervals (client-driven):
- Fast metrics: ~500 ms
- Processes: ~2 s (top 50)
- Disks: ~5 s
2025-08-09 22:40:44 -07:00
2025-08-12 15:52:46 -07:00
The agent stays idle unless queried. When queried, it collects just what’ s needed.
2025-08-09 22:40:44 -07:00
2025-08-12 15:52:46 -07:00
---
2025-08-09 22:40:44 -07:00
2025-08-12 15:52:46 -07:00
## Updating
2025-08-09 22:40:44 -07:00
2025-08-12 15:52:46 -07:00
Update the agent (systemd):
2025-08-09 22:40:44 -07:00
2025-08-12 15:52:46 -07:00
``` bash
# on the server running the agent
cargo install socktop_agent --force
sudo systemctl stop socktop-agent
sudo install -o root -g root -m 0755 " $HOME /.cargo/bin/socktop_agent " /usr/local/bin/socktop_agent
# if you changed the unit file:
# sudo install -o root -g root -m 0644 docs/socktop-agent.service /etc/systemd/system/socktop-agent.service
# sudo systemctl daemon-reload
sudo systemctl start socktop-agent
sudo systemctl status socktop-agent --no-pager
# logs:
# journalctl -u socktop-agent -f
2025-08-09 22:40:44 -07:00
```
2025-08-12 15:52:46 -07:00
Update the TUI (client):
2025-08-09 22:40:44 -07:00
``` bash
2025-08-12 15:52:46 -07:00
cargo install socktop --force
socktop ws://HOST:3000/ws
2025-08-09 22:40:44 -07:00
```
2025-08-12 15:52:46 -07:00
Tip: If only the binary changed, restart is enough. If the unit file changed, run sudo systemctl daemon-reload.
2025-08-08 12:41:32 -07:00
---
2025-08-12 15:52:46 -07:00
## Configuration (agent)
2025-08-08 13:00:36 -07:00
2025-08-12 15:52:46 -07:00
- Port:
- Flag: --port 8080 or -p 8080
- Positional: socktop_agent 8080
- Env: SOCKTOP_PORT=8080
2025-08-16 01:23:20 -07:00
- TLS (self‑ signed):
- Enable: --enableSSL
- Default TLS port: 8443 (override with --port/-p)
- Certificate/Key location (created on first TLS run):
- Linux (XDG): $XDG_CONFIG_HOME/socktop_agent/tls/{cert.pem,key.pem} (defaults to ~/.config)
- The agent prints these paths on creation.
- You can set XDG_CONFIG_HOME before first run to control where certs are written.
2025-08-12 15:52:46 -07:00
- Auth token (optional): SOCKTOP_TOKEN=changeme
- Disable GPU metrics: SOCKTOP_AGENT_GPU=0
- Disable CPU temperature: SOCKTOP_AGENT_TEMP=0
2025-08-08 13:00:36 -07:00
2025-08-12 15:52:46 -07:00
---
2025-08-08 13:00:36 -07:00
2025-08-12 15:52:46 -07:00
## Keyboard & Mouse
2025-08-08 13:00:36 -07:00
2025-08-12 15:52:46 -07:00
- Quit: q or Esc
- Processes pane:
- Click “CPU %” to sort by CPU descending
- Click “Mem” to sort by memory descending
- Mouse wheel: scroll
- Drag scrollbar: scroll
- Arrow/PageUp/PageDown/Home/End: scroll
2025-08-08 13:00:36 -07:00
---
2025-08-08 01:06:43 -07:00
## Example agent JSON
2025-08-12 15:52:46 -07:00
2025-08-08 01:06:43 -07:00
``` json
{
"cpu_total" : 12.4 ,
2025-08-12 15:52:46 -07:00
"cpu_per_core" : [ 11.2 , 15.7 ] ,
2025-08-08 01:06:43 -07:00
"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 }
2025-08-12 15:52:46 -07:00
] ,
"gpus" : null
2025-08-08 01:06:43 -07:00
}
```
2025-08-12 15:52:46 -07:00
Notes:
- process_count is merged into the main metrics on the client when processes are polled.
- top_processes are the current top 50 (sorting in the TUI is client-side).
2025-08-08 01:06:43 -07:00
---
2025-08-12 15:52:46 -07:00
## Security
Set a token on the agent and pass it as a query param from the client:
Server:
2025-08-08 01:06:43 -07:00
``` bash
2025-08-12 15:52:46 -07:00
SOCKTOP_TOKEN = changeme socktop_agent --port 3000
2025-08-08 01:06:43 -07:00
```
2025-08-12 15:52:46 -07:00
Client:
``` bash
socktop "ws://HOST:3000/ws?token=changeme"
```
2025-08-16 01:23:20 -07:00
### TLS / WSS
For encrypted connections, enable TLS on the agent and pin the server certificate on the client.
Server (generates self‑ signed cert and key on first run):
``` bash
socktop_agent --enableSSL --port 8443
```
Client (trust/pin the server cert; copy cert.pem from the agent):
``` bash
socktop --tls-ca /path/to/agent/cert.pem wss://HOST:8443/ws
```
Notes:
- Do not copy the private key off the server; only the cert.pem is needed by clients.
- When --tls-ca/-t is supplied, the client auto‑ upgrades ws:// to wss:// to avoid protocol mismatch.
- You can run multiple clients with different cert paths by passing --tls-ca per invocation.
2025-08-12 15:52:46 -07:00
---
2025-08-12 17:02:01 -07:00
## Using tmux to monitor multiple hosts
You can use tmux to show multiple socktop instances in a single terminal.
2025-08-12 17:12:27 -07:00

2025-08-12 17:02:01 -07:00
monitoring 4 Raspberry Pis using Tmux
Prerequisites:
- Install tmux (Ubuntu/Debian: `sudo apt-get install tmux` )
Key bindings (defaults):
- Split left/right: Ctrl-b %
- Split top/bottom: Ctrl-b "
- Move between panes: Ctrl-b + Arrow keys
- Show pane numbers: Ctrl-b q
- Close a pane: Ctrl-b x
- Detach from session: Ctrl-b d
Two panes (left/right)
- This creates a session named "socktop", splits it horizontally, and starts two socktops.
``` bash
tmux new-session -d -s socktop 'socktop ws://HOST1:3000/ws' \; \
split-window -h 'socktop ws://HOST2:3000/ws' \; \
select -layout even-horizontal \; \
attach
```
Four panes (top-left, top-right, bottom-left, bottom-right)
- This creates a 2x2 grid with one socktop per pane.
``` bash
tmux new-session -d -s socktop 'socktop ws://HOST1:3000/ws' \; \
split-window -h 'socktop ws://HOST2:3000/ws' \; \
select -pane -t 0 \; split-window -v 'socktop ws://HOST3:3000/ws' \; \
select -pane -t 1 \; split-window -v 'socktop ws://HOST4:3000/ws' \; \
select -layout tiled \; \
attach
```
Tips:
- Replace HOST1..HOST4 (and ports) with your targets.
- Reattach later: `tmux attach -t socktop`
---
2025-08-12 15:52:46 -07:00
## Platform notes
- Linux: fully supported (agent and client).
- Raspberry Pi:
- 64-bit: aarch64-unknown-linux-gnu
- 32-bit: armv7-unknown-linux-gnueabihf
- Windows:
- TUI + agent can build with stable Rust; bring your own MSVC. You’ re on Windows; you know the drill.
- CPU temperature may be unavailable.
2025-08-12 16:48:35 -07:00
- binary exe for both available in build artifacts under actions.
2025-08-12 15:52:46 -07:00
- macOS:
2025-08-12 16:48:35 -07:00
- TUI works; agent is primarily targeted at Linux. Agent will run just fine on macos for debugging but I have not documented how to run as a service, I may not given the "security" feautures with applications on macos. We will see.
2025-08-12 15:52:46 -07:00
---
## Development
2025-08-08 01:03:35 -07:00
``` bash
2025-08-08 01:06:43 -07:00
cargo fmt
2025-08-12 15:52:46 -07:00
cargo clippy --all-targets --all-features
cargo run -p socktop -- ws://127.0.0.1:3000/ws
2025-08-16 01:23:20 -07:00
# TLS (dev): first run will create certs under ~/.config/socktop_agent/tls/
cargo run -p socktop_agent -- --enableSSL --port 8443
2025-08-08 01:03:35 -07:00
```
---
2025-08-08 01:06:43 -07:00
## Roadmap
2025-08-12 15:52:46 -07:00
- [x] Agent authentication (token)
- [x] Hide per-thread entries; only show processes
- [x] Sort top processes in the TUI
- [ ] Configurable refresh intervals (client)
2025-08-08 01:06:43 -07:00
- [ ] Export metrics to file
2025-08-16 01:23:20 -07:00
- [x] TLS / WSS support (self‑ signed server cert + client pinning)
2025-08-12 15:52:46 -07:00
- [x] Split processes/disks to separate WS calls with independent cadences (already logical on client; formalize API)
2025-08-08 01:06:43 -07:00
---
## License
2025-08-12 15:52:46 -07:00
MIT — see LICENSE.
2025-08-08 01:06:43 -07:00
---
## Acknowledgements
2025-08-12 15:52:46 -07:00
- ratatui for the TUI
- sysinfo for system metrics
- tokio-tungstenite for WebSockets