From 982853369737e9c81361bf2210f1f9a8cfd1cf14 Mon Sep 17 00:00:00 2001 From: jonas-lindmark <60670615+jonas-lindmark@users.noreply.github.com> Date: Wed, 19 Feb 2020 15:51:30 +0100 Subject: Swap usage on darwin from sysctl vm.swapusage (#1608) Signed-off-by: jonas --- collector/meminfo_darwin.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/collector/meminfo_darwin.go b/collector/meminfo_darwin.go index 5ca9004..87f3e5a 100644 --- a/collector/meminfo_darwin.go +++ b/collector/meminfo_darwin.go @@ -16,6 +16,8 @@ package collector // #include +// #include +// 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 } -- cgit v1.2.3