优化代码/CPU监控信息增加CPU逻辑核数

This commit is contained in:
GoEdgeLab
2022-04-07 09:45:55 +08:00
parent 60cedd498b
commit 4d48100cfb
2 changed files with 12 additions and 10 deletions

View File

@@ -20,20 +20,21 @@ func init() {
goman.New(func() { goman.New(func() {
for range ticker.C { for range ticker.C {
// 加入到数据队列中 // 加入到数据队列中
if teaconst.InTrafficBytes > 0 { var inBytes = atomic.LoadUint64(&teaconst.InTrafficBytes)
atomic.StoreUint64(&teaconst.InTrafficBytes, 0) // 重置数据
if inBytes > 0 {
monitor.SharedValueQueue.Add(nodeconfigs.NodeValueItemTrafficIn, maps.Map{ monitor.SharedValueQueue.Add(nodeconfigs.NodeValueItemTrafficIn, maps.Map{
"total": teaconst.InTrafficBytes, "total": inBytes,
})
}
if teaconst.OutTrafficBytes > 0 {
monitor.SharedValueQueue.Add(nodeconfigs.NodeValueItemTrafficOut, maps.Map{
"total": teaconst.OutTrafficBytes,
}) })
} }
// 重置数据 var outBytes = atomic.LoadUint64(&teaconst.OutTrafficBytes)
atomic.StoreUint64(&teaconst.InTrafficBytes, 0) atomic.StoreUint64(&teaconst.OutTrafficBytes, 0) // 重置数据
atomic.StoreUint64(&teaconst.OutTrafficBytes, 0) if outBytes > 0 {
monitor.SharedValueQueue.Add(nodeconfigs.NodeValueItemTrafficOut, maps.Map{
"total": outBytes,
})
}
} }
}) })
}) })

View File

@@ -148,6 +148,7 @@ func (this *NodeStatusExecutor) updateCPU(status *nodeconfigs.NodeStatus) {
// 记录监控数据 // 记录监控数据
monitor.SharedValueQueue.Add(nodeconfigs.NodeValueItemCPU, maps.Map{ monitor.SharedValueQueue.Add(nodeconfigs.NodeValueItemCPU, maps.Map{
"usage": status.CPUUsage, "usage": status.CPUUsage,
"cores": runtime.NumCPU(),
}) })
if this.cpuLogicalCount == 0 && this.cpuPhysicalCount == 0 { if this.cpuLogicalCount == 0 && this.cpuPhysicalCount == 0 {