version 1.68, 2011/04/10 03:20:59 |
version 1.69, 2011/07/12 14:57:53 |
|
|
#include <unistd.h> |
#include <unistd.h> |
#include <sys/sysctl.h> |
#include <sys/sysctl.h> |
#include <sys/dkstat.h> |
#include <sys/dkstat.h> |
|
#include <sys/mount.h> |
#include <sys/swap.h> |
#include <sys/swap.h> |
#include <err.h> |
#include <err.h> |
#include <errno.h> |
#include <errno.h> |
|
|
}; |
}; |
|
|
/* these are for detailing the memory statistics */ |
/* these are for detailing the memory statistics */ |
int memory_stats[8]; |
int memory_stats[10]; |
char *memorynames[] = { |
char *memorynames[] = { |
"Real: ", "K/", "K act/tot ", "Free: ", "K ", |
"Real: ", "K/", "K act/tot ", "Free: ", "K ", |
"Swap: ", "K/", "K used/tot", |
"Cache: ", "K ", |
|
"Swap: ", "K/", "K", |
NULL |
NULL |
}; |
}; |
|
|
|
|
{ |
{ |
static int sysload_mib[] = {CTL_VM, VM_LOADAVG}; |
static int sysload_mib[] = {CTL_VM, VM_LOADAVG}; |
static int vmtotal_mib[] = {CTL_VM, VM_METER}; |
static int vmtotal_mib[] = {CTL_VM, VM_METER}; |
|
static int bcstats_mib[] = {CTL_VFS, VFS_GENERIC, VFS_BCACHESTAT}; |
struct loadavg sysload; |
struct loadavg sysload; |
struct vmtotal vmtotal; |
struct vmtotal vmtotal; |
|
struct bcachestats bcstats; |
double *infoloadp; |
double *infoloadp; |
size_t size; |
size_t size; |
int i; |
int i; |
|
|
warn("sysctl failed"); |
warn("sysctl failed"); |
bzero(&vmtotal, sizeof(vmtotal)); |
bzero(&vmtotal, sizeof(vmtotal)); |
} |
} |
|
size = sizeof(bcstats); |
|
if (sysctl(bcstats_mib, 3, &bcstats, &size, NULL, 0) < 0) { |
|
warn("sysctl failed"); |
|
bzero(&bcstats, sizeof(bcstats)); |
|
} |
/* convert memory stats to Kbytes */ |
/* convert memory stats to Kbytes */ |
memory_stats[0] = -1; |
memory_stats[0] = -1; |
memory_stats[1] = pagetok(vmtotal.t_arm); |
memory_stats[1] = pagetok(vmtotal.t_arm); |
|
|
memory_stats[3] = -1; |
memory_stats[3] = -1; |
memory_stats[4] = pagetok(vmtotal.t_free); |
memory_stats[4] = pagetok(vmtotal.t_free); |
memory_stats[5] = -1; |
memory_stats[5] = -1; |
|
memory_stats[6] = pagetok(bcstats.numbufpages); |
|
memory_stats[7] = -1; |
|
|
if (!swapmode(&memory_stats[6], &memory_stats[7])) { |
if (!swapmode(&memory_stats[8], &memory_stats[9])) { |
memory_stats[6] = 0; |
memory_stats[8] = 0; |
memory_stats[7] = 0; |
memory_stats[9] = 0; |
} |
} |
|
|
/* set arrays and strings */ |
/* set arrays and strings */ |