Motivation
I need to maintain more than 20 physical servers at work. I connect to them via SSH and have to access each one individually to check CPU usage, disk usage, GPU usage, etc.
This process is time-consuming and doesn't scale well, so I built a tool to handle it.
Introducing ssh-monitor
ssh-monitor is a terminal tool that discovers SSH hosts from your config and shows real-time metrics in an interactive view.
Installation
Start the SSH agent and add your keys:
ssh-agent
ssh-add ~/.ssh/id_rsa
Install ssh-monitor:
curl -sSL https://raw.githubusercontent.com/tsugumi-sys/ssh-monitor/main/install.sh | bash
Run it:
ssh-monitor
Current Features
It auto-discovers hosts from your SSH config, uses a Ratatui-based UI for smooth navigation, and tracks CPU, memory, disk, and GPU metrics when available.
How It Works
Run ssh-monitor; it discovers hosts, shows a navigable list, and opens real-time charts for a selected host. CPU timelines, memory, disk, and GPU metrics update continuously.
Technical Implementation: Efficient SSH Connections
Minimizing SSH connections was the main challenge. Opening one session per metric would mean 120 connections per minute for 10 servers checked every five seconds. Instead, ssh-monitor batches metrics in a single session:
echo __BEGIN_cpu__
bash -c '
if [[ "$(uname)" == "Darwin" ]]; then
sysctl -a;
else
lscpu;
fi
'
echo __END_cpu__
echo __BEGIN_mem__
bash -c 'uname -s && echo __MEM__ && (free -m || (echo __MAC__ && sysctl -n hw.memsize && vm_stat))'
echo __END_mem__
echo __BEGIN_disk__
df -Pm | tail -n +2
echo __END_disk__
Delimiter tags separate metrics so the tool can parse everything from one command run, cutting connections from 120 to about 30 per minute.