mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-01 14:47:38 +00:00
31 lines
610 B
Go
31 lines
610 B
Go
|
package memory
|
||
|
|
||
|
import (
|
||
|
"syscall"
|
||
|
"unsafe"
|
||
|
|
||
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
||
|
)
|
||
|
|
||
|
// This has been adapted from github.com/pbnjay/memory.
|
||
|
func sysTotalMemory() int {
|
||
|
s, err := sysctlUint64("hw.memsize")
|
||
|
if err != nil {
|
||
|
logger.Panicf("FATAL: cannot determine system memory: %s", err)
|
||
|
}
|
||
|
return int(s)
|
||
|
}
|
||
|
|
||
|
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
|
||
|
}
|