MCPcopy Index your code
hub / github.com/inbug-team/InScan / GetCpuPercent

Function GetCpuPercent

host_info/host_info.go:104–119  ·  view source on GitHub ↗

4.CPU使用率

()

Source from the content-addressed store, hash-verified

102
103// 4.CPU使用率
104func GetCpuPercent() (result CpuInfo, err error) {
105 infos, err := cpu.Percent(1*time.Second, true)
106 if err != nil {
107 return result, err
108 }
109 var total float64 = 0
110 for index, value := range infos {
111 result.CpuAll = append(result.CpuAll, CpuSingle{
112 Num: fmt.Sprintf("#%d", index+1),
113 Percent: int(value),
114 })
115 total += value
116 }
117 result.CpuAvg = decimal(fmt.Sprintf("%.1f", total/float64(len(infos))))
118 return result, err
119}
120
121// 5.内存信息
122func GetMemInfo() (float64, []map[string]interface{}) {

Callers

nothing calls this directly

Calls 1

decimalFunction · 0.85

Tested by

no test coverage detected