Skip to content

Commit

Permalink
fix: 调整 dmidecode 补充信息的逻辑为按需补充 (#262)
Browse files Browse the repository at this point in the history
1.调整dmidecode补充CPU信息的逻辑。
(部分情况下可能会出现 gopsutil 获取的cpu信息可能不全,使用dmidecode获取的信息也有错误,这个时候使用
dmidecode获取的数据直接对CPU信息进行修改不合适; 变更为以
gopsutil获取的信息为主,然后dmidecode获取的信息按需替换的形式)
  • Loading branch information
Liyu6371 authored Mar 26, 2024
1 parent c9f08fa commit 215ef98
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pkg/bkmonitorbeat/tasks/basereport/collector/cpu_stat_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func queryCpuInfo(r *CpuReport, _ time.Duration, _ time.Duration) (err error) {
useDmidecode := false
if len(r.Cpuinfo) > 0 {
// 取第一个cpu检查,如果发现存在信息为空的情况,则启用dmidecode进行填充
if r.Cpuinfo[0].Mhz == 0 || r.Cpuinfo[0].Model == "" {
if r.Cpuinfo[0].Mhz == 0 || r.Cpuinfo[0].Model == "" || r.Cpuinfo[0].ModelName == "" {
model, mhz = getDMIDecodeCPUInfo()
useDmidecode = true
}
Expand All @@ -142,11 +142,17 @@ func queryCpuInfo(r *CpuReport, _ time.Duration, _ time.Duration) (err error) {
return nil
}

// 用dmidecode信息填充所有核
// 用dmidecode信息填充所有核 (按需补充信息)
for index, info := range r.Cpuinfo {
info.Mhz = mhz
info.Model = model
info.ModelName = model
if info.Mhz == 0 {
info.Mhz = mhz
}
if info.Model == "" {
info.Model = model
}
if info.ModelName == "" {
info.ModelName = model
}
r.Cpuinfo[index] = info
}

Expand Down

0 comments on commit 215ef98

Please sign in to comment.