prometheus-community / pro-bing

A library for creating continuous probers
MIT License
309 stars 52 forks source link

add timeout handler #48

Closed zey1996 closed 1 year ago

zey1996 commented 1 year ago

I believe that developers should have a way to know when a data packet is lost or does not return within a specified time.

you can set MaxRtt and OnTimeout func

Ontime func while be call when a request was not answered within a specified time

you only need add:

  pinger.MaxRtt = time.Second * 3

  pinger.OnTimeOut = func(packet *probing.Packet) {
    fmt.Println("timeout", packet.Addr, packet.Rtt, packet.TTL)
  }

It has good compatibility, as if MaxRtt is not set, it will have the same behavior as before.

However, there are still some issues remaining.

But I believe that this is acceptable.

SuperQ commented 1 year ago

This needs a DCO sign-off. You can use git commit -s --amend to add it.

zey1996 commented 1 year ago

please see also: https://github.com/prometheus-community/pro-bing/pull/49