-------------------------------
#!/bin/sh
#
# -- san2(at)linuxchannel.net
# -- 2004.11.11
# -- FreeBSD memory information(in vmstat)
count2size()
{
ACTIVE=$1; WIRE=$2; INACTIVE=$3
CACHE=$4; FREE=$5; TOTAL=$6
TOTAL=`perl -e "printf('%.2f',$TOTAL/$UNIT)"`
_FREE=`perl -e "printf('%.2f',($INACTIVE+$CACHE+$FREE)/$UNIT)"`
_USED=`perl -e "printf('%.2f',$TOTAL-$_FREE)"`
_ETC=`perl -e "printf('%.2f',$_USED-($ACTIVE+$WIRE)/$UNIT)"`
ACTIVE=`perl -e "printf('%.2f',$ACTIVE/$UNIT)"`
WIRE=`perl -e "printf('%.2f',$WIRE/$UNIT)"`
INACTIVE=`perl -e "printf('%.2f',$INACTIVE/$UNIT)"`
CACHE=`perl -e "printf('%.2f',$CACHE/$UNIT)"`
FREE=`perl -e "printf('%.2f',$FREE/$UNIT)"`
}
PAGE=4096
UNIT=`perl -e "printf('%.2f',1048576/$PAGE)"`
ARGS=`sysctl -n vm.stats.vm.v_active_count vm.stats.vm.v_wire_count \
vm.stats.vm.v_inactive_count vm.stats.vm.v_cache_count \
vm.stats.vm.v_free_count vm.stats.vm.v_page_count`
count2size $ARGS
cat <<__END__
memory information(in vmstat)
_USED: $_USED MB = ACTIVE($ACTIVE MB) + WIRE($WIRE MB) + ETC($_ETC MB)
_FREE: $_FREE MB = INACTIVE($INACTIVE MB) + CACHE($CACHE MB) + FREE($FREE MB)
TOTAL: $TOTAL MB = _USED($_USED MB) + _FREE($_FREE MB)
__END__
exit 0
---------------------------------------
|