diff --git a/Cargo.lock b/Cargo.lock index fc42cc4..77db37f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -99,7 +99,7 @@ dependencies = [ [[package]] name = "btest-rs" -version = "0.5.0" +version = "0.6.0" dependencies = [ "anyhow", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 312ab4c..f81188a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "btest-rs" -version = "0.5.0" +version = "0.6.0" edition = "2021" description = "MikroTik Bandwidth Test (btest) server and client with EC-SRP5 auth — a Rust reimplementation" license = "MIT AND Apache-2.0" diff --git a/README.md b/README.md index 010a108..0ec8bc8 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ A Rust reimplementation of the [MikroTik Bandwidth Test (btest)](https://wiki.mi - **Bidirectional testing** -- simultaneous upload and download - **Syslog logging** -- send structured events (auth, test start/end) to a remote syslog server - **CSV output** -- append machine-readable test results to a CSV file +- **CPU usage monitoring** -- local and remote CPU shown per interval, warning at >70% - **Timed tests** -- `--duration` flag to automatically stop after N seconds - **Quiet mode** -- suppress terminal output for scripted/automated use - **NAT traversal** -- probe packet to open firewall holes for UDP receive diff --git a/docs/architecture.md b/docs/architecture.md index 467be25..eab4c40 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -219,6 +219,14 @@ IPv6 requires special handling on macOS: - NDP probe packet sent before data blast to populate neighbor cache - Adaptive backoff on ENOBUFS (200μs→10ms, resets on success) +### 11. CPU usage monitoring + +A background OS thread samples system CPU every 1 second via: +- **macOS:** `host_statistics(HOST_CPU_LOAD_INFO)` — returns user/system/idle/nice ticks +- **Linux:** `/proc/stat` — reads aggregate CPU line + +The percentage is stored in a global `AtomicU8` and included in every status message at byte 1 using MikroTik's encoding: `0x80 | percentage`. On receive, the remote CPU is decoded with `byte & 0x7F` and capped at 100%. Both local and remote CPU are displayed per interval and logged to CSV/syslog. + ## File Layout ``` @@ -232,6 +240,7 @@ btest-rs/ │ ├── server.rs # Server mode: listener, TCP/UDP handlers │ ├── client.rs # Client mode: connector, TCP/UDP handlers │ ├── bandwidth.rs # Rate limiting, formatting, shared state +│ ├── cpu.rs # CPU usage sampler (macOS + Linux) │ ├── csv_output.rs # CSV result logging (append-mode, auto-header) │ └── syslog_logger.rs # Remote syslog sender (RFC 3164 / BSD format) ├── tests/ diff --git a/docs/man/btest.1 b/docs/man/btest.1 index 065997f..403963f 100644 --- a/docs/man/btest.1 +++ b/docs/man/btest.1 @@ -1,5 +1,5 @@ .\" btest-rs manual page -.\" Generated for btest-rs v0.5.0 +.\" Generated for btest-rs v0.6.0 .TH BTEST 1 "2026-03-31" "btest-rs 0.5.0" "User Commands" .SH NAME btest \- MikroTik Bandwidth Test server and client diff --git a/docs/user-guide.md b/docs/user-guide.md index de3837e..da8351a 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -235,10 +235,11 @@ btest -c 192.168.88.1 -r -P 3000 ## Reading the Output ``` -[ 1] TX 264.50 Mbps (33062912 bytes) -[ 2] TX 263.98 Mbps (32997376 bytes) -[ 2] RX 263.98 Mbps (32997012 bytes) -[ 3] RX 430.51 Mbps (53813376 bytes) lost: 5 +[ 1] TX 264.50 Mbps (33062912 bytes) cpu: 12%/0% +[ 2] TX 263.98 Mbps (32997376 bytes) cpu: 15%/33% +[ 2] RX 263.98 Mbps (32997012 bytes) cpu: 15%/33% +[ 3] RX 430.51 Mbps (53813376 bytes) lost: 5 cpu: 18%/45% +[ 4] RX 450.00 Mbps (56250000 bytes) cpu: 72%/85% ! ``` | Field | Meaning | @@ -249,6 +250,8 @@ btest -c 192.168.88.1 -r -P 3000 | `Mbps` | Megabits per second | | `bytes` | Raw bytes transferred in this interval | | `lost: N` | UDP packets lost in this interval (UDP mode only) | +| `cpu: L%/R%` | Local CPU / Remote CPU usage percentage | +| `!` | Warning: CPU usage exceeds 70% on either side | ## Complete CLI Reference