@ -23,6 +23,7 @@ import (
/ *
/ *
# include < sys / param . h >
# include < sys / param . h >
# include < sys / types . h >
# include < sys / types . h >
# include < sys / mount . h >
# include < sys / sysctl . h >
# include < sys / sysctl . h >
int
int
@ -37,22 +38,39 @@ sysctl_uvmexp(struct uvmexp *uvmexp)
return 0 ;
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"
import "C"
func ( c * meminfoCollector ) getMemInfo ( ) ( map [ string ] float64 , error ) {
func ( c * meminfoCollector ) getMemInfo ( ) ( map [ string ] float64 , error ) {
var uvmexp C . struct_uvmexp
var uvmexp C . struct_uvmexp
var bcstats C . struct_bcachestats
if _ , err := C . sysctl_uvmexp ( & uvmexp ) ; err != nil {
if _ , err := C . sysctl_uvmexp ( & uvmexp ) ; err != nil {
return nil , fmt . Errorf ( "sysctl CTL_VM VM_UVMEXP failed: %v" , err )
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 )
ps := float64 ( uvmexp . pagesize )
// see uvm(9)
// see uvm(9)
return map [ string ] float64 {
return map [ string ] float64 {
"active_bytes" : ps * float64 ( uvmexp . active ) ,
"active_bytes" : ps * float64 ( uvmexp . active ) ,
"cache_bytes" : ps * float64 ( uvmexp. vnode pages) ,
"cache_bytes" : ps * float64 ( bcstats. numbuf pages) ,
"free_bytes" : ps * float64 ( uvmexp . free ) ,
"free_bytes" : ps * float64 ( uvmexp . free ) ,
"inactive_bytes" : ps * float64 ( uvmexp . inactive ) ,
"inactive_bytes" : ps * float64 ( uvmexp . inactive ) ,
"size_bytes" : ps * float64 ( uvmexp . npages ) ,
"size_bytes" : ps * float64 ( uvmexp . npages ) ,