cpu: implement Mhz and Cores

Adapted from the FreeBSD code.
Successfully tested with Nomad.
This commit is contained in:
Antoine Jacoutot 2019-01-02 17:06:46 +01:00
parent db425313bf
commit 7276e963eb
1 changed files with 13 additions and 3 deletions

View File

@ -124,14 +124,24 @@ func Info() ([]InfoStat, error) {
func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
var ret []InfoStat
var err error
c := InfoStat{}
v, err := unix.Sysctl("hw.model")
if err != nil {
var u32 uint32
if u32, err = unix.SysctlUint32("hw.cpuspeed"); err != nil {
return nil, err
}
c.Mhz = float64(u32)
if u32, err = unix.SysctlUint32("hw.ncpu"); err != nil {
return nil, err
}
c.Cores = int32(u32)
if c.ModelName, err = unix.Sysctl("hw.model"); err != nil {
return nil, err
}
c.ModelName = v
return append(ret, c), nil
}