1
0
Fork 0
mirror of https://github.com/pnx/pinger.git synced 2026-06-16 03:24:54 +02:00

main.go: add option to changes stats interval.

This commit is contained in:
Henrik Hautakoski 2025-05-25 22:26:12 +02:00
parent cef5f5daba
commit ab292886a8

View file

@ -22,8 +22,7 @@ func printStats(pinger *probing.Pinger) {
stats.MinRtt, stats.AvgRtt, stats.MaxRtt, stats.StdDevRtt) stats.MinRtt, stats.AvgRtt, stats.MaxRtt, stats.StdDevRtt)
} }
func eventLoop(pinger *probing.Pinger) { func eventLoop(pinger *probing.Pinger, ticker *time.Ticker) {
ticker := time.NewTicker(time.Second * 4)
defer ticker.Stop() defer ticker.Stop()
defer pinger.Stop() defer pinger.Stop()
@ -52,6 +51,7 @@ func main() {
count := getopt.IntLong("count", 'c', 0, "Stop after this many packages has been sent (and received). If this option is not specified, pinger will operate until interrupted.") count := getopt.IntLong("count", 'c', 0, "Stop after this many packages has been sent (and received). If this option is not specified, pinger will operate until interrupted.")
timeout := getopt.DurationLong("timeout", 't', 0, "Exit the program after this time is reached, regardless of how many packets have been received.") timeout := getopt.DurationLong("timeout", 't', 0, "Exit the program after this time is reached, regardless of how many packets have been received.")
interval := getopt.DurationLong("interval", 'i', time.Second*2, "Wait time between each packet send") interval := getopt.DurationLong("interval", 'i', time.Second*2, "Wait time between each packet send")
statsInterval := getopt.DurationLong("stats-interval", 0, time.Second*4, "How often stats should be printed to the console.")
proto_udp := getopt.BoolLong("udp", 0, "Send UDP ping instead of a raw IMCP ping, IMCP required super-user privileges") proto_udp := getopt.BoolLong("udp", 0, "Send UDP ping instead of a raw IMCP ping, IMCP required super-user privileges")
record_rtt := getopt.BoolLong("rtt", 0, "Keep a record of rtts of all received packets.") record_rtt := getopt.BoolLong("rtt", 0, "Keep a record of rtts of all received packets.")
@ -85,7 +85,7 @@ func main() {
} }
// Enter event loop in another goroutine. // Enter event loop in another goroutine.
go eventLoop(pinger) go eventLoop(pinger, time.NewTicker(*statsInterval))
// Run pinger in main thread. // Run pinger in main thread.
fmt.Println("PING", pinger.Addr()) fmt.Println("PING", pinger.Addr())