Skip to content

feat(batch): add json/csv output, max-loss exit code, and RTT jitter - #58

Merged
servak merged 2 commits into
mainfrom
feature/batch-automation
Sep 23, 2026
Merged

servak merged 2 commits into
mainfrom
feature/batch-automation

Conversation

@servak

@servak servak commented Sep 23, 2026

Copy link
Copy Markdown
Owner

Summary

Make mping batch usable from scripts, CI, and monitoring systems.

  • -o/--output table|json|csv: machine-readable results. RTT fields are in milliseconds, timestamps are RFC3339, and zero timestamps are omitted.
  • --max-loss PCT: exit with status 2 when any target's loss exceeds the threshold (violators are listed on stderr). Usage/config errors still exit 1.
  • RTT jitter: standard deviation of RTT (same as mdev in iputils ping), shown in the TUI host detail panel and in json/csv output.
  • Clean stdout: progress dots go to stderr only when it is a TTY, and the failure beep (\a) is disabled in batch mode.
  • -I/--interface for batch, for parity with the interactive mode.

Bug fix

--count N used to send N+1 probes, because the wait (N*interval) raced the next ticker round. Batch now stops half an interval after the last round. Stop() already waits for in-flight probes, so the final replies are still collected.

Test plan

  • go test ./... (added tests for jitter, json/csv export, max-loss boundaries, and flag validation)
  • go test -race on the changed packages
  • E2E with TCP targets: --count 1/3/5 → exactly 1/3/5 sent; --max-loss 0 → exit 2; no BEL on stdout
  • ICMP E2E (requires privileges)

🤖 Generated with Claude Code

servak and others added 2 commits September 23, 2026 16:15
- Add -o/--output (table, json, csv) for machine-readable batch results
- Add --max-loss to exit with status 2 when any target exceeds the threshold
- Add -I/--interface to batch for parity with interactive mode
- Track RTT jitter (stddev, equivalent to ping's mdev) and show it in
  host details and json/csv output
- Write progress to stderr only when it is a terminal and disable the
  failure beep in batch mode so stdout stays clean for pipes
- Fix --count sending count+1 probes by stopping half an interval after
  the last round instead of racing the next tick

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Measure batch wait deadlines from a fixed start so sleep overshoot
  does not accumulate and exceed --count on long runs
- Add shared.ValidateOutputFormat and use it from batch and WriteReport
- Reuse WriteReport for the interactive mode's final table
- Keep CSV header and row together via csvHeader/csvRecord, with a test
- Add MetricsManager.SetBeepEnabled instead of check-and-toggle
- Drop redundant cancel() and unreachable "" format case
@servak
servak merged commit 2aec9d9 into main Sep 23, 2026
4 checks passed
@servak
servak deleted the feature/batch-automation branch September 23, 2026 07:46
servak added a commit that referenced this pull request Sep 24, 2026
feat(batch): add json/csv output, max-loss exit code, and RTT jitter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant