fix: wrong IP value in some situations (#32)
This commit is contained in:
parent
81b774a7f0
commit
fb86c89de7
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user