A status-right line for tmux
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

33 lines
599 B

//+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
}