|
|
|
|
@ -16,6 +16,8 @@ |
|
|
|
|
package collector |
|
|
|
|
|
|
|
|
|
// #include <mach/mach_host.h>
|
|
|
|
|
// #include <sys/sysctl.h>
|
|
|
|
|
// typedef struct xsw_usage xsw_usage_t;
|
|
|
|
|
import "C" |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
@ -43,6 +45,13 @@ func (c *meminfoCollector) getMemInfo() (map[string]float64, error) { |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
swapraw, err := unix.SysctlRaw("vm.swapusage") |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
swap := (*C.xsw_usage_t)(unsafe.Pointer(&swapraw[0])) |
|
|
|
|
|
|
|
|
|
// Syscall removes terminating NUL which we need to cast to uint64
|
|
|
|
|
total := binary.LittleEndian.Uint64([]byte(totalb + "\x00")) |
|
|
|
|
|
|
|
|
|
@ -59,5 +68,8 @@ func (c *meminfoCollector) getMemInfo() (map[string]float64, error) { |
|
|
|
|
"swapped_in_bytes_total": ps * float64(vmstat.pageins), |
|
|
|
|
"swapped_out_bytes_total": ps * float64(vmstat.pageouts), |
|
|
|
|
"total_bytes": float64(total), |
|
|
|
|
"swap_used_bytes": float64(swap.xsu_used), |
|
|
|
|
"swap_free_bytes": float64(swap.xsu_avail), |
|
|
|
|
"swap_total_bytes": float64(swap.xsu_total), |
|
|
|
|
}, nil |
|
|
|
|
} |
|
|
|
|
|