1
edit
Changes
→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 1.5
# Reference: http://wiki.openvz.org/Setting_UBC_parameters
# The script program is placed under the GNU Public License (GPL)
# Author: Roberto Blandino Cisneros.
# Under any change or develop please notify me to# rojoblandino @(at)yahoo.com
# Advantages or changes:
# First thing to do is to get the list of containers
vzn=`$(($(vzlist | wc -l`# Save the output into a var and erase the first# garbage line by subtracting 1.let $n "n=vzn)-1"))
case $# in
# Just avoiding our human error
datachk=`$(echo $vm_param | grep -e [a-z] | wc -l`)
if let "datachk>0";then
exit
fi
# Avoiding another mistake maybe the user forgot the quantity of vm allocated
if let "vm_param>nvzn";then echo printf "Container out of range, please try a number between 1 and %d\n" "$nvzn"
exit
elif let "vm_param==0";then
exit
fi
# Uncomment this and comment the line above if you want to switch the order
#let $vm "vm=(n-vm_param)+2"
# Take the id from the vzlist output
id_vm=`$(vzlist | head -$vm | tail -1|awk '{print $1}'`)
# Get the line where is located the vm to be calculated
val=`$(grep -n $id_vm /proc/user_beancounters | awk -F: '{print $1}'`)
# Adding the 23 block where the info is located
# you must read carefully the page http://wiki.openvz.org/Setting_UBC_parameters
# the only thing i do was to get the values explained already there.
kmemsize=`$(head -$val /proc/user_beancounters | tail -24 | head -1 | tail -1 | awk '{print $3}'`) oomguarpages=`$(head -$val /proc/user_beancounters | tail -24 | head -9 | tail -1 | awk '{print $2}'`) tcpsndbuf=`$(head -$val /proc/user_beancounters | tail -24 | head -14 | tail -1 | awk '{print $2}'`) tcprcvbuf=`$(head -$val /proc/user_beancounters | tail -24 | head -15 | tail -1 | awk '{print $2}'`) othersockbuf=`$(head -$val /proc/user_beancounters | tail -24 | head -16 | tail -1 | awk '{print $2}'`) dgramrcvbuf=`$(head -$val /proc/user_beancounters | tail -24 | head -17 | tail -1 | awk '{print $2}'`) oomguarpages_barrier=`$(head -$val /proc/user_beancounters | tail -24 | head -9 | tail -1 | awk '{print $4}'`)
# Three current values need to be calculated:
# Showing the ID and Percentage of the container
#echo `$(head -$val /proc/user_beancounters | tail -24| head -1 | awk -F: '{print $1}'`)" Status: "$porc"%" printf "%s Status: %d %%\n" "$(head -$val /proc/user_beancounters | tail -24| head -1 | awk -F: '{print $1}' | sed "s/^\ *//g")" "$porc"
# Showing the two important values.
# Uncoment this if you just want to now if it is below to barrier
# it means is healthy if resp is less than oom