diff options
author | Matthieu Guegan <matthieu.guegan@deindeal.ch> | 2019-12-02 13:41:58 +0100 |
---|---|---|
committer | Johannes 'fish' Ziemke <github@freigeist.org> | 2019-12-02 13:41:58 +0100 |
commit | 2cae917bb7e0b6379221e8a24da012b16e63d661 (patch) | |
tree | 5d48b8be0c272b2cb056a7fea10722b35eaab73f | |
parent | 0d9d7e961a9c5784faea6f279d975845a484e927 (diff) | |
download | prometheus_node_collector-2cae917bb7e0b6379221e8a24da012b16e63d661.tar.bz2 prometheus_node_collector-2cae917bb7e0b6379221e8a24da012b16e63d661.tar.xz prometheus_node_collector-2cae917bb7e0b6379221e8a24da012b16e63d661.zip |
fix OpenBSD cache memory information (#1542)
This will now use `bcstats.numbufpages` instead of `uvmexp.vnodepages`.
Inspired by OpenBSD's `src/usr.bin/top`
Signed-off-by: Matthieu Guegan <matthieu.guegan@deindeal.ch>
-rw-r--r-- | collector/meminfo_openbsd.go | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/collector/meminfo_openbsd.go b/collector/meminfo_openbsd.go index 4915c01..75702ef 100644 --- a/collector/meminfo_openbsd.go +++ b/collector/meminfo_openbsd.go | |||
@@ -23,6 +23,7 @@ import ( | |||
23 | /* | 23 | /* |
24 | #include <sys/param.h> | 24 | #include <sys/param.h> |
25 | #include <sys/types.h> | 25 | #include <sys/types.h> |
26 | #include <sys/mount.h> | ||
26 | #include <sys/sysctl.h> | 27 | #include <sys/sysctl.h> |
27 | 28 | ||
28 | int | 29 | int |
@@ -37,22 +38,39 @@ sysctl_uvmexp(struct uvmexp *uvmexp) | |||
37 | return 0; | 38 | return 0; |
38 | } | 39 | } |
39 | 40 | ||
41 | int | ||
42 | sysctl_bcstats(struct bcachestats *bcstats) | ||
43 | { | ||
44 | static int bcstats_mib[] = {CTL_VFS, VFS_GENERIC, VFS_BCACHESTAT}; | ||
45 | size_t sz = sizeof(struct bcachestats); | ||
46 | |||
47 | if(sysctl(bcstats_mib, 3, bcstats, &sz, NULL, 0) < 0) | ||
48 | return -1; | ||
49 | |||
50 | return 0; | ||
51 | } | ||
52 | |||
40 | */ | 53 | */ |
41 | import "C" | 54 | import "C" |
42 | 55 | ||
43 | func (c *meminfoCollector) getMemInfo() (map[string]float64, error) { | 56 | func (c *meminfoCollector) getMemInfo() (map[string]float64, error) { |
44 | var uvmexp C.struct_uvmexp | 57 | var uvmexp C.struct_uvmexp |
58 | var bcstats C.struct_bcachestats | ||
45 | 59 | ||
46 | if _, err := C.sysctl_uvmexp(&uvmexp); err != nil { | 60 | if _, err := C.sysctl_uvmexp(&uvmexp); err != nil { |
47 | return nil, fmt.Errorf("sysctl CTL_VM VM_UVMEXP failed: %v", err) | 61 | return nil, fmt.Errorf("sysctl CTL_VM VM_UVMEXP failed: %v", err) |
48 | } | 62 | } |
49 | 63 | ||
64 | if _, err := C.sysctl_bcstats(&bcstats); err != nil { | ||
65 | return nil, fmt.Errorf("sysctl CTL_VFS VFS_GENERIC VFS_BCACHESTAT failed: %v", err) | ||
66 | } | ||
67 | |||
50 | ps := float64(uvmexp.pagesize) | 68 | ps := float64(uvmexp.pagesize) |
51 | 69 | ||
52 | // see uvm(9) | 70 | // see uvm(9) |
53 | return map[string]float64{ | 71 | return map[string]float64{ |
54 | "active_bytes": ps * float64(uvmexp.active), | 72 | "active_bytes": ps * float64(uvmexp.active), |
55 | "cache_bytes": ps * float64(uvmexp.vnodepages), | 73 | "cache_bytes": ps * float64(bcstats.numbufpages), |
56 | "free_bytes": ps * float64(uvmexp.free), | 74 | "free_bytes": ps * float64(uvmexp.free), |
57 | "inactive_bytes": ps * float64(uvmexp.inactive), | 75 | "inactive_bytes": ps * float64(uvmexp.inactive), |
58 | "size_bytes": ps * float64(uvmexp.npages), | 76 | "size_bytes": ps * float64(uvmexp.npages), |