~/Projects/clash-pro
git clone https://code.lsong.org/clash-pro
Commit
- Commit
- a7aa5fd5231d2059a2980b0b094155ea4a7ce8a3
- Author
- wwqgtxx <[email protected]>
- Date
- 2022-10-31 16:04:50 +0800 +0800
- Diffstat
adapter/provider/healthcheck.go | 14 +++++++++++++-
adjust: add some log for healthcheck debug
diff --git a/adapter/provider/healthcheck.go b/adapter/provider/healthcheck.go index bf8bcc6a9ebca65891698e3816188158d48809de..16b9ad611499318991314cd51f1b4a9150da68e9 100644 --- a/adapter/provider/healthcheck.go +++ b/adapter/provider/healthcheck.go @@ -2,12 +2,15 @@ package provider import ( "context" - "github.com/Dreamacro/clash/common/singledo" "time" "github.com/Dreamacro/clash/common/batch" + "github.com/Dreamacro/clash/common/singledo" + C "github.com/Dreamacro/clash/constant" + "github.com/Dreamacro/clash/common/batch" C "github.com/Dreamacro/clash/constant" + "github.com/gofrs/uuid" "go.uber.org/atomic" ) @@ -55,6 +58,7 @@ if !hc.lazy || now-hc.lastTouch.Load() < int64(hc.interval) { hc.check() return true } else { + log.Debugln("Skip once health check because we are lazy") return false } } @@ -73,18 +77,26 @@ } func (hc *HealthCheck) check() { _, _, _ = hc.singleDo.Do(func() (struct{}, error) { + id := "" + if uid, err := uuid.NewV4(); err == nil { + id = uid.String() + } + log.Debugln("Start New Health Checking {%s}", id) b, _ := batch.New[bool](context.Background(), batch.WithConcurrencyNum[bool](10)) for _, proxy := range hc.proxies { p := proxy b.Go(p.Name(), func() (bool, error) { ctx, cancel := context.WithTimeout(context.Background(), defaultURLTestTimeout) defer cancel() + log.Debugln("Health Checking %s {%s}", p.Name(), id) _, _ = p.URLTest(ctx, hc.url) + log.Debugln("Health Checked %s : %t %d ms {%s}", p.Name(), p.Alive(), p.LastDelay(), id) return false, nil }) } b.Wait() + log.Debugln("Finish A Health Checking {%s}", id) return struct{}{}, nil }) }