Home > Openvz and Virtuozzo, Scripts > Script to check failcnt in /proc/user_beancounters of all vps

Script to check failcnt in /proc/user_beancounters of all vps

In openvz and virtuozzo vps nodes, sometimes resource overconsumption can result in unexpected behaviour with the vps node. The resource which is over-utilised will be mentioned in “/proc/user_beancounters”. The following script will help the one who manages the main hardware node to find out all the vps nodes for which resource failures are reported, and can proactive actions based on the output.

This script needs to be executed from the main hardware node.

#!/bin/bash
# Create AWK rules and save it in /root/checkresource.awk
# Filename: /root/vpsresourcecheck.sh


########################
### Func: checkall
### No of Arguments = 0
########################
function checkall {

   flag=0

   #Create a file containing awk rules
   echo -e "{\nif(NF==7 && match(\$1,\"[0-9]+:\") && \$NF!=0 )\nprint \$2;\nelse if(NF==6 && \$NF!=0)\nprint \$1;\n}" > /root/checkresource.awk

   # Check "/proc/user_beancounters" of all vps nodes and print the CTID of ones with failcnt
   #
   for i in $(vzlist -o ctid|grep -v CTID|awk '{print $1}')
   do
     vzctl exec ${i} cat /proc/user_beancounters > ~/tmp.txt
     if [ `awk -f /root/checkresource.awk ~/tmp.txt|wc -l` -gt 0 ];then
        echo "Resource over-usage in CTID: ${i}"
        flag=1
     else
        echo "CTID: ${i} is GOOD"
     fi
   done

   if [ $flag -eq 0 ];then
     echo -e "\nNo failcnt reported for any of the nodes; everything is good:)\n"
   fi

}

########################
### Func: reportfailcnt
### No of arguments = 1
########################
function reportfailcnt {
    # Called only from inside function checkvps 
    # Contain only one argument and its the CTID
      echo -e "{\nif(NF==7 && match(\$1,\"[0-9]+:\") && \$NF!=0 )\nprint \$2\":\"\$NF;\nelse if(NF==6 && \$NF!=0)\nprint \$1\":\"\$NF;\n}" > /root/checkresource.awk
      
      vzctl exec $1 cat /proc/user_beancounters > ~/tmp.txt
     
    # List out the resource name and the failcnt
      awk -f /root/checkresource.awk ~/tmp.txt
}

########################
### Func: checkvps
### No of arguments = 1
########################
function checkvps {
   # Contain only one argument and its the CTID
   echo -e "{\nif(NF==7 && match(\$1,\"[0-9]+:\") && \$NF!=0 )\nprint \$2;\nelse if(NF==6 && \$NF!=0)\nprint \$1;\n}" > /root/checkresource.awk

   vzctl exec $1 cat /proc/user_beancounters > ~/tmp.txt

   if [ `awk -f /root/checkresource.awk ~/tmp.txt|wc -l` -gt 0 ];then
     echo -e "\n\nRESOURCE OVERUTILIZATION REPORTED FOR CTID: $1 \n"
     echo -e "\n++++++++++++++++++++++\nRESOURCE : FAILCNT\n+++++++++++++++++++++"
     reportfailcnt $1
     echo -e "++++++++++++++++++++++++"
     exit 1
   else
     echo -e "\nNo failure count reported for CTID: $1\n Everything is good:)\n" 
   fi

} 



########################
### Main section
########################

case "$1" in 
      checkall) 
          checkall
          ;;
      checkvps)
           # One argument required
            if [ $# -ne 2 ];then
             echo "Usage: /root/vpsresourcecheck.sh checkvps <CTID>"
             exit 1
            fi
 
           checkvps $2 
          ;;
      *)
       echo "Usage: /root/vpsresourcecheck.sh {checkvps <CTID>|checkall}"
       exit 1
esac


SAMPLE OUTPUT

[root@vz ~]# /root/vpsresourcecheck.sh checkall
CTID: 1 is GOOD
Resource over-usage in CTID: 1040
CTID: 1439 is GOOD
Resource over-usage in CTID: 4603
Resource over-usage in CTID: 5243
Resource over-usage in CTID: 5605
CTID: 5850 is GOOD
Resource over-usage in CTID: 8999
[root@vz ~]#

[root@vz ~]# /root/vpsresourcecheck.sh checkvps 8999

RESOURCE OVERUTILIZATION REPORTED FOR CTID: 8999

++++++++++++++++++++++
RESOURCE : FAILCNT
+++++++++++++++++++++
kmemsize:35
privvmpages:62
++++++++++++++++++++++++
[root@vz ~]# /root/vpsresourcecheck.sh checkvps 1

No failure count reported for CTID: 1
Everything is good:)

[root@vz ~]#

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: