Editing Monitoring openvz resources using nagios and snmp

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 210: Line 210:
 
#####################################################################################
 
#####################################################################################
  
if [ $RET1 -gt $RET2 ]; then
+
if [ $RET1 -gt $RET2 ]; then
 
         RET=$RET1
 
         RET=$RET1
 
         else
 
         else
Line 221: Line 221:
 
exit $RET
 
exit $RET
 
</source>
 
</source>
 
 
=== check_vzquota Without SNMP ===
 
=== check_vzquota Without SNMP ===
 
<source lang="bash">
 
<source lang="bash">
 
#!/bin/bash
 
#!/bin/bash
 
RET=0
 
RET=0
DATA=`echo;sudo /usr/sbin/vzlist -1 2>/dev/null | xargs -I {} bash -c "echo {}:;sudo /usr/sbin/vzquota stat {} | sed 's/\*//g'"`
+
DATA=`echo;sudo /usr/sbin/vzlist -1 | xargs -I {} bash -c "echo {}:;sudo /usr/sbin/vzquota stat {}"`
if [ -z "$DATA" ]; then
 
        VPS_err=$(sudo /usr/sbin/vzlist -1 2>&1 1>/dev/null)
 
        if [ -n "$VPS_err" ] && [ "$VPS_err" == "Container(s) not found" ]; then
 
                echo "OK - $VPS_err";
 
                exit 0;
 
        else
 
                if [ -n "$VPS_err" ]; then
 
                        echo "UNKNOWN - Error: $VPS_err";
 
                else
 
                        echo "UNKNOWN - VZquota stats are not readable or empty. Maybe it is only readable for root and this script should be called by sudo.";
 
                fi
 
                exit 3;
 
        fi
 
fi
 
 
 
 
echo "$DATA" | perl  -n -e'
 
echo "$DATA" | perl  -n -e'
 
my $vid ;
 
my $vid ;
 
my $ret=0 ;
 
my $ret=0 ;
my $crit="";
 
my $warn="";
 
my $ok="";
 
 
while(<STDIN>){
 
while(<STDIN>){
 
         my %vid;
 
         my %vid;
Line 257: Line 238:
 
                 $softlimit=$3 ;
 
                 $softlimit=$3 ;
 
                 $hardlimit=$4 ;
 
                 $hardlimit=$4 ;
                 if ( $usage >= $hardlimit ){
+
                 if ( $usage >= $softlimit ){
                         $crit=$crit."VZquota limit exceeded on $vid: $resource  usage->$usage, softlimit->$softlimit, hardlimit->$hardlimit, time->$time, expire->$expire  " ;
+
                         print "WARNING: VZquota limit exceeded on $vid: $resource  usage->$usage, softlimit->$softlimit, hardlimit->$hardlimit, time->$time, expire->$expire  " ;
                        $ret=2;
 
                } elsif ( $usage >= $softlimit ){
 
                        $warn=$warn."VZquota limit exceeded on $vid: $resource  usage->$usage, softlimit->$softlimit, hardlimit->$hardlimit, time->$time, expire->$expire  " ;
 
 
                         $ret=1;
 
                         $ret=1;
 
                 }
 
                 }
                $ok=$ok."$vid:$resource $usage/$softlimit\n";
+
                                print "$vid:$resource $usage/$softlimit ";
 
         }
 
         }
}
 
if ($ret == 0) {
 
        print "OK - click on service-link for details...\n$ok";
 
} elsif ($ret == 1)  {
 
        print "WARNING - $warn\n";
 
} else {
 
        print "CRITICAL - $crit\n";
 
 
}
 
}
 
exit($ret);
 
exit($ret);
 
'
 
'
 
RET=$?
 
RET=$?
 +
echo
 
exit $RET
 
exit $RET
 +
 
</source>
 
</source>
The script calls <code>/usr/sbin/vzlist</code> by sudo. When doing this it normally needs a password, which check_nrpe will not know. Because of this it is necessary that you append a line like the following to <code>/etc/sudors</code> (user name an path should be adapted to the right ones on your system):
 
nagios  ALL=NOPASSWD: /usr/sbin/vzlist, /usr/sbin/vzquota
 
  
 
=== check_ubc Without SNMP ===
 
=== check_ubc Without SNMP ===
 
<source lang="bash">
 
<source lang="bash">
 
#!/bin/bash
 
#!/bin/bash
# Servicestate description can have a http-link to the openvz-wiki
 
