fix max packetloss being over 100%
This commit is contained in:
@@ -24,8 +24,8 @@ var (
|
|||||||
PingCount = flag.Int("count", 5, "how many pings to average")
|
PingCount = flag.Int("count", 5, "how many pings to average")
|
||||||
PingWarningLimit = flag.Int("warn", 50, "ping warning limit")
|
PingWarningLimit = flag.Int("warn", 50, "ping warning limit")
|
||||||
PingCritLimit = flag.Int("crit", 100, "ping critical limit")
|
PingCritLimit = flag.Int("crit", 100, "ping critical limit")
|
||||||
PacketLossWarnLimit = flag.Int("pwarn", 10, "package-loss warning limit")
|
PacketLossWarnLimit = flag.Int("pwarn", 10, "packetloss warning limit")
|
||||||
PacketLossCritLimit = flag.Int("pcrit", 25, "package-loss critical limit")
|
PacketLossCritLimit = flag.Int("pcrit", 25, "packetloss critical limit")
|
||||||
Host = flag.String("host", "google.com", "host to ping")
|
Host = flag.String("host", "google.com", "host to ping")
|
||||||
WarnColor = flag.String("warnc", "ffbf00", "hex color for warning ping (without #)")
|
WarnColor = flag.String("warnc", "ffbf00", "hex color for warning ping (without #)")
|
||||||
CritColor = flag.String("critc", "ff5050", "hex color for critical ping (without #)")
|
CritColor = flag.String("critc", "ff5050", "hex color for critical ping (without #)")
|
||||||
@@ -49,7 +49,7 @@ type WaybarOut struct {
|
|||||||
|
|
||||||
func formatLinePolybar(stats *PingStats) {
|
func formatLinePolybar(stats *PingStats) {
|
||||||
if stats.PacketLoss >= 100.0 {
|
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)
|
fmt.Printf("%%{F#%s}🚫\n", *CritColor)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -121,7 +121,7 @@ func (cp *ContinuousPinger) Stats(dSent, dReceive int) (*PingStats, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ps.AvgRtt = time.Duration(sum / int64(pkgsInArr))
|
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)
|
stdDev, err := stats.StandardDeviation(rttArray)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Reference in New Issue
Block a user