VictoriaMetrics/lib/memory/sysctl.go

23 lines
446 B
Go
Raw Permalink Normal View History

//go:build darwin || freebsd || openbsd || dragonfly || netbsd
2019-08-27 22:04:44 +00:00
package memory
import (
"syscall"
"unsafe"
)
// This has been adapted from github.com/pbnjay/memory.
func sysctlUint64(name string) (uint64, error) {
s, err := syscall.Sysctl(name)
if err != nil {
return 0, err
}
// hack because the string conversion above drops a \0
b := []byte(s)
if len(b) < 8 {
b = append(b, 0)
}
return *(*uint64)(unsafe.Pointer(&b[0])), nil
}