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"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@ -35,6 +36,10 @@ var (
|
|||||||
excludeNetInterfaces = []string{
|
excludeNetInterfaces = []string{
|
||||||
"lo", "tun", "docker", "veth", "br-", "vmbr", "vnet", "kube",
|
"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
|
agentConfig *model.AgentConfig
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -62,7 +67,7 @@ var statDataFetchAttempts = map[string]int{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
updateTempStatus int32
|
updateTempStatus = new(atomic.Int32)
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitConfig(cfg *model.AgentConfig) {
|
func InitConfig(cfg *model.AgentConfig) {
|
||||||
@ -237,7 +242,7 @@ func TrackNetworkSpeed() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if isListContainsStr(excludeNetInterfaces, v.Name) {
|
if util.ContainsStr(excludeNetInterfaces, v.Name) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -270,7 +275,7 @@ func getDiskTotalAndUsed() (total uint64, used uint64) {
|
|||||||
for _, d := range diskList {
|
for _, d := range diskList {
|
||||||
fsType := strings.ToLower(d.Fstype)
|
fsType := strings.ToLower(d.Fstype)
|
||||||
// 不统计 K8s 的虚拟挂载点:https://github.com/shirou/gopsutil/issues/1007
|
// 不统计 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
|
devices[d.Device] = d.Mountpoint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -362,10 +367,10 @@ func updateGPUStat() float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func updateTemperatureStat() {
|
func updateTemperatureStat() {
|
||||||
if !atomic.CompareAndSwapInt32(&updateTempStatus, 0, 1) {
|
if !updateTempStatus.CompareAndSwap(0, 1) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer atomic.StoreInt32(&updateTempStatus, 0)
|
defer updateTempStatus.Store(0)
|
||||||
|
|
||||||
if statDataFetchAttempts["Temperatures"] < maxDeviceDataFetchAttempts {
|
if statDataFetchAttempts["Temperatures"] < maxDeviceDataFetchAttempts {
|
||||||
temperatures, err := sensors.SensorsTemperatures()
|
temperatures, err := sensors.SensorsTemperatures()
|
||||||
@ -376,7 +381,7 @@ func updateTemperatureStat() {
|
|||||||
statDataFetchAttempts["Temperatures"] = 0
|
statDataFetchAttempts["Temperatures"] = 0
|
||||||
tempStat := []model.SensorTemperature{}
|
tempStat := []model.SensorTemperature{}
|
||||||
for _, t := range temperatures {
|
for _, t := range temperatures {
|
||||||
if t.Temperature > 0 {
|
if t.Temperature > 0 && !util.ContainsStr(sensorIgnoreList, t.SensorKey) {
|
||||||
tempStat = append(tempStat, model.SensorTemperature{
|
tempStat = append(tempStat, model.SensorTemperature{
|
||||||
Name: t.SensorKey,
|
Name: t.SensorKey,
|
||||||
Temperature: t.Temperature,
|
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
|
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{}) {
|
func printf(format string, v ...interface{}) {
|
||||||
util.Printf(agentConfig.Debug, format, v...)
|
util.Printf(agentConfig.Debug, format, v...)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user