# in case that a ressource is warning/critical. To use it:
 
# 1. set "escape_html_tags=0" in nagios/etc/cgi.cfg
 
# 2. set "my $linked=1;" in the first perl lines in this script
 
#
 
 
export FILE=/tmp/check_ubc
 
export FILE=/tmp/check_ubc
 
RET=0
 
RET=0
 +
 
ubc_file='/proc/user_beancounters';
 
ubc_file='/proc/user_beancounters';
 
DATA='';
 
DATA='';
Line 298: Line 265:
 
fi
 
fi
 
if [ -z "$DATA" ]; then
 
if [ -z "$DATA" ]; then
         echo "UNKNOWN - $ubc_file is not readable or empty. Maybe it is only readable for root and this script should be called by sudo.";
+
         echo "CRITICAL - $ubc_file is not readable or empty. Maybe it is only readable for root and this script should be called by sudo.";
 
         exit 3;
 
         exit 3;
 
fi
 
fi
Line 305: Line 272:
 
echo "$DATA" | perl  -n -e'
 
echo "$DATA" | perl  -n -e'
 
use Data::Dumper;
 
use Data::Dumper;
my $linked=1;  # 0:plain text output, 1:resourcename is a http-link to OpenVZ-wiki
 
 
my $file=$ENV{"FILE"};
 
my $file=$ENV{"FILE"};
 
my $ret=0 ;
 
my $ret=0 ;
Line 329: Line 295:
 
                 ${beancounters{$vid}}{$resource}=[$held , $maxheld , $barrier , $limit ,$failcnt ];
 
                 ${beancounters{$vid}}{$resource}=[$held , $maxheld , $barrier , $limit ,$failcnt ];
 
                 if ( ($held  > $barrier) && ($barrier != 0) ) {
 
                 if ( ($held  > $barrier) && ($barrier != 0) ) {
                         print "WARNING: Limits on $vid: ".&url($resource,$linked)." held->$held , barrier->$barrier ( limit->$limit ) " ;
+
                         print "WARNING: Limits on $vid: $resource  held->$held , barrier->$barrier ( limit->$limit ) " ;
 
                         $ret=1;
 
                         $ret=1;
 
                 }
 
                 }
Line 362: Line 328:
 
                         my $limit=$beancounters{$vmachine_id}{$resource}[3];
 
                         my $limit=$beancounters{$vmachine_id}{$resource}[3];
 
                         if ( $failcnt_old < $failcnt ){
 
                         if ( $failcnt_old < $failcnt ){
                                 print "CRITICAL: Increased failcnt  $vmachine_id: ".url($resource,$linked)." from $failcnt_old to $failcnt (held->$held , maxheld->$maxheld , barrier->$barrier , limit->$limit ) " ;
+
                                 print "CRITICAL: Incrased failcnt  $vmachine_id: $resource from $failcnt_old to $failcnt (held->$held , maxheld->$maxheld , barrier->$barrier , limit->$limit ) " ;
 
                                 $ret=2;
 
                                 $ret=2;
 
                         }
 
                         }
Line 370: Line 336:
  
 
}
 
}
sub url {
+
 
        my ($name,$with_link) = @_;
+
if ($ret == 0 ) { print "OK. \n" ; }
        if ($with_link) {
 
                return "<a target=\"_blank\" href=\"http://wiki.openvz.org/".$name."#".$name."\">$name</a>";
 
        } else {
 
                return $name;
 
        }
 
}
 
if ($ret == 0 ) { print "OK: All bean counters fine \n" ; }
 
 
# print Dumper(%beancounters_old) ;
 
# print Dumper(%beancounters_old) ;
 
# print "\n";
 
# print "\n";
Line 395: Line 354:
 
Also don't forget to consider this on your <code>nrpe.cfg</code>, so that you call the script with sudo:
 
Also don't forget to consider this on your <code>nrpe.cfg</code>, so that you call the script with sudo:
 
  command[check_ubc]=sudo /usr/local/nagios/libexec/check_ubc
 
  command[check_ubc]=sudo /usr/local/nagios/libexec/check_ubc
 
[[Category: Monitoring]]
 

Please note that all contributions to OpenVZ Virtuozzo Containers Wiki may be edited, altered, or removed by other contributors. If you don't want your writing to be edited mercilessly, then don't submit it here.
If you are going to add external links to an article, read the External links policy first!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)