Skip to content

Commit

Permalink
improve: sort sensor names & add an ignore list for sensors (#71)
Browse files Browse the repository at this point in the history
* improve: sort sensor names

* add an ignore list for sensors
  • Loading branch information
uubulb authored Oct 1, 2024
1 parent 62a5c78 commit b3211b9
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions pkg/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os/exec"
"runtime"
"sort"
"strconv"
"strings"
"sync/atomic"
Expand Down Expand Up @@ -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
)

Expand Down Expand Up @@ -62,7 +67,7 @@ var statDataFetchAttempts = map[string]int{
}

var (
updateTempStatus int32
updateTempStatus = new(atomic.Int32)
)

func InitConfig(cfg *model.AgentConfig) {
Expand Down Expand Up @@ -237,7 +242,7 @@ func TrackNetworkSpeed() {
continue
}
} else {
if isListContainsStr(excludeNetInterfaces, v.Name) {
if util.ContainsStr(excludeNetInterfaces, v.Name) {
continue
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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()
Expand All @@ -376,26 +381,21 @@ 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,
})
}
}

temperatureStat = tempStat
}
}
}
sort.Slice(tempStat, func(i, j int) bool {
return tempStat[i].Name < tempStat[j].Name
})

func isListContainsStr(list []string, str string) bool {
for i := 0; i < len(list); i++ {
if strings.Contains(str, list[i]) {
return true
temperatureStat = tempStat
}
}
return false
}

func printf(format string, v ...interface{}) {
Expand Down

0 comments on commit b3211b9

Please sign in to comment.