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
|
// Original License: MIT
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/nezhahq/agent/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ROCmSMI struct {
|
type ROCmSMI struct {
|
||||||
@ -48,7 +49,7 @@ func gatherROCmSMI(ret []byte) ([]float64, error) {
|
|||||||
var gpus map[string]GPU
|
var gpus map[string]GPU
|
||||||
var percentage []float64
|
var percentage []float64
|
||||||
|
|
||||||
err := json.Unmarshal(ret, &gpus)
|
err := util.Json.Unmarshal(ret, &gpus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -100,21 +100,23 @@ func fetchGeoIP(servers []string, isV6 bool) geoIP {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
if err := ip.Unmarshal(body); err != nil {
|
newIP := geoIP{}
|
||||||
|
if err := newIP.Unmarshal(body); err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// 没取到 v6 IP
|
// 没取到 v6 IP
|
||||||
if isV6 && !strings.Contains(ip.IP, ":") {
|
if isV6 && !strings.Contains(newIP.IP, ":") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// 没取到 v4 IP
|
// 没取到 v4 IP
|
||||||
if !isV6 && !strings.Contains(ip.IP, ".") {
|
if !isV6 && !strings.Contains(newIP.IP, ".") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// 未获取到国家码
|
// 未获取到国家码
|
||||||
if ip.CountryCode == "" {
|
if newIP.CountryCode == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
ip = newIP
|
||||||
return ip
|
return ip
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user