diff options
-rw-r--r-- | collector/meminfo_darwin.go | 12 |
1 files changed, 12 insertions, 0 deletions
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 @@ | |||
16 | package collector | 16 | package collector |
17 | 17 | ||
18 | // #include <mach/mach_host.h> | 18 | // #include <mach/mach_host.h> |
19 | // #include <sys/sysctl.h> | ||
20 | // typedef struct xsw_usage xsw_usage_t; | ||
19 | import "C" | 21 | import "C" |
20 | 22 | ||
21 | import ( | 23 | import ( |
@@ -43,6 +45,13 @@ func (c *meminfoCollector) getMemInfo() (map[string]float64, error) { | |||
43 | if err != nil { | 45 | if err != nil { |
44 | return nil, err | 46 | return nil, err |
45 | } | 47 | } |
48 | |||
49 | swapraw, err := unix.SysctlRaw("vm.swapusage") | ||
50 | if err != nil { | ||
51 | return nil, err | ||
52 | } | ||
53 | swap := (*C.xsw_usage_t)(unsafe.Pointer(&swapraw[0])) | ||
54 | |||
46 | // Syscall removes terminating NUL which we need to cast to uint64 | 55 | // Syscall removes terminating NUL which we need to cast to uint64 |
47 | total := binary.LittleEndian.Uint64([]byte(totalb + "\x00")) | 56 | total := binary.LittleEndian.Uint64([]byte(totalb + "\x00")) |
48 | 57 | ||
@@ -59,5 +68,8 @@ func (c *meminfoCollector) getMemInfo() (map[string]float64, error) { | |||
59 | "swapped_in_bytes_total": ps * float64(vmstat.pageins), | 68 | "swapped_in_bytes_total": ps * float64(vmstat.pageins), |
60 | "swapped_out_bytes_total": ps * float64(vmstat.pageouts), | 69 | "swapped_out_bytes_total": ps * float64(vmstat.pageouts), |
61 | "total_bytes": float64(total), | 70 | "total_bytes": float64(total), |
71 | "swap_used_bytes": float64(swap.xsu_used), | ||
72 | "swap_free_bytes": float64(swap.xsu_avail), | ||
73 | "swap_total_bytes": float64(swap.xsu_total), | ||
62 | }, nil | 74 | }, nil |
63 | } | 75 | } |