-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpinger.go
More file actions
31 lines (26 loc) · 760 Bytes
/
pinger.go
File metadata and controls
31 lines (26 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main
import (
"fmt"
"net"
probing "github.com/prometheus-community/pro-bing"
)
func Ping(route *Route, dest *Destination, ip net.IP) bool {
pinger, err := probing.NewPinger(ip.String())
if err != nil {
dest.Increment("connectivity.icmp.error", []string{})
LogRouteError(route, fmt.Sprintf("Failed to setup ping to %s", ip.String()), err)
return false
}
pinger.Count = 1
err = pinger.Run()
if err != nil {
dest.Increment("connectivity.icmp.error", []string{})
LogRouteError(route, fmt.Sprintf("Failed to ping %s", ip.String()), err)
return false
}
// Emit metrics
stats := pinger.Statistics()
dest.Increment("connectivity.icmp.success", []string{})
dest.Timer("connectivity.icmp", stats.AvgRtt, []string{})
return true
}