fix health check

This commit is contained in:
jebbs 2022-10-17 17:10:23 +08:00
parent 8d2f261105
commit ebe1b0f381
2 changed files with 9 additions and 0 deletions

View File

@ -109,6 +109,7 @@ func (h *HealthCheck) Check() {
nodes := h.refreshNodes() nodes := h.refreshNodes()
h.mutex.Unlock() h.mutex.Unlock()
for _, n := range nodes { for _, n := range nodes {
n := n
go h.checkNode(n) go h.checkNode(n)
} }
} }
@ -124,6 +125,7 @@ func (h *HealthCheck) CheckNodes() {
nodes := h.refreshNodes() nodes := h.refreshNodes()
h.mutex.Unlock() h.mutex.Unlock()
for _, n := range nodes { for _, n := range nodes {
n := n
delay := time.Duration(rand.Intn(int(h.options.Interval))) delay := time.Duration(rand.Intn(int(h.options.Interval)))
time.AfterFunc(delay, func() { time.AfterFunc(delay, func() {
h.checkNode(n) h.checkNode(n)

View File

@ -59,6 +59,12 @@ func (h *HealthCheck) Nodes(network string) *Nodes {
default: default:
nodes.Qualified = append(nodes.Qualified, n) nodes.Qualified = append(nodes.Qualified, n)
} }
h.logger.Trace(
"[", n.Tag, "]",
" STD=", n.Deviation,
" AVG=", n.Average,
" Fail=", n.Fail, "/", n.All,
)
} }
return nodes return nodes
} }
@ -83,6 +89,7 @@ func (h *HealthCheck) refreshNodes() []adapter.Outbound {
nodes := CoveredOutbounds(h.router, h.tags) nodes := CoveredOutbounds(h.router, h.tags)
tags := make(map[string]struct{}) tags := make(map[string]struct{})
for _, n := range nodes { for _, n := range nodes {
n := n
tag := n.Tag() tag := n.Tag()
tags[tag] = struct{}{} tags[tag] = struct{}{}
// make it known to the health check results // make it known to the health check results