33 lines
599 B
Go
33 lines
599 B
Go
//+build !windows
|
|
|
|
package cpu
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
|
|
cpuUtil "github.com/shirou/gopsutil/v3/cpu"
|
|
"github.com/shirou/gopsutil/v3/load"
|
|
|
|
"go.fanir.de/statusline/config"
|
|
)
|
|
|
|
func Load(format config.Format, precision int) (string, error) {
|
|
l, err := load.Avg()
|
|
if err != nil {
|
|
return "", err // FIXME
|
|
}
|
|
|
|
cpus, err := cpuUtil.Counts(true)
|
|
if err != nil {
|
|
// TODO: log error
|
|
cpus = runtime.NumCPU()
|
|
}
|
|
|
|
if l.Load1 > float64(cpus) {
|
|
return fmt.Sprintf(format.Warning), nil
|
|
}
|
|
|
|
return fmt.Sprintf("[%.[1]*[2]f %.[1]*[3]f %.[1]*[4]f]",
|
|
precision, l.Load1, l.Load5, l.Load15), nil
|
|
}
|