mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-07 02:20:25 +08:00
在初始化时即获取CPU数量
This commit is contained in:
@@ -108,7 +108,7 @@ func (this *NodeStatusExecutor) updateCPU(status *nodeconfigs.NodeStatus) {
|
|||||||
}
|
}
|
||||||
status.CPUUsage = percents[0] / 100
|
status.CPUUsage = percents[0] / 100
|
||||||
|
|
||||||
if time.Since(this.cpuUpdatedTime) > 300*time.Second { // 每隔5分钟才会更新一次
|
if this.cpuLogicalCount == 0 && this.cpuPhysicalCount == 0 {
|
||||||
this.cpuUpdatedTime = time.Now()
|
this.cpuUpdatedTime = time.Now()
|
||||||
|
|
||||||
status.CPULogicalCount, err = cpu.Counts(true)
|
status.CPULogicalCount, err = cpu.Counts(true)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ func TestNodeStatusExecutor_CPU(t *testing.T) {
|
|||||||
}
|
}
|
||||||
t.Log("physical count:", countPhysicalCPU)
|
t.Log("physical count:", countPhysicalCPU)
|
||||||
|
|
||||||
percents, err := cpu.Percent(100 * time.Millisecond, false)
|
percents, err := cpu.Percent(100*time.Millisecond, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user