实现缓存策略部分管理功能

This commit is contained in:
GoEdgeLab
2020-10-02 17:22:38 +08:00
parent 1da53beee4
commit 1bea7d00be
4 changed files with 33 additions and 4 deletions

View File

@@ -87,7 +87,7 @@ func (this *NodeStatusExecutor) updateCPU(status *NodeStatus) {
}
percents, err := cpu.Percent(duration, false)
if err != nil {
status.Error = err.Error()
status.Error = "cpu.Percent(): " + err.Error()
return
}
if len(percents) == 0 {
@@ -100,12 +100,12 @@ func (this *NodeStatusExecutor) updateCPU(status *NodeStatus) {
status.CPULogicalCount, err = cpu.Counts(true)
if err != nil {
status.Error = err.Error()
status.Error = "cpu.Counts(): " + err.Error()
return
}
status.CPUPhysicalCount, err = cpu.Counts(false)
if err != nil {
status.Error = err.Error()
status.Error = "cpu.Counts(): " + err.Error()
return
}
this.cpuLogicalCount = status.CPULogicalCount

View File

@@ -0,0 +1,27 @@
package nodes
import (
"github.com/shirou/gopsutil/cpu"
"testing"
"time"
)
func TestNodeStatusExecutor_CPU(t *testing.T) {
countLogicCPU, err := cpu.Counts(true)
if err != nil {
t.Fatal(err)
}
t.Log("logic count:", countLogicCPU)
countPhysicalCPU, err := cpu.Counts(false)
if err != nil {
t.Fatal(err)
}
t.Log("physical count:", countPhysicalCPU)
percents, err := cpu.Percent(100 * time.Millisecond, false)
if err != nil {
t.Fatal(err)
}
t.Log(percents)
}