How thewtex/tmux-mem-cpu-load works
Project type and purpose
• Type: A small native command-line monitoring tool written in modern C++.
• Purpose: Gather CPU, memory, and load-average metrics from the host OS; render them as a textual bar graph and statistics line for embedding in tmux status lines.
File structure
• Top level:
• builder/ → Shell scripts for CMake and Makefile–based builds
• common/ → Core logic and abstractions shared across OS targets
• freebsd/, linux/, netbsd/, openbsd/, osx/, windows/
→ OS-specific implementations for CPU, memory, load
• CMakeLists.txt → CMake build configuration
• Key patterns:
• “common” holds interfaces, utility code, main entry point
• Each OS directory overrides CPU/memory functions via polymorphic linkage
• builder scripts automate cmake/make sequences
• No frontend/backend split – it’s a single binary that interacts with OS services and outputs to stdout.
Extract architecture details from the README
• Outputs a combined line: memory usage, CPU bar graph, CPU percent, 1/5/15-minute load averages
• Integrates with tmux via plugin scripts (tmux and zsh plugins), but the core is the CLI binary.
Components & interactions
a. Main components:
1. CLI Argument Parser
2. MetricCollector
– CPU Module (abstract interface)
– Memory Module (abstract interface)
– LoadAverage Module (via common/getsysctl or OS syscalls)
3. OS Adapter Layer
– One implementation per OS directory (linux/cpu.cc, windows/memory.cc, etc.)
4. Graph & Formatter
– LUT generator (common/generate-luts.py + common/luts.h)
– GraphRenderer (common/graph.cc)
– OutputFormatter (common/main.cc)
5. Stdout / tmux status line
b. Relationships / data flow:
• CLI Parser reads flags → invokes MetricCollector
• MetricCollector calls OS Adapter Layer → returns raw metrics
• GraphRenderer + LUTs → create text bars
• tmux captures stdout → displays in status line
c. Architectural patterns:
• Strategy/Interface pattern for OS-specific modules
• Modular separation of data gathering vs. rendering vs. CLI logic
d. Key technologies:
• C++11
• CMake build system (+ optional Makefiles via builder/)
• Shell scripts for automated builds
• tmux plugin integration (external)