check: set checklatencysamples default to 10 (#282)

This commit is contained in:
nadoo committed 2022-02-20 21:37:36 +08:00
1 parent fa97a44e8d
commit f96ad73c7d
5 files changed
+16 -11

No files matched your search

+1 -1
View File
@@ -47,7 +47,7 @@ func NewConfFromFile(ruleFile string) (*Config, error) {
f.StringVar(&p.Strategy.Check, "check", "http://www.msftconnecttest.com/connecttest.txt#expect=200", "check=tcp[://HOST:PORT]: tcp port connect check\ncheck=http://HOST[:PORT][/URI][#expect=STRING_IN_RESP_LINE]\ncheck=file://SCRIPT_PATH: run a check script, healthy when exitcode=0, environment variables: FORWARDER_ADDR\ncheck=disable: disable health check")
f.IntVar(&p.Strategy.CheckInterval, "checkinterval", 30, "fowarder check interval(seconds)")
f.IntVar(&p.Strategy.CheckTimeout, "checktimeout", 10, "fowarder check timeout(seconds)")
f.IntVar(&p.Strategy.CheckLatencySamples, "checklatencysamples", 1, "use the average latency of the latest N checks")
f.IntVar(&p.Strategy.CheckLatencySamples, "checklatencysamples", 10, "use the average latency of the latest N checks")
f.IntVar(&p.Strategy.CheckTolerance, "checktolerance", 0, "fowarder check tolerance(ms), switch only when new_latency < old_latency - tolerance, only used in lha mode")
f.BoolVar(&p.Strategy.CheckDisabledOnly, "checkdisabledonly", false, "check disabled fowarders only")
f.IntVar(&p.Strategy.MaxFailures, "maxfailures", 3, "max failures to change forwarder status to disabled")
+2 -2
View File
@@ -276,8 +276,8 @@ func (p *FwdrGroup) check(fwdr *Forwarder, checker Checker) {
func (p *FwdrGroup) setLatency(fwdr *Forwarder, elapsed time.Duration) {
newLatency := int64(elapsed)
if cnt := p.config.CheckLatencySamples; cnt > 1 {
if lastLagency := fwdr.Latency(); lastLagency > 0 {
newLatency = (lastLagency*(int64(cnt)-1) + int64(elapsed)) / int64(cnt)
if lastLatency := fwdr.Latency(); lastLatency > 0 {
newLatency = (lastLatency*(int64(cnt)-1) + int64(elapsed)) / int64(cnt)
}
}
fwdr.SetLatency(newLatency)