This commit is contained in:
Bel LaPointe
2026-06-08 13:10:29 -07:00
parent 8e202a0381
commit 3a5819007f
2 changed files with 5 additions and 3 deletions

View File

@@ -34,19 +34,20 @@ func run() error {
switch *o { switch *o {
case "csv": case "csv":
fmt.Printf("ts,n,ok_pct,max,avg,stddev\n") fmt.Printf("ts,n,ok_pct,last,max,avg,stddev\n")
case "json": case "json":
default: default:
panic(*o) panic(*o)
} }
pinger.OnRecv = func(*ping.Packet) { pinger.OnRecv = func(packet *ping.Packet) {
stat := pinger.Statistics() stat := pinger.Statistics()
switch *o { switch *o {
case "csv": case "csv":
fmt.Printf("%s,%d,%.0f%%,%dms,%dms,%dms\n", fmt.Printf("%s,%d,%.0f%%,%dms,%dms,%dms,%dms\n",
time.Now().UTC().Format("2006-01-02T15:04:05Z"), time.Now().UTC().Format("2006-01-02T15:04:05Z"),
stat.PacketsRecv, stat.PacketsRecv,
stat.PacketLoss, stat.PacketLoss,
packet.Rtt.Milliseconds(),
stat.MaxRtt.Milliseconds(), stat.MaxRtt.Milliseconds(),
stat.AvgRtt.Milliseconds(), stat.AvgRtt.Milliseconds(),
stat.StdDevRtt.Milliseconds(), stat.StdDevRtt.Milliseconds(),
@@ -56,6 +57,7 @@ func run() error {
"ts": time.Now().UTC().Format("2006-01-02T15:04:05Z"), "ts": time.Now().UTC().Format("2006-01-02T15:04:05Z"),
"n": stat.PacketsRecv, "n": stat.PacketsRecv,
"bad_pct": stat.PacketLoss, "bad_pct": stat.PacketLoss,
"last": packet.Rtt.Milliseconds(),
"max": stat.MaxRtt.Milliseconds(), "max": stat.MaxRtt.Milliseconds(),
"avg": stat.AvgRtt.Milliseconds(), "avg": stat.AvgRtt.Milliseconds(),
"stddev": stat.StdDevRtt.Milliseconds(), "stddev": stat.StdDevRtt.Milliseconds(),

BIN
pingd

Binary file not shown.