@ -21,12 +21,12 @@
*/
*/
# include <fcntl.h>
# include <fcntl.h>
# include <kvm.h>
# include <limits.h>
# include <limits.h>
# include <stdio.h>
# include <stdio.h>
# include <stdlib.h>
# include <stdlib.h>
# include <string.h>
# include <string.h>
# include <sys/param.h>
# include <sys/param.h>
# include <sys/resource.h>
# include <sys/sysctl.h>
# include <sys/sysctl.h>
# include <sys/types.h>
# include <sys/types.h>
# include <sys/vmmeter.h>
# include <sys/vmmeter.h>
@ -34,6 +34,7 @@
/* Everything post 1.5.x uses uvm/uvm_* includes */
/* Everything post 1.5.x uses uvm/uvm_* includes */
# if __NetBSD_Version__ >= 105010000
# if __NetBSD_Version__ >= 105010000
# include <uvm/uvm_param.h>
# include <uvm/uvm_param.h>
# include <uvm/uvm_extern.h>
# else
# else
# include <vm/vm_param.h>
# include <vm/vm_param.h>
# endif
# endif
@ -45,29 +46,25 @@
static size_t Total = 0 ;
static size_t Total = 0 ;
static size_t MFree = 0 ;
static size_t MFree = 0 ;
static size_t Used = 0 ;
static size_t Used = 0 ;
static size_t Buffers = 0 ;
static size_t Active = 0 ;
static size_t Cached = 0 ;
static size_t Inactive = 0 ;
static size_t Wired = 0 ;
static size_t Execpages = 0 ;
static size_t Filepages = 0 ;
static size_t STotal = 0 ;
static size_t STotal = 0 ;
static size_t SFree = 0 ;
static size_t SFree = 0 ;
static size_t SUsed = 0 ;
static size_t SUsed = 0 ;
static kvm_t * kd ;
void
void
initMemory ( struct SensorModul * sm )
initMemory ( struct SensorModul * sm )
{
{
char * nlistf = NULL ;
char * memf = NULL ;
char buf [ _POSIX2_LINE_MAX ] ;
if ( ( kd = kvm_openfiles ( nlistf , memf , NULL , O_RDONLY , buf ) ) = = NULL ) {
log_error ( " kvm_openfiles() " ) ;
return ;
}
registerMonitor ( " mem/physical/free " , " integer " , printMFree , printMFreeInfo , sm ) ;
registerMonitor ( " mem/physical/free " , " integer " , printMFree , printMFreeInfo , sm ) ;
registerMonitor ( " mem/physical/used " , " integer " , printUsed , printUsedInfo , sm ) ;
registerMonitor ( " mem/physical/used " , " integer " , printUsed , printUsedInfo , sm ) ;
registerMonitor ( " mem/physical/buf " , " integer " , printBuffers , printBuffersInfo , sm ) ;
registerMonitor ( " mem/physical/active " , " integer " , printActive , printActiveInfo , sm ) ;
registerMonitor ( " mem/physical/cached " , " integer " , printCached , printCachedInfo , sm ) ;
registerMonitor ( " mem/physical/inactive " , " integer " , printInactive , printInactiveInfo , sm ) ;
registerMonitor ( " mem/physical/wired " , " integer " , printWired , printWiredInfo , sm ) ;
registerMonitor ( " mem/physical/execpages " , " integer " , printExecpages , printExecpagesInfo , sm ) ;
registerMonitor ( " mem/physical/filepages " , " integer " , printFilepages , printFilepagesInfo , sm ) ;
registerMonitor ( " mem/swap/free " , " integer " , printSwapFree , printSwapFreeInfo , sm ) ;
registerMonitor ( " mem/swap/free " , " integer " , printSwapFree , printSwapFreeInfo , sm ) ;
registerMonitor ( " mem/swap/used " , " integer " , printSwapUsed , printSwapUsedInfo , sm ) ;
registerMonitor ( " mem/swap/used " , " integer " , printSwapUsed , printSwapUsedInfo , sm ) ;
}
}
@ -75,7 +72,6 @@ initMemory(struct SensorModul* sm)
void
void
exitMemory ( void )
exitMemory ( void )
{
{
kvm_close ( kd ) ;
}
}
int
int
@ -83,7 +79,6 @@ updateMemory(void)
{
{
# define ARRLEN(X) (sizeof(X) / sizeof(X[0]))
# define ARRLEN(X) (sizeof(X) / sizeof(X[0]))
long pagesize ; /* using a long promotes the arithmetic */
size_t len ;
size_t len ;
{
{
@ -95,35 +90,23 @@ updateMemory(void)
}
}
{
{
struct uvmexp x ;
struct uvmexp _sysctl x ;
static int mib [ ] = { CTL_VM , VM_UVMEXP } ;
static int mib [ ] = { CTL_VM , VM_UVMEXP 2 } ;
len = sizeof ( x ) ;
len = sizeof ( x ) ;
STotal = SUsed = SFree = - 1 ;
STotal = SUsed = SFree = - 1 ;
pagesize = 1 ;
Active = Inactive = Wired = Execpages = Filepages = MFree = Used = - 1 ;
if ( - 1 < sysctl ( mib , ARRLEN ( mib ) , & x , & len , NULL , 0 ) ) {
if ( - 1 < sysctl ( mib , ARRLEN ( mib ) , & x , & len , NULL , 0 ) ) {
pagesize = x . pagesize ;
STotal = ( x . pagesize * x . swpages ) > > 10 ;
STotal = ( pagesize * x . swpages ) > > 10 ;
SUsed = ( x . pagesize * x . swpginuse ) > > 10 ;
SUsed = ( pagesize * x . swpginuse ) > > 10 ;
SFree = STotal - SUsed ;
SFree = STotal - SUsed ;
}
MFree = STotal - SUsed ;
}
Active = ( x . active * x . pagesize ) > > 10 ;
Inactive = ( x . inactive * x . pagesize ) > > 10 ;
/* can't find NetBSD filesystem buffer info */
Wired = ( x . wired * x . pagesize ) > > 10 ;
Buffers = - 1 ;
Execpages = ( x . execpages * x . pagesize ) > > 10 ;
Filepages = ( x . filepages * x . pagesize ) > > 10 ;
/* NetBSD doesn't know about vm.stats */
Used = Total - MFree ;
Cached = - 1 ;
{
static int mib [ ] = { CTL_VM , VM_METER } ;
struct vmtotal x ;
len = sizeof ( x ) ;
MFree = Used = - 1 ;
if ( sysctl ( mib , ARRLEN ( mib ) , & x , & len , NULL , 0 ) > - 1 ) {
MFree = ( x . t_free * pagesize ) > > 10 ;
Used = ( x . t_rm * pagesize ) > > 10 ;
}
}
}
}
return 0 ;
return 0 ;
@ -154,27 +137,63 @@ printUsedInfo(const char* cmd)
}
}
void
void
printBuffers ( const char * cmd )
printActive ( const char * cmd )
{
fprintf ( CurrentClient , " %d \n " , Active ) ;
}
void
printActiveInfo ( const char * cmd )
{
fprintf ( CurrentClient , " Active Memory \t 0 \t %dtKB \n " , Total ) ;
}
void
printInactive ( const char * cmd )
{
fprintf ( CurrentClient , " %d \n " , Inactive ) ;
}
void
printInactiveInfo ( const char * cmd )
{
fprintf ( CurrentClient , " Inctive Memory \t 0 \t %dtKB \n " , Total ) ;
}
void
printWired ( const char * cmd )
{
fprintf ( CurrentClient , " %d \n " , Wired ) ;
}
void
printWiredInfo ( const char * cmd )
{
fprintf ( CurrentClient , " Wired Memory \t 0 \t %dtKB \n " , Total ) ;
}
void
printExecpages ( const char * cmd )
{
{
fprintf ( CurrentClient , " %d \n " , Buffers ) ;
fprintf ( CurrentClient , " %d \n " , Execpage s) ;
}
}
void
void
printBuffersInfo ( const char * cmd )
print Execpage sInfo( const char * cmd )
{
{
fprintf ( CurrentClient , " Buffer Memory \t 0 \t %d \t KB \n " , Total ) ;
fprintf ( CurrentClient , " Exec Pages\t 0 %d\t KB \n " , Total ) ;
}
}
void
void
printCached ( const char * cmd )
print Filepages ( const char * cmd )
{
{
fprintf ( CurrentClient , " %d \n " , Cached ) ;
fprintf ( CurrentClient , " %d \n " , Filepages ) ;
}
}
void
void
printCachedInfo ( const char * cmd )
print Filepages Info( const char * cmd )
{
{
fprintf ( CurrentClient , " Cached Memory \t 0 \t %d \t KB \n " , Total ) ;
fprintf ( CurrentClient , " File Pages \t 0 \t %d \t KB \n " , Total ) ;
}
}
void
void