fix: 避免 agent 与 dashboard 更新不同步情况

This commit is contained in:
naiba 2024-07-28 15:44:06 +08:00
parent 80ef923a38
commit c50a21c5b1
2 changed files with 3 additions and 8 deletions

View File

@ -427,10 +427,9 @@ func reportState() {
if lastReportHostInfo.Before(time.Now().Add(-10 * time.Minute)) { if lastReportHostInfo.Before(time.Now().Add(-10 * time.Minute)) {
lastReportHostInfo = time.Now() lastReportHostInfo = time.Now()
client.ReportSystemInfo(context.Background(), monitor.GetHost().PB()) client.ReportSystemInfo(context.Background(), monitor.GetHost().PB())
if monitor.GeoQueryIPChanged { if monitor.GeoQueryIP != "" {
geoip, err := client.LookupGeoIP(context.Background(), &pb.GeoIP{Ip: monitor.GeoQueryIP}) geoip, err := client.LookupGeoIP(context.Background(), &pb.GeoIP{Ip: monitor.GeoQueryIP})
if err == nil { if err == nil {
monitor.GeoQueryIPChanged = false
monitor.CachedCountryCode = geoip.GetCountryCode() monitor.CachedCountryCode = geoip.GetCountryCode()
} }
} }

View File

@ -19,7 +19,6 @@ var (
"https://cf-ns.com/cdn-cgi/trace", // 有国内节点 "https://cf-ns.com/cdn-cgi/trace", // 有国内节点
} }
CachedIP, GeoQueryIP, CachedCountryCode string CachedIP, GeoQueryIP, CachedCountryCode string
GeoQueryIPChanged bool
httpClientV4 = util.NewSingleStackHTTPClient(time.Second*20, time.Second*5, time.Second*10, false) httpClientV4 = util.NewSingleStackHTTPClient(time.Second*20, time.Second*5, time.Second*10, false)
httpClientV6 = util.NewSingleStackHTTPClient(time.Second*20, time.Second*5, time.Second*10, true) httpClientV6 = util.NewSingleStackHTTPClient(time.Second*20, time.Second*5, time.Second*10, true)
) )
@ -45,14 +44,11 @@ func UpdateIP(useIPv6CountryCode bool, period uint32) {
CachedIP = fmt.Sprintf("%s/%s", ipv4, ipv6) CachedIP = fmt.Sprintf("%s/%s", ipv4, ipv6)
} }
var newIP string
if !useIPv6CountryCode { if !useIPv6CountryCode {
newIP = ipv4 GeoQueryIP = ipv4
} else { } else {
newIP = ipv6 GeoQueryIP = ipv6
} }
GeoQueryIPChanged = newIP != GeoQueryIP
GeoQueryIP = newIP
time.Sleep(time.Second * time.Duration(period)) time.Sleep(time.Second * time.Duration(period))
} }