From d846e021ac97a29e2340f34fce4680fe65000240 Mon Sep 17 00:00:00 2001 From: Giovanni Harting <539@idlegandalf.com> Date: Wed, 15 Nov 2023 20:38:28 +0100 Subject: [PATCH] fix max packetloss being over 100% --- ping-package.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ping-package.go b/ping-package.go index 00db4cd..b8a3bc5 100644 --- a/ping-package.go +++ b/ping-package.go @@ -24,8 +24,8 @@ var ( PingCount = flag.Int("count", 5, "how many pings to average") PingWarningLimit = flag.Int("warn", 50, "ping warning limit") PingCritLimit = flag.Int("crit", 100, "ping critical limit") - PacketLossWarnLimit = flag.Int("pwarn", 10, "package-loss warning limit") - PacketLossCritLimit = flag.Int("pcrit", 25, "package-loss critical limit") + PacketLossWarnLimit = flag.Int("pwarn", 10, "packetloss warning limit") + PacketLossCritLimit = flag.Int("pcrit", 25, "packetloss critical limit") Host = flag.String("host", "google.com", "host to ping") WarnColor = flag.String("warnc", "ffbf00", "hex color for warning ping (without #)") CritColor = flag.String("critc", "ff5050", "hex color for critical ping (without #)") @@ -49,7 +49,7 @@ type WaybarOut struct { func formatLinePolybar(stats *PingStats) { if stats.PacketLoss >= 100.0 { - // fontawesome/forkawesome don't have a fitting icon, so we use 🚫 from UTF-8 symbols/emoji + // fontawesome/forkawesome don't have a fitting (free) icon, so we use 🚫 from UTF-8 symbols/emoji fmt.Printf("%%{F#%s}🚫\n", *CritColor) return } @@ -121,7 +121,7 @@ func (cp *ContinuousPinger) Stats(dSent, dReceive int) (*PingStats, error) { } } ps.AvgRtt = time.Duration(sum / int64(pkgsInArr)) - ps.PacketLoss = 100.0 - (float64(dReceive) / float64(dSent) * 100.0) + ps.PacketLoss = math.Min(100, 100-(float64(dReceive)/float64(dSent)*100)) stdDev, err := stats.StandardDeviation(rttArray) if err != nil { return nil, err