aboutsummaryrefslogtreecommitdiff
path: root/collector
diff options
context:
space:
mode:
authorjonas-lindmark <60670615+jonas-lindmark@users.noreply.github.com>2020-02-19 15:51:30 +0100
committerGitHub <noreply@github.com>2020-02-19 15:51:29 +0100
commit982853369737e9c81361bf2210f1f9a8cfd1cf14 (patch)
tree9f411c47293a6f25222cb7b04b06eae14b334bc2 /collector
parent8faa843fc42260cabb749cc9eb8886c191f28f7c (diff)
downloadprometheus_node_collector-982853369737e9c81361bf2210f1f9a8cfd1cf14.tar.bz2
prometheus_node_collector-982853369737e9c81361bf2210f1f9a8cfd1cf14.tar.xz
prometheus_node_collector-982853369737e9c81361bf2210f1f9a8cfd1cf14.zip
Swap usage on darwin from sysctl vm.swapusage (#1608)
Signed-off-by: jonas <jonas.lindmark@denacode.se>
Diffstat (limited to 'collector')
-rw-r--r--collector/meminfo_darwin.go12
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 @@
16package collector 16package 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;
19import "C" 21import "C"
20 22
21import ( 23import (
@@ -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}