Linux system memory mechanism: In Linux there is such a thought, the memory is not white, so it as far as possible cache and buffer some data to facilitate the next use. But in fact, the memory is also available for immediate use. So free memory =free+buffers+cached
#!/bin/bash usage= "' Basename $0 ' [-w|--warning]<percent free> [-c|-- Critical]<percent free> " threshold_usage=" warning threshold must be greater than critical: ' basename $0 ' $* ' calc=/tmp/memcalc Percent_free=/tmp/mempercent critical= " warning=" " STATE_OK=0 State_warning=1 state_critical=2 state_unknown=3 # print usage if [ $# -lt 4 ]; then echo " " echo " wrong syntax: ' basename $0 ' $* " echo "" echo "usage: $USAGE" echo "" exit 0 fi # read input&Nbsp; while [ $# -gt 0 ] do case "$" in -w|--warning) shift warning=$1 ;; -c|--critical) shift critical=$1 ;; esac shift done # verify input if [[ $warning -eq $critical | | $warning -lt $critical ]]; then echo "" echo "$THRESHOLD _usage" echo " echo " usage: $USAGE " echo "" exit 0 fi # total memory available total= ' free -m | head -2 |tail -1 |gawk ' { print $2} ' # total memory used used= ' Free -m | head -3 |tail -1 |awk ' {print $3} ' # calc total minus used free= ' free -m | head -3 |tail -1 |awk ' {print $4} ' # normal values #echo $total mb total #echo $used mb used #echo $free mb free # make it into % percent free = ((FREE&NBSP;MEM&NBSP;/&NBSP;TOTAL&NBSP;MEM) * 100) echo "5" > $calc # decimal accuracy echo "K" >> $calc # commit echo "+" >> $calc # multiply echo "$free" >> $calc # division integer echo "$total" >> $calc # division integer echo "/" >> $calc # division sign echo "*" >> $calc # multiplication sign echo "P" >> $calc # print Percent= '/usr/bin/dc $calc |/bin/sed ' s/^\./0./' |/usr/bin/tr '. " " " |/usr/bin/gawk {' print $1 '} '  : #percent1 = '/usr/bin/dc $calc ' #echo ' $percent 1 if [[ ' $percent " -le $critical ]]; then echo " critical - $free MB ($percent%) free memory " exit 2 fi if [[ "$percent" -le $warning ]]; then echo "warning - $free MB ($percent%) Free memory " exit 1 fi if [[ " $ Percent " -gt $warning ]]; then echo " OK - $free MB ($percent%) free memory " exit 0 fi
This article is from the "Smurf Linux ops" blog, so be sure to keep this source http://jin771998569.blog.51cto.com/2147853/1636439
Nagios Monitoring Server remaining memory