statusline/load.go

28 lines
465 B
Go
Raw Normal View History

//+build !windows
package main
import (
"fmt"
"github.com/shirou/gopsutil/v3/load"
"runtime"
)
func printLoad(format Format, precision int) {
l, err := load.Avg()
if err != nil {
panic(err) // fixme
}
cpus, err := cpu.Counts(true)
if err != nil {
// todo: log error
cpus = runtime.NumCPU()
}
if l.Load1 > float64(cpus) {
fmt.Print(format.Warning)
}
fmt.Printf("[%.[1]*[2]f %.[1]*[3]f %.[1]*[4]f]",
precision, l.Load1, l.Load5, l.Load15)
}