You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
945 B

package main
import (
"github.com/go-ping/ping"
"github.com/sirupsen/logrus"
"time"
)
var log *logrus.Logger
func main() {
log = logrus.New()
for {
pinger, err := ping.NewPinger("ucs.osb-alliance.de")
if err != nil {
log.WithFields(logrus.Fields{"error": err}).Error("Pinger error")
}
pinger.Debug = true
pinger.SetPrivileged(true)
pinger.SetLogger(log)
pinger.Count = 10
err = pinger.Run() // blocks until finished
if err != nil {
log.WithFields(logrus.Fields{"error": err}).Error("Pinger error")
}
stats := pinger.Statistics() // get send/receive/rtt stats
log.WithFields(logrus.Fields{
"MinRTT": float64(stats.MinRtt.Nanoseconds()) / 1000000,
"MaxRTT": float64(stats.MaxRtt.Nanoseconds()) / 1000000,
"Median": float64(stats.AvgRtt.Nanoseconds()) / 1000000,
"Loss": stats.PacketLoss,
"Timestamp": time.Now()}).Info()
time.Sleep(time.Duration(120 * time.Second))
}
}