MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / updateCPU

Method updateCPU

internal/nodes/node_status_executor.go:168–206  ·  view source on GitHub ↗

更新CPU

(status *nodeconfigs.NodeStatus)

Source from the content-addressed store, hash-verified

166
167// 更新CPU
168func (this *NodeStatusExecutor) updateCPU(status *nodeconfigs.NodeStatus) {
169 var duration = time.Duration(0)
170 if this.isFirstTime {
171 duration = 100 * time.Millisecond
172 }
173 percents, err := cpu.Percent(duration, false)
174 if err != nil {
175 status.Error = "cpu.Percent(): " + err.Error()
176 return
177 }
178 if len(percents) == 0 {
179 return
180 }
181 status.CPUUsage = percents[0] / 100
182
183 // 记录监控数据
184 monitor.SharedValueQueue.Add(nodeconfigs.NodeValueItemCPU, maps.Map{
185 "usage": status.CPUUsage,
186 "cores": runtime.NumCPU(),
187 })
188
189 if this.cpuLogicalCount == 0 && this.cpuPhysicalCount == 0 {
190 status.CPULogicalCount, err = cpu.Counts(true)
191 if err != nil {
192 status.Error = "cpu.Counts(): " + err.Error()
193 return
194 }
195 status.CPUPhysicalCount, err = cpu.Counts(false)
196 if err != nil {
197 status.Error = "cpu.Counts(): " + err.Error()
198 return
199 }
200 this.cpuLogicalCount = status.CPULogicalCount
201 this.cpuPhysicalCount = status.CPUPhysicalCount
202 } else {
203 status.CPULogicalCount = this.cpuLogicalCount
204 status.CPUPhysicalCount = this.cpuPhysicalCount
205 }
206}
207
208// 更新硬盘
209func (this *NodeStatusExecutor) updateDisk(status *nodeconfigs.NodeStatus) {

Callers 1

updateMethod · 0.95

Calls 2

AddMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected