mirror of
https://github.com/nadoo/glider.git
synced 2026-11-19 07:09:42 +08:00
check: added new config checklatencysamples to support average latency calculating (#282)
This commit is contained in:
1 parent
cb698713ee
commit
fa97a44e8d
4 files changed
+29
-16
No files matched your search
+12
-10
@@ -24,16 +24,17 @@ type Config struct {
|
||||
|
||||
// Strategy configurations.
|
||||
type Strategy struct {
|
||||
Strategy string
|
||||
Check string
|
||||
CheckInterval int
|
||||
CheckTimeout int
|
||||
CheckTolerance int
|
||||
CheckDisabledOnly bool
|
||||
MaxFailures int
|
||||
DialTimeout int
|
||||
RelayTimeout int
|
||||
IntFace string
|
||||
Strategy string
|
||||
Check string
|
||||
CheckInterval int
|
||||
CheckTimeout int
|
||||
CheckTolerance int
|
||||
CheckLatencySamples int
|
||||
CheckDisabledOnly bool
|
||||
MaxFailures int
|
||||
DialTimeout int
|
||||
RelayTimeout int
|
||||
IntFace string
|
||||
}
|
||||
|
||||
// NewConfFromFile returns a new config from file.
|
||||
@@ -46,6 +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.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")
|
||||
|
||||
+13
-3
@@ -266,13 +266,23 @@ func (p *FwdrGroup) check(fwdr *Forwarder, checker Checker) {
|
||||
}
|
||||
|
||||
wait = 1
|
||||
fwdr.SetLatency(int64(elapsed))
|
||||
log.F("[check] %s: %s(%d), SUCCESS. elapsed: %s",
|
||||
p.name, fwdr.Addr(), fwdr.Priority(), elapsed)
|
||||
p.setLatency(fwdr, elapsed)
|
||||
log.F("[check] %s: %s(%d), SUCCESS. elapsed: %s, Latency: %s",
|
||||
p.name, fwdr.Addr(), fwdr.Priority(), elapsed, time.Duration(fwdr.Latency()))
|
||||
fwdr.Enable()
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
fwdr.SetLatency(newLatency)
|
||||
}
|
||||
|
||||
// Round Robin.
|
||||
func (p *FwdrGroup) scheduleRR(dstAddr string) *Forwarder {
|
||||
return p.avail[atomic.AddUint32(&p.index, 1)%uint32(len(p.avail))]
|
||||
|
||||
Reference in new issue
Block a user