node_exporter/collector/loadavg_freebsd.go
Dominik Honnef 54c74923ee Implement loadavg on FreeBSD without cgo
The code may also work for other BSDs, but I don't have access to those
for testing.
2016-12-26 23:06:05 +01:00

28 lines
463 B
Go

// +build !noloadavg
package collector
import (
"unsafe"
"golang.org/x/sys/unix"
)
func getLoad() ([]float64, error) {
type loadavg struct {
load [3]uint32
scale int
}
b, err := unix.SysctlRaw("vm.loadavg")
if err != nil {
return nil, err
}
load := *(*loadavg)(unsafe.Pointer((&b[0])))
scale := float64(load.scale)
return []float64{
float64(load.load[0]) / scale,
float64(load.load[1]) / scale,
float64(load.load[2]) / scale,
}, nil
}