From 6bd51269b730bdfdda87ada3a971edf582d7d308 Mon Sep 17 00:00:00 2001 From: Tariq Ibrahim Date: Thu, 6 Dec 2018 07:47:20 -0800 Subject: [PATCH] update to host_statistics64 for Darwin meminfo (#1183) Signed-off-by: tariqibrahim --- collector/meminfo_darwin.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/collector/meminfo_darwin.go b/collector/meminfo_darwin.go index fc6b7b33..5ca90049 100644 --- a/collector/meminfo_darwin.go +++ b/collector/meminfo_darwin.go @@ -21,18 +21,18 @@ import "C" import ( "encoding/binary" "fmt" - "syscall" "unsafe" "golang.org/x/sys/unix" ) func (c *meminfoCollector) getMemInfo() (map[string]float64, error) { - infoCount := C.mach_msg_type_number_t(C.HOST_VM_INFO_COUNT) - vmstat := C.vm_statistics_data_t{} - ret := C.host_statistics( - C.host_t(C.mach_host_self()), - C.HOST_VM_INFO, + host := C.mach_host_self() + infoCount := C.mach_msg_type_number_t(C.HOST_VM_INFO64_COUNT) + vmstat := C.vm_statistics64_data_t{} + ret := C.host_statistics64( + C.host_t(host), + C.HOST_VM_INFO64, C.host_info_t(unsafe.Pointer(&vmstat)), &infoCount, ) @@ -46,9 +46,13 @@ func (c *meminfoCollector) getMemInfo() (map[string]float64, error) { // Syscall removes terminating NUL which we need to cast to uint64 total := binary.LittleEndian.Uint64([]byte(totalb + "\x00")) - ps := float64(C.natural_t(syscall.Getpagesize())) + var pageSize C.vm_size_t + C.host_page_size(C.host_t(host), &pageSize) + + ps := float64(pageSize) return map[string]float64{ "active_bytes": ps * float64(vmstat.active_count), + "compressed_bytes": ps * float64(vmstat.compressor_page_count), "inactive_bytes": ps * float64(vmstat.inactive_count), "wired_bytes": ps * float64(vmstat.wire_count), "free_bytes": ps * float64(vmstat.free_count),