rendered paste body#!/bin/bash
echo "Usage: this util expects to receive /proc/user_beancounters via command line pipe."
## Array field constants:
param_name=0; held=1; maxheld=2; barrier=3; limit=4; failcnt=5
read_params () {
case $# in
2) UBC_version="$2"; return;;
7) UBC_veid="${1%:}"; shift;;
6) ;;
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[@]}"
}
## 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))
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
}
## Read the UBC data:
while read LINE; do
# printf "."
# echo "debug: LINE=\"$LINE\""
read_params $LINE
done
#printf "\r"
## Output whatever interests you:
echo "Processing UBC version $UBC_version for VEID: $UBC_veid"
printf "%4d MB Allocation Guarantee [vmguarpages barrier]\n" $((${UBC_vmguarpages[barrier]} / 256))
printf "%4d MB Memory Guarantee [oomguarpages barrier]\n" $((${UBC_oomguarpages[barrier]} / 256))
printf "%4d MB page memory allocated [privvmpages held]\n" $((${UBC_privvmpages[held]} / 256))
printf "%4d MB page memory used [physpages held]\n" $((${UBC_physpages[held]} / 256))
printf "%4d MB memory + swap used [oomguarpages held]\n" $((${UBC_oomguarpages[held]} / 256))
print_bytes "%4d %s kernel memory used [kmemsize held]\n" ${UBC_kmemsize[held]}
BUFMEM=$((${UBC_tcpsndbuf[held]} + ${UBC_tcprcvbuf[held]} + ${UBC_othersockbuf[held]} + ${UBC_dgramrcvbuf[held]}))
print_bytes "%4d %s buffer memory used [*buf held]\n" $BUFMEM
echo '-----------------------------------------------'
echo ' 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"
#done
for X in "${!UBC_num@}"; do
eval printf '"%6d %6d %6d %s\n"' "\${$X[held]}" "\${$X[maxheld]}" "\${$X[limit]} ${X#*_}"
done
echo '-----------------------------------------------'
# look at failcnts ....
exit 0