You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
427 B
Go
29 lines
427 B
Go
package nmon
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/shirou/gopsutil/v4/cpu"
|
|
"time"
|
|
)
|
|
|
|
func Cpu() {
|
|
go func() {
|
|
flat, err := cpu.Percent(time.Second, false)
|
|
if err != nil {
|
|
return
|
|
}
|
|
fmt.Println(flat)
|
|
}()
|
|
flat, err := cpu.Percent(time.Second, true)
|
|
if err != nil {
|
|
return
|
|
}
|
|
c := 0.0000
|
|
for _, v := range flat {
|
|
c += v
|
|
}
|
|
fmt.Println(flat)
|
|
fmt.Println(c / float64(len(flat)))
|
|
time.Sleep(time.Millisecond * 200)
|
|
}
|