Memory Usage Monitor on Linux/SunOS Servers

ok, so i'm trying to write a shell script (not perl) that monitors memory usage on a server. but i'm confused as to what fields exactly determines that yes, memory is low on a particular server.

it sounds simple enough, but it really isn't. what do I look for in the field below?

[hostname:527] 
[hostname:527] snmpwalk -v2c -c bla@$AF s54.jabla.net UCD-SNMP-MIB::memory    
UCD-SNMP-MIB::memIndex.0 = INTEGER: 0
UCD-SNMP-MIB::memErrorName.0 = STRING: swap
UCD-SNMP-MIB::memTotalSwap.0 = INTEGER: 2040212 kB
UCD-SNMP-MIB::memAvailSwap.0 = INTEGER: 2036260 kB
UCD-SNMP-MIB::memTotalReal.0 = INTEGER: 8314956 kB
UCD-SNMP-MIB::memAvailReal.0 = INTEGER: 302620 kB
UCD-SNMP-MIB::memTotalFree.0 = INTEGER: 2338880 kB
UCD-SNMP-MIB::memMinimumSwap.0 = INTEGER: 16000 kB
UCD-SNMP-MIB::memShared.0 = INTEGER: 0 kB
UCD-SNMP-MIB::memBuffer.0 = INTEGER: 203980 kB
UCD-SNMP-MIB::memCached.0 = INTEGER: 4031680 kB
UCD-SNMP-MIB::memSwapError.0 = INTEGER: noError(0)
UCD-SNMP-MIB::memSwapErrorMsg.0 = STRING: 
[hostname:528] 
[hostname:528] 

With VM, low memory is excess paging. Memory only shows as free because a process exited and released their swap, or the system was recently rebooted, and so indicates nothing. If a process mmap's files, like dynamic libraries, those pages are still in use for that even though not assigned to any process! When no memory is free and you need a page, it just takes the least used and unmodified page from whoever was using it, and if anyone references that page, it will take a RAM page from some other VM page and read the requested VM page back in to it.