Knowing if you adjusted your user beancounters in OpenVZ right can be quite difficult. The OpenVZ wiki has a great article about the systemwide UBC configuration but I takes a bit of effort to calculate all of them, and over again when you’ve adjusted them. So I made a simple script that checks the systemwide UBC parameters of all running containers (VPS). You can find detailed information about the results in article; http://wiki.openvz.org/UBC_systemwide_configuration
If you need any help or think that something is wrong with the script please drop a line in the comments. Thank you!
This script has to be run on the hardwarenode itself.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
#!/bin/bash # # Script to display UBC systemwide configuration as explained in article; http://wiki.openvz.org/UBC_systemwide_configuration # # Written by ezeyme.com # # Script is as it is. No warranty given. declare -A ubc_parm_current declare -A ubc_parm_barrier declare -A ubc_parm_limit # Get system memory tmem=`cat /proc/meminfo |grep MemTotal|awk '{print $2}'` # Total System Memory #echo "tmem: "$tmem tswap=`cat /proc/meminfo |grep SwapTotal|awk '{print $2}'` # Total Swap #echo "tswap: "$tswap # Calculate normal system memory utilization let tmem_plus_swap=tmem+tswap #echo "tmem_plus_swap: "$tmem_plus_swap minmem_util=$(echo 'scale=4; '$tmem'/'$tmem_plus_swap | bc) # Ram Size/Ramsize + swap size let htswap=tswap/2 # 1/2 swap size #echo "htswap: "$htswap let tmem_plus_htswap=tmem+htswap #echo "tmem_plus_htswap: "$tmem_plus_htswap maxmem_util=$(echo 'scale=4; '$tmem_plus_htswap'/'$tmem_plus_swap | bc) # Ram Size + 1/2 swap size/Ram Size + swap size echo "Minimum memory utilization: "$minmem_util echo "Maximum memory utilization: "$maxmem_util # Get counters from running VPS's ubc=(kmemsize privvmpages physpages vmguarpages oomguarpages tcpsndbuf tcprcvbuf othersockbuf dgramrcvbuf) for veid in `vzlist -o veid -H`; do echo echo -n "VEID: "$veid vzctl exec $veid cat /proc/user_beancounters > output.tmp for i in ${ubc[@]}; do if [[ $i == "kmemsize" ]]; then ubc_parm_current[$i]=`cat output.tmp | grep $i | awk '{print $3}'` ubc_parm_barrier[$i]=`cat output.tmp | grep $i | awk '{print $5}'` ubc_parm_limit[$i]=`cat output.tmp | grep $i | awk '{print $6}'` else ubc_parm_current[$i]=`cat output.tmp | grep $i | awk '{print $2}'` ubc_parm_barrier[$i]=`cat output.tmp | grep $i | awk '{print $4}'` ubc_parm_limit[$i]=`cat output.tmp | grep $i | awk '{print $5}'` fi echo -n "." done let oomguard_tot_current=oomguard_tot_current+${ubc_parm_current['oomguarpages']} let oomguard_tot_barrier=oomguard_tot_barrier+${ubc_parm_barrier['oomguarpages']} let privvm_tot_current=privvm_tot_current+${ubc_parm_current['privvmpages']} let vmguar_tot_barrier=vmguar_tot_barrier+${ubc_parm_barrier['vmguarpages']} let privvm_tot_limit=privvm_tot_limit+${ubc_parm_limit['privvmpages']} let kmemsize_tot_current=kmemsize_tot_current+${ubc_parm_current['kmemsize']} let kmemsize_tot_limit=kmemsize_tot_limit+${ubc_parm_limit['kmemsize']} let allsocketbuf_tot_current=allsocketbuf_tot_current+${ubc_parm_current['tcpsndbuf']}+${ubc_parm_current['tcprcvbuf']}+${ubc_parm_current['othersockbuf']}+${ubc_parm_current['dgramrcvbuf']} let allsocketbuf_tot_limit=allsocketbuf_tot_limit+${ubc_parm_limit['tcpsndbuf']}+${ubc_parm_limit['tcprcvbuf']}+${ubc_parm_limit['othersockbuf']}+${ubc_parm_limit['dgramrcvbuf']} done let oomguard_util=oomguard_tot_current*4096 let oomguard_util=oomguard_util+kmemsize_tot_current+allsocketbuf_tot_current let oomguard_commit=oomguard_tot_barrier*4096 let oomguard_commit=oomguard_commit+kmemsize_tot_current+allsocketbuf_tot_current let privv_util=privv_tot_current*4096 let privv_util=privv_util+kmemsize_tot_current+allsocketbuf_tot_current let privv_limit=privv_tot_limit*4096 let privv_limit=privv_limit+kmemsize_tot_limit+allsocketbuf_tot_limit let vmguar_commit=vmguar_tot_barrier*4096 let vmguar_commit=vmguar_commit+kmemsize_tot_current+allsocketbuf_tot_current let tmem=tmem*1024 let tswap=tswap*1024 let memtotal=tmem+tswap echo echo -n "Oomguardpages utilization: "; echo 'scale=4; '$oomguard_util' / '$memtotal | bc echo echo -n "Oomguardpages commitment : "; echo 'scale=4; '$oomguard_commit' / '$memtotal | bc echo echo -n "Privvmpages utilization : "; echo 'scale=4; '$privv_util' / '$memtotal | bc echo echo -n "Vmguapages commitment : "; echo 'scale=4; '$vmguar_commit' / '$memtotal | bc echo echo -n "Privvmpages limitation : "; echo 'scale=4; '$privv_limit' / '$memtotal | bc |
Interesting work.
Don’t you want to github it and start promoting it — as a tool for people to get their head around the UBC parameters?