rendered paste body#!/bin/bash# released 11 Nov 2006 by grummund and yager on irc.chatspike.net#RapidVPS# this util expects to receive /proc/user_beancounters via stdin# unprivileged users may use beanc.c from http://www.labradordata.ca/home/35# primary reference: http://wiki.openvz.org/Proc/user_beancounters# also http://forum.swsoft.com/showthread.php?s=d03fd7e49b67dfb1f45f4f453e019a73&threadid=26770## Output option defaults to everything except explanations:option_date=y; option_datehost=y; option_uptime=yoption_limits=y; option_usage=yoption_memory=y; option_kernel=yoption_others=y; option_failcnts=yoption_demarcations=y; option_explanations=noption_help=y; option_veid=yexp0="******" # around the explanation text## Array field constants:param_name=0; held=1; maxheld=2; barrier=3; limit=4; failcnt=5declare -a FailCountsFailCounts[0]=0fails=0demarcate () { echo '-----------------------------------------------'}read_params () { case $# in 2) UBC_version="$2"; return;; 7) UBC_veid="${1%:}"; shift;; 6) ;; *) return 1;; esac PARAM=$1 let UBC_$PARAM[1]=$2 let UBC_$PARAM[2]=$3 let UBC_$PARAM[3]=$4 let UBC_$PARAM[4]=$5 let UBC_$PARAM[5]=$6# eval echo "debug: $PARAM= \${UBC_$PARAM[@]}" let fails=UBC_$PARAM[5] if [ $fails -gt 0 ] && [ $6 != "failcnt" ] then let "FailCounts[0] += 1" FailCounts[${FailCounts[0]}]="$*" fi}## A couple handy functions:Return_Val= # Global variable to hold oversize return value of function.kilos () { Return_Val=$(($1 / 1024)) return }megas () { kilos $1# Return_Val=$(($Return_Val / 1024)) let "Return_Val /= 1024" return }print_bytes () { if [ "$2" -gt 1048576 ]; then printf "$1" "$(($2 / 1048576))" "MB" elif [ "$2" -gt 1024 ]; then printf "$1" "$(($2 / 1024))" "KB" else printf "$1" "$2" "B" fi}## parse the command line arguments:for arg in $@; do case ${arg:0:1} in +) option_state=y;; -) option_state=n;; esac char=1 while [ $char -lt ${#arg} ] ; do case ${arg:$char:1} in v) option_veid=$option_state;; i) option_datehost=$option_state;; s) option_uptime=$option_state;; l) option_limits=$option_state;; u) option_usage=$option_state;; m) option_memory=$option_state;; k) option_kernel=$option_state;; o) option_others=$option_state;; f) option_failcnts=$option_state;; d) option_demarcations=$option_state;; e) option_explanations=$option_state;; H) option_veid=$option_state option_datehost=$option_state option_uptime=$option_state;; a) option_datehost=$option_state option_uptime=$option_state option_limits=$option_state option_usage=$option_state option_memory=$option_state option_kernel=$option_state option_others=$option_state option_failcnts=$option_state option_demarcations=$option_state option_explanations=$option_state option_veid=$option_state esac char=$[$char+1] done # while case $arg in -h|+h|--h|--help) cat <<EOFUsage: $0 [(+|-)(option)[option]...] ...][+|-] turns output options on or off$0 reads (requires) the contents of /proc/user_beancounters on stdinOptions, processed sequentially, default to On except explanations a) for all options (use first) d) demarcation lines ------H) Header Elements: v) VEID i) ID : date and hostname s) status : uptimeBeanCounters: l) limits set by host u) usage by VE m) memory pages k) kernel (low) memory o) other, non-memory, parameters f) fail countsInformational: e) explanationsEOF exit;; esacdone ## Read the UBC data:while read LINE; do# printf "."# echo "debug: LINE=\"$LINE\"" read_params $LINEdone#printf "\r"## Output whatever interests you:[ $option_demarcations = y ] && demarcate[ $option_veid = y ] && echo "Processing UBC version $UBC_version for VEID: $UBC_veid"[ $option_datehost = y ] && echo `date` " " `hostname`[ $option_uptime = y ] && echo `uptime`if [ $option_memory = y ] ; then [ $option_demarcations = y ] && demarcate if [ $option_limits = y ] ; then [ $option_explanations = y ] && echo "$exp0 vmguarpages and oomguarpages limits are unspecified" [ $option_explanations = y ] && echo "$exp0 each VE privvmpages limit should be <= 0.6 * RAM (=1228 MB), probably [much] lower." printf "%4d MB Allocation Limit [privvmpages limit]\n" $((${UBC_privvmpages[limit]} / 256)) [ $option_explanations = y ] && echo "$exp0 only high value processes have a chance in this range" [ $option_explanations = y ] && echo "$exp0 having this safety range is important to permit critical processes" printf "%4d MB Allocation Barrier [privvmpages barrier]\n" $((${UBC_privvmpages[barrier]} / 256)) [ $option_explanations = y ] && echo "$exp0 allocation requests in this range have a chance" printf "%4d MB Allocation Guarantee [vmguarpages barrier]\n" $((${UBC_vmguarpages[barrier]} / 256)) [ $option_explanations = y ] && echo "$exp0 allocation will succeed in this range" printf "%4d MB Memory Guarantee [oomguarpages barrier]\n" $((${UBC_oomguarpages[barrier]} / 256)) fi # limits if [ $option_usage = y ] ; then printf "%4d MB" $((${UBC_privvmpages[held]} / 256)) printf " (%4d MB Max) page memory allocated [privvmpages held]\n" $((${UBC_privvmpages[$maxheld]} / 256)) printf "%4d MB" $((${UBC_oomguarpages[held]} / 256)) printf " (%4d MB Max) memory + swap used [oomguarpages held]\n" $((${UBC_oomguarpages[$maxheld]} / 256)) printf "%4d MB" $((${UBC_physpages[held]} / 256)) printf " (%4d MB Max) page memory used [physpages held]\n" $((${UBC_physpages[$maxheld]} / 256)) fi # usagefi # memory#[ $option_explanations = y ] && echo "$exp0 host system swap size should be double the physical RAM size"if [ $option_kernel = y ] ; then if [ $option_limits = y ] ; thenmegas ${UBC_kmemsize[$limit]} printf "%4d MB kernel memory limit [kmemsize limit]" $Return_Val kilos ${UBC_kmemsize[$limit]} printf "(%6d KB)\n" $Return_Val [ $option_explanations = y ] && echo "$exp0 a safety range here, between limit and barrier, is important"megas ${UBC_kmemsize[barrier]} printf "%4d MB kernel memory barrier [kmemsize barrier]" $Return_Val kilos ${UBC_kmemsize[barrier]} printf "(%6d KB)\n" $Return_Val fi # limits if [ $option_usage = y ] ; thenBUFMEM=$((${UBC_tcpsndbuf[held]} + ${UBC_tcprcvbuf[held]} + ${UBC_othersockbuf[held]} + ${UBC_dgramrcvbuf[held]}))# print_bytes "%4d %s kernel memory used [kmemsize held]\n" ${UBC_kmemsize[held]}# print_bytes "%4d %s buffer memory used [*buf held]\n" $BUFMEMmegas ${UBC_kmemsize[$held]} printf "%4d MB kernel memory used [kmemsize held]" $Return_Val kilos ${UBC_kmemsize[$held]} printf "(%6d KB)\n" $Return_Val megas $BUFMEMprintf "%4d MB buffer memory used [*buf held]" $Return_Valkilos $BUFMEMprintf "(%6d KB)\n" $Return_Val fi # usagefi #kernelif [ $option_others = y ] ; then[ $option_demarcations = y ] && demarcateecho ' Used : Max_Used : Limit for Other Resources'#for X in numpty numproc numfile numflock numtcpsock numothersock numiptent numsiginfo; do# eval printf '"%6d %6d %6d %s\n"' "\${UBC_$X[held]}" "\${UBC_$X[maxheld]}" "\${UBC_$X[limit]} $X"#donefor X in "${!UBC_num@}"; do eval printf '"%6d %6d %6d %s\n"' "\${$X[held]}" "\${$X[maxheld]}" "\${$X[limit]} ${X#*_}"donefi # otherif [ $option_failcnts = y ] ; then[ $option_demarcations = y ] && demarcate# look at failcnts ....# declare -p FailCountsecho "Fail Count conditions: ${FailCounts[0]}"if [ ${FailCounts[0]} -gt 0 ] then for i in ${FailCounts[0]} do echo ${FailCounts[$i]} done; fifi # failcnts exit 0