Added max rtt and max avg rtt to ping check
This commit is contained in:
parent
5c55903e88
commit
233aec7010
@ -14,6 +14,8 @@ const (
|
||||
TK_TIMEOUT
|
||||
TK_INTERVAL
|
||||
TK_MAXPACKETLOSS
|
||||
TK_MAXRTT
|
||||
TK_MAXAVGRTT
|
||||
)
|
||||
|
||||
type CheckPing struct {
|
||||
@ -23,6 +25,8 @@ type CheckPing struct {
|
||||
Timeout time.Duration
|
||||
Interval time.Duration
|
||||
MaxPacketLoss float64
|
||||
MaxRTT time.Duration
|
||||
MaxAvgRTT time.Duration
|
||||
state int
|
||||
}
|
||||
|
||||
@ -63,11 +67,22 @@ func (c *CheckPing) Check(debuglvl int) error {
|
||||
|
||||
if debuglvl > 0 {
|
||||
fmt.Printf("Packet loss: %.f%%\n", stats.PacketLoss)
|
||||
fmt.Printf("Max RTT: %s\n", stats.MaxRtt.String())
|
||||
fmt.Printf("Max Configured RTT: %s\n", c.MaxRTT.String())
|
||||
fmt.Printf("Average RTT: %s\n", stats.AvgRtt.String())
|
||||
}
|
||||
|
||||
if stats.PacketLoss > c.MaxPacketLoss {
|
||||
return fmt.Errorf("ping packet loss exceeds max")
|
||||
}
|
||||
|
||||
if c.MaxRTT > 0 && stats.MaxRtt > c.MaxRTT {
|
||||
return fmt.Errorf("ping rtt exceeds max")
|
||||
}
|
||||
|
||||
if c.MaxAvgRTT > 0 && stats.AvgRtt > c.MaxAvgRTT {
|
||||
return fmt.Errorf("ping average rtt exceeds max")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -84,6 +99,10 @@ func (c *CheckPing) Parse(tk string) (bool, error) {
|
||||
c.state = TK_INTERVAL
|
||||
case "maxpacketloss":
|
||||
c.state = TK_MAXPACKETLOSS
|
||||
case "maxrtt":
|
||||
c.state = TK_MAXRTT
|
||||
case "maxavgrtt":
|
||||
c.state = TK_MAXAVGRTT
|
||||
default:
|
||||
return false, nil
|
||||
}
|
||||
@ -116,6 +135,20 @@ func (c *CheckPing) Parse(tk string) (bool, error) {
|
||||
}
|
||||
c.state = TK_NONE
|
||||
|
||||
case TK_MAXRTT:
|
||||
c.MaxRTT, err = time.ParseDuration(tk)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("invalid maxrtt \"%s\"", tk)
|
||||
}
|
||||
c.state = TK_NONE
|
||||
|
||||
case TK_MAXAVGRTT:
|
||||
c.MaxAvgRTT, err = time.ParseDuration(tk)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("invalid maxavgrtt \"%s\"", tk)
|
||||
}
|
||||
c.state = TK_NONE
|
||||
|
||||
default:
|
||||
return false, fmt.Errorf("invalid state in check_ping")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user