1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-05-02 22:17:08 +08:00
shirou_gopsutil/load/load_linux.go
Jonathan Chauncey 0461c50666 chore(*): Fixes #94
Added the ability to fetch an alternative location for /proc via an
environment variable. If the env var is not set it will return /proc as
the default value.
2015-10-17 11:34:41 -06:00

43 lines
704 B
Go

// +build linux
package load
import (
"io/ioutil"
"strconv"
"strings"
common "github.com/shirou/gopsutil/common"
)
func LoadAvg() (*LoadAvgStat, error) {
filename := common.GetEnv("HOST_PROC", "/proc") + "/loadavg"
line, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
values := strings.Fields(string(line))
load1, err := strconv.ParseFloat(values[0], 64)
if err != nil {
return nil, err
}
load5, err := strconv.ParseFloat(values[1], 64)
if err != nil {
return nil, err
}
load15, err := strconv.ParseFloat(values[2], 64)
if err != nil {
return nil, err
}
ret := &LoadAvgStat{
Load1: load1,
Load5: load5,
Load15: load15,
}
return ret, nil
}