Open main menu

OpenVZ Virtuozzo Containers Wiki β

Changes

User:Kako/check vpsconf ressources.sh

12,128 bytes removed, 14:06, 12 August 2009
checking now mem by using vzmemcheck
#
# @author Claudio Thomas, 2009
# @version $Id: check_vpsconf_ressources.sh,v 1.1 3 2009/08/12 1014:5404:49 50 thomas_c Exp $
# @license LGPL
# @see http://wiki.openvz.org/UBC_systemwide_configuration
# Functions
# ------------------------------------------------------------------
function ok() {
echo "\033[0;32mOK $1\033[0m";
}
function warn() {
echo "\033[1;33mWARN $1\033[0m";
}
function err() {
echo "\033[0;31mERR $1\033[0m";
}
function incWarnings() {
w=`expr $w + 1`;
}
function checkDisk() {
# DISKSPACE
diskspaces=`egrep ^DISKSPACE $VZCONF_PATH/*.conf | cut -d '"' -f 2`
if [ "$sum_hard" -lt "$diskinode_real" ]; then echo -e "\t-- `ok`"; else echo -e "\t-- `warn '!!!'`"; incWarnings; fi
}
function checkMem() { mem_real_kbmem=`cat /proc/meminfo | grep 'MemTotal' | tr vzmemcheck -s ' ' | cut -d ' ' -f 2` lowmem_real_kb=`cat /proc/meminfo | grep 'LowTotal' | tr -s ' ' | cut -d ' ' -f 2` mem_real_mb=`expr $mem_real_kb / 1024` lowmem_real_mb=`expr $lowmem_real_kb / 1024` echo -e "TOTAL MEM:\t$mem_real_mb MB"; #------------------ # ---- LOW RAM ---- # @see: http://wiki.openvz.org/UBC_systemwide_configuration#.E2.80.9CLow_memory.E2.80.9D RAM_kb=v`echo "scale=4;0.4 * $lowmem_real_kb" | bc` RAM_mb=`echo "scale=4;$RAM_kb / 1024" | bc` echo -e "LOW MEM:\t$lowmem_real_mb MB (40% -> $RAM_mb MB)"; # ALLSOCKETBUF LIMIT = tcprcvbuf+tcpsndbuf+dgramrcvbuf+othersockbuf tcprcvbuf_b=`egrep ^TCPRCVBUF $VZCONF_PATH/*.conf | cut -d '"' -f 2` tcpsndbuf_b=`egrep ^TCPSNDBUF $VZCONF_PATH/*.conf | cut -d '"' -f 2` dgramrcvbuf_b=`egrep ^DGRAMRCVBUF $VZCONF_PATH/*.conf | cut -d '"' -f 2` othersockbuf_b=`egrep ^OTHERSOCKBUF $VZCONF_PATH/*.conf | cut -d 'mem"' -f 2` sum_soft_b=0; sum_hard_b=0; for limit in $tcprcvbuf_b; do soft_b=`echo $limit | cut -d ':' -f 1`; hard_b=`echo $limit | cut -d ':' -f 2`; sum_soft_b=`expr $sum_soft_b + $soft_b`; sum_hard_b=`expr $sum_hard_b + $hard_b`; done; for limit in $tcpsndbuf_b; do soft_b=`echo $limit | cut -d ':' -f 1`; hard_b=`echo $limit | cut -d ':' -f 2`; sum_soft_b=`expr $sum_soft_b + $soft_b`; sum_hard_b=`expr $sum_hard_b + $hard_b`; done; for limit in $dgramrcvbuf_b; do soft_bmem_sumary=`echo $limit | cut -d ':' -f 1`; hard_b=`echo $limit | cut -d ':' -f 2`; sum_soft_b=`expr $sum_soft_b + $soft_b`; sum_hard_b=`expr $sum_hard_b + $hard_b`; done; for limit in $othersockbuf_b; do soft_b=`echo $limit | cut -d ':' -f 1`; hard_b=`echo $limit | cut -d ':' -f 2`; sum_soft_b=`expr $sum_soft_b + $soft_b`; sum_hard_b=`expr $sum_hard_b + $hard_b`; done; # ALLSOCKETBUF current = tcprcvbuf+tcpsndbuf+dgramrcvbuf+othersockbuf tcprcvbuf_b=`grep tcprcvbuf /proc/user_beancounters | grep -v $MAX_VAL | tr -s ' ' | cut -d ' ' -f 3` tcpsndbuf_b=`grep tcpsndbuf /proc/user_beancounters mem | grep -v $MAX_VAL | tr -s ' Summary' | cut -d ' ' -f 3` dgramrcvbuf_b=`grep dgramrcvbuf /proc/user_beancounters | grep -v $MAX_VAL | tr -s ' ' | cut -d ' ' -f 3` othersockbuf_b=`grep othersockbuf /proc/user_beancounters | grep -v $MAX_VAL | tr -s ' ' | cut -d ' ' -f 3` sum_cur_b=0; for current in $tcprcvbuf_b; do sum_cur_b=`expr $sum_cur_b + $current`; done; for current in $tcpsndbuf_b; do sum_cur_b=`expr $sum_cur_b + $current`; done; for current in $dgramrcvbuf_b; do sum_cur_b=`expr $sum_cur_b + $current`; done; for current in $othersockbuf_b; do sum_cur_b=`expr $sum_cur_b + $current`; done; # normalize (Values were in Byte, so convert to KB) sum_soft_kb=`expr $sum_soft_b / 1024`; sum_hard_kb=`expr $sum_hard_b / 1024`; sum_cur_kb=`expr $sum_cur_b / 1024`; ALLSOCKETBUF_soft_kb=$sum_soft_kb; ALLSOCKETBUF_hard_kb=$sum_hard_kb; ALLSOCKETBUF_cur_kb=$sum_cur_kb; ALLSOCKETBUF_soft_mb=`echo "scale=2;$ALLSOCKETBUF_soft_kb / 1024" | bc` ALLSOCKETBUF_hard_mb=`echo "scale=2;$ALLSOCKETBUF_hard_kb / 1024" | bc` ALLSOCKETBUF_cur_mb=`echo "scale=2;$ALLSOCKETBUF_cur_kb / 1024" | bc` echo -n "-ALLSOCKETBUF: "; echo -en "\tSOFT: $ALLSOCKETBUF_soft_mb MB"; echo -en "\tHARD: $ALLSOCKETBUF_hard_mb MB"; echo -e "\tCurrent: $ALLSOCKETBUF_cur_mb MB"; # KMEMSIZE LIMIT kmemsize_b=`egrep ^KMEMSIZE $VZCONF_PATH/*.conf | cut -d '"' -f 2` sum_soft_b=0; sum_hard_b=0; for limit percent in $kmemsize_bmem_sumary; do soft_b=`echo $limit | cut -d ':' -f 1`; hard_b=`echo $limit | cut -d ':' -f 2`; sum_soft_b=`expr $sum_soft_b + $soft_b`; sum_hard_b=`expr $sum_hard_b + $hard_b`; done; # KMEMSIZE current kmemsize_b=`grep kmemsize /proc/user_beancounters | grep -v '0:' | tr -s ' ' | cut -d ' ' -f 4` sum_cur_b=0; for current in $kmemsize_b; do sum_cur_b=`expr $sum_cur_b + $current`; done; # normalize (Values were in Byte, so convert to KB) sum_soft_kb=`expr $sum_soft_b / 1024`; sum_hard_kb=`expr $sum_hard_b / 1024`; sum_cur_kb=`expr $sum_cur_b / 1024`; KMEMSIZE_soft_kb=$sum_soft_kb; KMEMSIZE_hard_kb=$sum_hard_kb; KMEMSIZE_cur_kb=$sum_cur_kb; KMEMSIZE_soft_mb=`echo "scale=2;$KMEMSIZE_soft_kb / 1024" | bc` KMEMSIZE_hard_mb=`echo "scale=2;$KMEMSIZE_hard_kb / 1024" | bc` KMEMSIZE_cur_mb=`echo "scale=2;$KMEMSIZE_cur_kb / 1024" | bc` echo -n "-KMEMSIZE: "; echo -en "\tSOFT: $KMEMSIZE_soft_mb MB"; echo -en "\tHARD: $KMEMSIZE_hard_mb MB"; echo -e "\tCurrent: $KMEMSIZE_cur_mb MB";  level=`echo "scale=4;( $KMEMSIZE_cur_kb + $ALLSOCKETBUF_cur_kb ) / $RAM_kb" | bc` echo -en " LowMem Utilization: ($KMEMSIZE_cur_mb + $ALLSOCKETBUF_cur_mb) / $RAM_mb \t\t=> $level Level"; st=`echo "$level < 1" | bc`; if [ $st -eq 1 ]; then echo -e "\t-- `ok`"; else echo -e "\t-- `warn '!!!'`"; incWarnings; fi level=`echo "scale=4;( $KMEMSIZE_hard_kb + $ALLSOCKETBUF_hard_kb ) / $RAM_kb" | bc` echo -en " LowMem Commitment: ($KMEMSIZE_hard_mb + $ALLSOCKETBUF_hard_mb) / $RAM_mb\t\t=> $level Level"; st=`echo "$level percent < 1100" | bc`; if [ $st -eq 1 ]; then echo -e "\t-- `ok`"; else echo -e "\t-- `warn '!!!'`"; incWarnings; fi   #------------------ #---- TOTAL RAM ---- # @see: http://wiki.openvz.org/UBC_systemwide_configuration#Total_RAM physpages_b=`grep physpages /proc/user_beancounters | grep -v '$MAX_VAL $MAX_VAL' | tr -s ' ' | cut -d ' ' -f 3` sum_cur=0; for current in $physpages_b; do sum_cur_b=`expr $sum_cur_b + $current`; done; # normalize (Values were in Byte, so convert to KB) sum_cur_kb=`expr $sum_cur_b / 1024`; PHYSPAGES_cur_kb=$sum_cur_kb; PHYSPAGES_cur_mb=`echo "scale=2;$PHYSPAGES_cur_kb / 1024" | bc` amount_kb=`expr $PHYSPAGES_cur_kb + $KMEMSIZE_cur_kb + $ALLSOCKETBUF_cur_kb` amount_mb=`expr $amount_kb / 1024`; level=`echo "scale=4;$amount_kb / $mem_real_kb" | bc` echo -en " TotMem Utilization: ($PHYSPAGES_cur_mb + $KMEMSIZE_cur_mb + $ALLSOCKETBUF_cur_mb) / $mem_real_mb\t=> $amount_mb MB / $mem_real_mb MB ($level Level)"; st=`echo "$level < 1" | bc`; if [ $st -eq 1 ]; then echo -e "\t-- `ok`"; else echo -e "\t-- `warn`"; incWarnings; fi #------------------ #---- RAM+SWAP ---- # @see: http://wiki.openvz.org/UBC_systemwide_configuration#Memory_and_swap_space swapmem_real_kb=`cat /proc/meminfo | grep 'SwapTotal' | tr -s ' ' | cut -d ' ' -f 2` swapmem_real_mb=`expr $swapmem_real_kb / 1024` echo ""; echo -en "Swap MEM:\t$swapmem_real_mb MB"; mem4_kb=`expr 4 \* $mem_real_kb` if [ "$swapmem_real_kb" -lt "$mem4_kb" ]; then if [ "$mem_real_kb" -lt "$swapmem_real_kb" ]; then echo -e "\t-- `ok`"; else echo -e "\t-- `warn '!!! Swap should be > Total Mem'`"; incWarnings; fi else echo -e "\t-- `warn '!!! Swap should be < 4*Total Mem'`"; incWarnings; fi # OOMGUARPAGES LIMIT oomguarpages_b=`egrep ^OOMGUARPAGES $VZCONF_PATH/*.conf | cut -d '"' -f 2` sum_soft_b=0; sum_hard_b=0; for limit in $oomguarpages_b; do soft_b=`echo $limit | cut -d ':' -f 1`; hard_b=`echo $limit | cut -d ':' -f 2`; sum_soft_b=`expr $sum_soft_b + $soft_b`; sum_hard_b=`expr $sum_hard_b + $hard_b`; done; oomguarpages_b=`grep oomguarpages /proc/user_beancounters | grep -v '2147483647 2147483647' | tr -s ' ' | cut -d ' ' -f 3`; sum_cur_b=0; for current in $oomguarpages_b; do sum_cur_b=`expr $sum_cur_b + $current`; done; # normalize (Values were in Byte, so convert to KB) sum_cur_kb=`expr $sum_cur_b / 1024`; OOMGUARPAGES_soft_kb=$sum_soft_kb; OOMGUARPAGES_hard_kb=$sum_hard_kb; OOMGUARPAGES_cur_kb=$sum_cur_kb; OOMGUARPAGES_soft_mb=`echo "scale=2;$OOMGUARPAGES_soft_kb / 1024" | bc` OOMGUARPAGES_hard_mb=`echo "scale=2;$OOMGUARPAGES_hard_kb / 1024" | bc` OOMGUARPAGES_cur_mb=`echo "scale=2;$OOMGUARPAGES_cur_kb / 1024" | bc` echo -n "-OOMGUARPAGES: "; echo -en "\tSOFT: $OOMGUARPAGES_soft_mb MB"; echo -en "\tHARD: $OOMGUARPAGES_hard_mb MB"; echo -e "\tCurrent: $OOMGUARPAGES_cur_mb MB";  level=`echo "scale=4;( $OOMGUARPAGES_cur_kb + $KMEMSIZE_cur_kb + $ALLSOCKETBUF_cur_kb ) / ( $RAM_kb + swapmem_real_kb )" | bc` echo -en " Swap Utilization: ($OOMGUARPAGES_cur_mb + $KMEMSIZE_cur_mb + $ALLSOCKETBUF_cur_mb) / ($RAM_mb + $swapmem_real_mb) \t\t=> $level Level"; st=`echo "$level < 1" | bc`; if [ $st -eq 1 ]; then echo -e "\t-- `ok`"; else echo -e "\t-- `warn '!!!'`"; incWarnings; fi level=`echo "scale=4;( $OOMGUARPAGES_hard_kb + $KMEMSIZE_hard_kb + $ALLSOCKETBUF_hard_kb ) / ( $RAM_kb + swapmem_real_kb )" | bc` echo -en " Swap Commitment: ($OOMGUARPAGES_hard_mb + $KMEMSIZE_hard_mb + $ALLSOCKETBUF_hard_mb) / ($RAM_mb + $swapmem_real_mb) \t\t=> $level Level"; st=`echo "$level < 1" | bc`; if [ $st -eq 1 ]; then echo -e "\t-- `ok`"; else echo -e "\t-- `warn '!!!'`"; incWarnings; fi   #-------------------------- #---- Allocated Memory ---- # @see: http://wiki.openvz.org/UBC_systemwide_configuration#Allocated_memory # PRIVVMPAGES LIMIT privvmpages_b=`egrep ^PRIVVMPAGES $VZCONF_PATH/*.conf | cut -d '"' -f 2` sum_soft_b=0; sum_hard_b=0; for limit in $privvmpages_b; do soft_b=`echo $limit | cut -d ':' -f 1`; hard_b=`echo $limit | cut -d ':' -f 2`; sum_soft_b=`expr $sum_soft_b + $soft_b`; sum_hard_b=`expr $sum_hard_b + $hard_b`; done; privvmpages_b=`grep privvmpages /proc/user_beancounters | grep -v '2147483647 2147483647' | tr -s ' ' | cut -d ' ' -f 3`; sum_cur_b=0; for current in $privvmpages_b; do sum_cur_b=`expr $sum_cur_b + $current`; done; # normalize (Values were in Byte, so convert to KB) sum_cur_kb=`expr $sum_cur_b / 1024`; PRIVVMPAGES_soft_kb=$sum_soft_kb; PRIVVMPAGES_hard_kb=$sum_hard_kb; PRIVVMPAGES_cur_kb=$sum_cur_kb; PRIVVMPAGES_soft_mb=`echo "scale=2;$PRIVVMPAGES_soft_kb / 1024" | bc` PRIVVMPAGES_hard_mb=`echo "scale=2;$PRIVVMPAGES_hard_kb / 1024" | bc` PRIVVMPAGES_cur_mb=`echo "scale=2;$PRIVVMPAGES_cur_kb / 1024" | bc` echo -n "-PRIVVMPAGES: "; echo -en "\tSOFT: $PRIVVMPAGES_soft_mb MB"; echo -en "\tHARD: $PRIVVMPAGES_hard_mb MB"; echo -e "\tCurrent: $PRIVVMPAGES_cur_mb MB";  # VMGUARPAGES LIMIT vmguarpages_b=`egrep ^VMGUARPAGES $VZCONF_PATH/*.conf | cut -d '"' -f 2` sum_soft_b=0; sum_hard_b=0; for limit in $vmguarpages_b; do soft_b=`echo $limit | cut -d ':' -f 1`; hard_b=`echo $limit | cut -d ':' -f 2`; sum_soft_b=`expr $sum_soft_b + $soft_b`; sum_hard_b=`expr $sum_hard_b + $hard_b`; done; vmguarpages_b=`grep vmguarpages /proc/user_beancounters | grep -v '2147483647 2147483647' | tr -s ' ' | cut -d ' ' -f 3`; sum_cur_b=0; for current in $vmguarpages_b; do sum_cur_b=`expr $sum_cur_b + $current`; done; # normalize (Values were in Byte, so convert to KB) sum_cur_kb=`expr $sum_cur_b / 1024`; VMGUARPAGES_soft_kb=$sum_soft_kb; VMGUARPAGES_hard_kb=$sum_hard_kb; VMGUARPAGES_cur_kb=$sum_cur_kb; VMGUARPAGES_soft_mb=`echo "scale=2;$VMGUARPAGES_soft_kb / 1024" | bc` VMGUARPAGES_hard_mb=`echo "scale=2;$VMGUARPAGES_hard_kb / 1024" | bc` VMGUARPAGES_cur_mb=`echo "scale=2;$VMGUARPAGES_cur_kb / 1024" | bc` echo -n "-VMGUARPAGES: "; echo -en "\tSOFT: $VMGUARPAGES_soft_mb MB"; echo -en "\tHARD: $VMGUARPAGES_hard_mb MB"; echo -e "\tCurrent: $VMGUARPAGES_cur_mb MB";  level=`echo "scale=4;( ($PRIVVMPAGES_cur_kb*4096) + $KMEMSIZE_cur_kb + $ALLSOCKETBUF_cur_kb ) / ( $RAM_kb + swapmem_real_kb )" | bc` echo -en " Alloc Utilization: (($PRIVVMPAGES_cur_mb*4096) + $KMEMSIZE_cur_mb + $ALLSOCKETBUF_cur_mb) / ($RAM_mb + $swapmem_real_mb) \t\t=> $level Level"; st=`echo "$level < 1" | bc`; if [ $st -eq 1 ]; then echo -e "\t-- `ok`"; else echo -e "\t-- `warn '!!!'`"; incWarnings; fi level=`echo "scale=4;( $VMGUARPAGES_soft_kb + $KMEMSIZE_hard_kb + $ALLSOCKETBUF_hard_kb ) / ( $RAM_kb + swapmem_real_kb )" | bc` echo -en " Alloc Commitment: (($VMGUARPAGES_soft_kb*4096) + $KMEMSIZE_hard_mb + $ALLSOCKETBUF_hard_mb) / ($RAM_mb + $swapmem_real_mb) \t\t=> $level Level"; st=`echo "$level < 1" | bc`; if [ $st -eq 1 ]; then echo -e "\t-- `ok`"; else echo -e "\t-- `warn '!!!'`"; incWarnings; fi level=`echo "scale=4;( $PRIVVMPAGES_hard_kb + $KMEMSIZE_hard_kb + $ALLSOCKETBUF_hard_kb ) / ( $RAM_kb + swapmem_real_kb )" | bc` echo -en " Alloc limit: (($PRIVVMPAGES_hard_mb*4096) + $KMEMSIZE_hard_mb + $ALLSOCKETBUF_hard_mb) / ($RAM_mb + $swapmem_real_mb) \t\t=> $level Level"; st=`echo "$level < 1" | bc`; if [ $st -eq 1 ]; then echo -e "\t-- `ok`"; else echo -e "\t-- `warn '!!!'`"; incWarnings; fi  
}
# ------------------------------------------------------------------
# MAIN
echo " http://wiki.openvz.org/UBC_systemwide_configuration";
echo "";
echo "Harddisk check:($VZVPS_PATH)";
echo "----------------------------------------------";
checkDisk;
echo "";
echo "Memory check: (level < 1 OK100%)";
echo "----------------------------------------------";
checkMem;
 
echo "";
15
edits