// +build linux package load import ( "context" "io/ioutil" "strconv" "strings" "syscall" "github.com/shirou/gopsutil/internal/common" ) func Avg() (*AvgStat, error) { return AvgWithContext(context.Background()) } func AvgWithContext(ctx context.Context) (*AvgStat, error) { stat, err := fileAvgWithContext(ctx) if err != nil { stat, err = sysinfoAvgWithContext(ctx) } return stat, err } func sysinfoAvgWithContext(ctx context.Context) (*AvgStat, error) { var info syscall.Sysinfo_t err := syscall.Sysinfo(&info) if err != nil { return nil, err } const si_load_shift = 16 return &AvgStat{ Load1: float64(info.Loads[0]) / float64(1<