From 2cae917bb7e0b6379221e8a24da012b16e63d661 Mon Sep 17 00:00:00 2001 From: Matthieu Guegan Date: Mon, 2 Dec 2019 13:41:58 +0100 Subject: [PATCH] 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 --- collector/meminfo_openbsd.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/collector/meminfo_openbsd.go b/collector/meminfo_openbsd.go index 4915c012..75702ef8 100644 --- a/collector/meminfo_openbsd.go +++ b/collector/meminfo_openbsd.go @@ -23,6 +23,7 @@ import ( /* #include #include +#include #include int @@ -37,22 +38,39 @@ sysctl_uvmexp(struct uvmexp *uvmexp) return 0; } +int +sysctl_bcstats(struct bcachestats *bcstats) +{ + static int bcstats_mib[] = {CTL_VFS, VFS_GENERIC, VFS_BCACHESTAT}; + size_t sz = sizeof(struct bcachestats); + + if(sysctl(bcstats_mib, 3, bcstats, &sz, NULL, 0) < 0) + return -1; + + return 0; +} + */ import "C" func (c *meminfoCollector) getMemInfo() (map[string]float64, error) { var uvmexp C.struct_uvmexp + var bcstats C.struct_bcachestats if _, err := C.sysctl_uvmexp(&uvmexp); err != nil { return nil, fmt.Errorf("sysctl CTL_VM VM_UVMEXP failed: %v", err) } + if _, err := C.sysctl_bcstats(&bcstats); err != nil { + return nil, fmt.Errorf("sysctl CTL_VFS VFS_GENERIC VFS_BCACHESTAT failed: %v", err) + } + ps := float64(uvmexp.pagesize) // see uvm(9) return map[string]float64{ "active_bytes": ps * float64(uvmexp.active), - "cache_bytes": ps * float64(uvmexp.vnodepages), + "cache_bytes": ps * float64(bcstats.numbufpages), "free_bytes": ps * float64(uvmexp.free), "inactive_bytes": ps * float64(uvmexp.inactive), "size_bytes": ps * float64(uvmexp.npages),