Changes

Jump to: navigation, search

Setting UBC parameters

376 bytes added, 22:58, 9 July 2010
Are you aware of a script that would run as a cron job and do the OOM math on a regular basis and email me if I've hit the red zone or maybe at 85-90%?
#!/bin/bash
# Openvz Containers Memory Status
# Version 0.68
# Reference: http://wiki.openvz.org/Setting_UBC_parameters
# Advantagesor changes:
# 1) Calculation of vz containers.
# 2) Percentage Calculation.
# 3) Avoid a char simples wrong characters and offset out of range entry.# 4) Use the same same order of vzlist output.
# The usage of this script is easy.
case $# in
1)
# We get Get the container to be calculated vmvm_param=$1 
# Just avoiding our human error
datachk=`echo $vm vm_param | grep -e [a-z] | wc -l`
if let "datachk>0";then
echo "That's not a valid number!"
exit
fi
  # Avoiding another mistake maybe we the user forgot the quantity of our containersvm allocated if let "vmvm_param>n";then
echo "Container out of range, please try a number between 1 and "$n
exit
fi
  # Calculating lines Take the real position of the container to be jump get from the output of user_bancounters.vzlist # Becuase there is a for avoiding the first garbage line i need 26 spaces we add one line more, this mean that id # will be taken from the 2nd line ahead let $vm "vm=vm_param+1"  # beginning, then i need Uncomment this and comment the line above if you want to show switch the last 24.order # let $vm "vm=(n-vmvm_param) because i do not want to see it bacward if you want to change +2"  # Take the id from thevzlist output id_vm=`vzlist | head -$vm | tail -1|awk '{print $1}'`  # order switch Get the comment with line where is located the following linevm to be calculated val=`grep -n $id_vm /proc/user_beancounters | awk -F:'{print $1}'`  # let $val "val=26+(24*vm)"Adding the 23 block where the info is located let $val "val=2623+(24*(n-vm)val)"
# If you want to see all values of the vm uncomment this
#head -$val /proc/user_beancounters | tail -24
# The math start here.
oomguarpages_barrier=`head -$val /proc/user_beancounters | tail -24 | head -9 | tail -1 | awk '{print $4}'`
# We Three current values need to calculate three current valuesbe calculated:
# oomguarpages current value (MEM+SWAP actual usage)
# socket buffers current value
let $resp "resp=((oomguarpages*4096)+tcpsndbuf+tcprcvbuf+othersockbuf+dgramrcvbuf+kmemsize)"
# We need to calculate Calculating the oom Barrier
let $oom "oom=(oomguarpages_barrier*4096)"
 
# Getting the percentage of the output
let $porc "porc=(resp*100)/oom"
# We show Showing the container ID and Percentageof the container
echo `head -$val /proc/user_beancounters | tail -24| head -1 | awk -F: '{print $1}'`" Status: "$porc"%"
  # We show Showing the two important values.
echo -e "System Count:\t-\tOOM Barrier:"
echo -e $resp"\t-\t"$oom
# Uncoment this if you just want to now if it is below to barrier
# it means is healthy if resp is less than oom
# if let "resp<oom";then
Anonymous user

Navigation menu