lmtop authoring skill

lmtop is a non-interactive host resource monitor for Linux, macOS, and Windows that exposes CPU, memory, disk, and network telemetry as a newline-delimited JSON (NDJSON) server over stdin and stdout. It samples 24 host-normalized metrics on a deterministic tick schedule, retains history in a fixed-cap memory ring buffer, and serves instant snapshots, downsampled time series, and percentile summaries.

Purpose

Use lmtop to collect machine-readable CPU, memory, block I/O, and network interface metrics during benchmarks, load tests, or production diagnostics without parsing human-oriented top or vmstat terminal output. It supports both ephemeral one-shot queries via lmtop client and long-running background telemetry collection via lmtop server connected to pipes or FIFOs.

When to use it

Choose lmtop whenever an automated agent or test harness needs host-level CPU utilization, hottest-core saturation, available memory, swap usage, deduplicated physical disk throughput/IOPS, network packet/byte/drop rates, or Linux Pressure Stall Information (PSI) over a time window. Use lmdebug when debugging or profiling specific target processes and threads, and use lmcurl or lmnet when measuring endpoint or socket latency.

Install

Download the pre-built standalone binary for your platform (lmtop-linux-x86_64, lmtop-linux-arm64, lmtop-macos-x86_64, lmtop-macos-arm64, lmtop-windows-x86_64.exe, or lmtop-windows-arm64.exe) from GitHub Releases and place it on your PATH, or build from source with CMake and a C++17 toolchain. Linux binaries are fully static with zero external runtime dependencies.

cmake -B build && cmake --build build -j
./build/lmtop --help

Commands

lmtop provides two subcommands: server (the default when no subcommand is given) and client (supporting both automatic child-spawn mode and POSIX named-pipe FIFO mode).

# Run the stdio NDJSON server (default 1000 ms interval, 100 MiB ring buffer cap)
lmtop server --interval 500 --cap-mb 100

# One-shot CLI client queries (spawns a private server, queries, and stops it)
lmtop client status
lmtop client --interval 250 now
lmtop client --interval 250 summary

# Supervised background server with POSIX FIFOs for continuous history accumulation
mkfifo /tmp/lmtop.in /tmp/lmtop.out
lmtop server --interval 1000 < /tmp/lmtop.in > /tmp/lmtop.out 2>/tmp/lmtop.log &
sleep 3
lmtop client --id 10 --in /tmp/lmtop.in --out /tmp/lmtop.out now
lmtop client --id 11 --in /tmp/lmtop.in --out /tmp/lmtop.out summary '{"seconds": 60}'
lmtop client --id 12 --in /tmp/lmtop.in --out /tmp/lmtop.out history '{"seconds": 60, "max_points": 30}'
lmtop client --id 13 --in /tmp/lmtop.in --out /tmp/lmtop.out stop

Inputs and outputs

In server mode, lmtop reads one UTF-8 JSON object per line on stdin ({"id": <int>, "method": "<name>", "params": {...}}) and writes one JSON response line per request on stdout ({"id": <int>, "result": {...}} or {"id": <int>, "error": "<msg>"}). All human-readable startup warnings and diagnostics are written strictly to stderr. Missing or unavailable metrics (such as counter resets, hot-plugged devices on their first tick, or Linux PSI on macOS and Windows) are emitted as -1.

Safety rules

Follow these operational rules when integrating lmtop into scripts and agent workflows:

Worked examples

The first example drives lmtop server over bidirectional stdio pipes from a shell pipeline to inspect the server catalog, capture a live sample, and shut down cleanly:

printf '{"id":1,"method":"status"}\n{"id":2,"method":"now"}\n{"id":3,"method":"stop"}\n' \
  | lmtop server --interval 200

The second example supervises a background lmtop server across a workload run and queries both the window summary statistics and a downsampled 10-point history trace:

mkfifo /tmp/bench.in /tmp/bench.out
lmtop server --interval 200 --cap-mb 32 < /tmp/bench.in > /tmp/bench.out 2>/tmp/bench.err &
SERVER_PID=$!
sleep 2
lmtop client --id 1 --in /tmp/bench.in --out /tmp/bench.out now
lmtop client --id 2 --in /tmp/bench.in --out /tmp/bench.out summary '{"seconds": 10}'
lmtop client --id 3 --in /tmp/bench.in --out /tmp/bench.out history '{"seconds": 10, "max_points": 10}'
lmtop client --id 4 --in /tmp/bench.in --out /tmp/bench.out stop
wait $SERVER_PID
rm -f /tmp/bench.in /tmp/bench.out

Errors and exit codes

lmtop uses distinct exit codes for clean execution, runtime I/O or communication failures, and CLI argument errors:

How to verify

Verify an installed or newly built lmtop binary by checking --help, running a one-shot status and now query, and running the cross-platform integration suite:

lmtop --help
lmtop client status
lmtop client --interval 200 now
python3 tests/integration.py build

The integration test launches a live server at a 200 ms sampling interval, generates synthetic CPU and fsync disk load over 10 seconds, verifies all 24 metric bounds, CPU slice identities, Welford summary statistics, stride downsampling, error envelopes on malformed JSON, and clean stop shutdown.