fix: wrong IP value in some situations (#32)

This commit is contained in:
UUBulb 2024-06-25 22:08:28 +08:00 committed by GitHub
parent 81b774a7f0
commit fb86c89de7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 6 deletions

View File

@ -4,11 +4,12 @@ package stat
// Original License: MIT
import (
"encoding/json"
"errors"
"os"
"os/exec"
"strconv"
"github.com/nezhahq/agent/pkg/util"
)
type ROCmSMI struct {
@ -48,7 +49,7 @@ func gatherROCmSMI(ret []byte) ([]float64, error) {
var gpus map[string]GPU
var percentage []float64
err := json.Unmarshal(ret, &gpus)
err := util.Json.Unmarshal(ret, &gpus)
if err != nil {
return nil, err
}

View File

@ -100,21 +100,23 @@ func fetchGeoIP(servers []string, isV6 bool) geoIP {
continue
}
resp.Body.Close()
if err := ip.Unmarshal(body); err != nil {
newIP := geoIP{}
if err := newIP.Unmarshal(body); err != nil {
continue
}
// 没取到 v6 IP
if isV6 && !strings.Contains(ip.IP, ":") {
if isV6 && !strings.Contains(newIP.IP, ":") {
continue
}
// 没取到 v4 IP
if !isV6 && !strings.Contains(ip.IP, ".") {
if !isV6 && !strings.Contains(newIP.IP, ".") {
continue
}
// 未获取到国家码
if ip.CountryCode == "" {
if newIP.CountryCode == "" {
continue
}
ip = newIP
return ip
}
}