Overview

Date: 2026-05-11

Time: 15:51

Overview

ftl2_htop.py is a distributed system monitoring TUI — essentially a remote htop built on FTL2's event-driven gate protocol. It connects to remote hosts via FTL2's SSH subsystem, streams real-time system metrics (CPU, memory, disk, network, processes) using psutil on the remote side, and renders them as a live-updating terminal dashboard using rich. It also supports WebSocket broadcasting for PWA clients and an optional Textual TUI mode.

Usage Patterns

The script is invoked via uv run as an inline-dependency script or through the cli() entry point:


# Monitor specific hosts (builds inventory dynamically)
uv run ftl2_htop.py web1.example.com web2.example.com

# Use an inventory file
uv run ftl2_htop.py -i inventory.yml

# Load hosts from a state file
uv run ftl2_htop.py -S .ftl2-state.json

# Filter to specific host groups
uv run ftl2_htop.py -i inventory.yml -g webservers databases

# Debug mode — raw events to stderr, no TUI
uv run ftl2_htop.py -i inventory.yml --debug

# WebSocket broadcast for live dashboards
uv run ftl2_htop.py -i inventory.yml --ws-port 8765

The core flow: cli()main() → opens automation() context → calls proxy.monitor() on each group → registers SystemMetrics event handlers → runs rich.Live display loop concurrently with ftl.listen().

API and Configuration

CLI Arguments:

| Argument | Description |

|---|---|

| hosts (positional) | Hostnames to monitor; builds inventory dict dynamically |

| -i, --inventory | Path to inventory YAML file |

| -S, --state | State file (.ftl2-state.json) to load hosts from |

| -g, --groups | Host groups to monitor (default: all groups) |

| --interval | Metrics sampling interval in seconds (default: 2.0) |

| --no-processes | Exclude process list from metrics (reduces bandwidth) |

| --debug | Print raw events to stderr, disable TUI |

| --tui | Use Textual TUI (for textual-serve compatibility) |

| --ws-port | WebSocket port for live metrics broadcast (e.g. 8765) |

Environment Variables:

Prerequisite on remote hosts:


await ftl.hosts.dnf(name="python3-psutil", state="present")

Key Behaviors

Relationships