godash/internal/system/cpu.go

30 lines
442 B
Go
Raw Normal View History

2023-06-14 21:53:27 +02:00
package system
import (
"math"
"runtime"
"strconv"
2023-06-21 16:49:07 +02:00
"github.com/shirou/gopsutil/v3/cpu"
2023-06-14 21:53:27 +02:00
)
func staticCpu() CPU {
var p CPU
p.Threads = strconv.Itoa(runtime.NumCPU()) + " threads"
c, err := cpu.Info()
if err == nil {
p.Name = c[0].ModelName
} else {
p.Name = "none detected"
}
return p
}
func (c *Config) liveCpu() {
p, err := cpu.Percent(0, false)
if err != nil {
return
}
c.System.Live.CPU = math.RoundToEven(p[0])
}