improve: sort sensor names & add an ignore list for sensors (#71)
* improve: sort sensor names * add an ignore list for sensors
This commit is contained in:
parent
62a5c7869d
commit
b3211b9c40
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
@ -35,6 +36,10 @@ var (
|
||||
excludeNetInterfaces = []string{
|
||||
"lo", "tun", "docker", "veth", "br-", "vmbr", "vnet", "kube",
|
||||
}
|
||||
sensorIgnoreList = []string{
|
||||
"PMU tcal", // the calibration sensor on arm macs, value is fixed
|
||||
"noname",
|
||||
}
|
||||
agentConfig *model.AgentConfig
|
||||
)
|
||||
|
||||
@ -62,7 +67,7 @@ var statDataFetchAttempts = map[string]int{
|
||||
}
|
||||
|
||||
var (
|
||||
updateTempStatus int32
|
||||
updateTempStatus = new(atomic.Int32)
|
||||
)
|
||||
|
||||
func InitConfig(cfg *model.AgentConfig) {
|
||||
@ -237,7 +242,7 @@ func TrackNetworkSpeed() {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
if isListContainsStr(excludeNetInterfaces, v.Name) {
|
||||
if util.ContainsStr(excludeNetInterfaces, v.Name) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
@ -270,7 +275,7 @@ func getDiskTotalAndUsed() (total uint64, used uint64) {
|
||||
for _, d := range diskList {
|
||||
fsType := strings.ToLower(d.Fstype)
|
||||
// 不统计 K8s 的虚拟挂载点:https://github.com/shirou/gopsutil/issues/1007
|
||||
if devices[d.Device] == "" && isListContainsStr(expectDiskFsTypes, fsType) && !strings.Contains(d.Mountpoint, "/var/lib/kubelet") {
|
||||
if devices[d.Device] == "" && util.ContainsStr(expectDiskFsTypes, fsType) && !strings.Contains(d.Mountpoint, "/var/lib/kubelet") {
|
||||
devices[d.Device] = d.Mountpoint
|
||||
}
|
||||
}
|
||||
@ -362,10 +367,10 @@ func updateGPUStat() float64 {
|
||||
}
|
||||
|
||||
func updateTemperatureStat() {
|
||||
if !atomic.CompareAndSwapInt32(&updateTempStatus, 0, 1) {
|
||||
if !updateTempStatus.CompareAndSwap(0, 1) {
|
||||
return
|
||||
}
|
||||
defer atomic.StoreInt32(&updateTempStatus, 0)
|
||||
defer updateTempStatus.Store(0)
|
||||
|
||||
if statDataFetchAttempts["Temperatures"] < maxDeviceDataFetchAttempts {
|
||||
temperatures, err := sensors.SensorsTemperatures()
|
||||
@ -376,7 +381,7 @@ func updateTemperatureStat() {
|
||||
statDataFetchAttempts["Temperatures"] = 0
|
||||
tempStat := []model.SensorTemperature{}
|
||||
for _, t := range temperatures {
|
||||
if t.Temperature > 0 {
|
||||
if t.Temperature > 0 && !util.ContainsStr(sensorIgnoreList, t.SensorKey) {
|
||||
tempStat = append(tempStat, model.SensorTemperature{
|
||||
Name: t.SensorKey,
|
||||
Temperature: t.Temperature,
|
||||
@ -384,20 +389,15 @@ func updateTemperatureStat() {
|
||||
}
|
||||
}
|
||||
|
||||
sort.Slice(tempStat, func(i, j int) bool {
|
||||
return tempStat[i].Name < tempStat[j].Name
|
||||
})
|
||||
|
||||
temperatureStat = tempStat
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func isListContainsStr(list []string, str string) bool {
|
||||
for i := 0; i < len(list); i++ {
|
||||
if strings.Contains(str, list[i]) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func printf(format string, v ...interface{}) {
|
||||
util.Printf(agentConfig.Debug, format, v...)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user