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),