Open main menu

OpenVZ Virtuozzo Containers Wiki β

Changes

Monitoring openvz resources using nagios and snmp

2,848 bytes added, 12:26, 21 December 2015
add category monitoring
#####################################################################################
if [ $RET1 -gt $RET2 ]; then
RET=$RET1
else
exit $RET
</source>
 
=== check_vzquota Without SNMP ===
<source lang="bash">
#!/bin/bash
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'"`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; fifi 
echo "$DATA" | perl -n -e'
my $vid ;
my $ret=0 ;
my $crit="";
my $warn="";
my $ok="";
while(<STDIN>){
my %vid;
$softlimit=$3 ;
$hardlimit=$4 ;
if ( $usage >= $hardlimit ){ $crit=$crit."VZquota limit exceeded on $vid: $resource usage->$usage, softlimit->$softlimit, hardlimit->$hardlimit, time->$time, expire->$expire " ; $ret=2; } elsif ( $usage >= $softlimit ){ print $warn=$warn."WARNING: VZquota limit exceeded on $vid: $resource usage->$usage, softlimit->$softlimit, hardlimit->$hardlimit, time->$time, expire->$expire " ;
$ret=1;
}
print $ok=$ok."$vid:$resource $usage/$softlimit \n";
}
}
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);
'
RET=$?
echo
exit $RET
 
</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 ===
<source lang="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
RET=0
ubc_file='/proc/user_beancounters';DATA='';if [ -r $ubc_file ]; then DATA=`cat /proc/user_beancounters$ubc_file`fiif [ -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."; exit 3;fi
if [ -f $FILE ]; then
echo "$DATA" | perl -n -e'
use Data::Dumper;
my $linked=1; # 0:plain text output, 1:resourcename is a http-link to OpenVZ-wiki
my $file=$ENV{"FILE"};
my $ret=0 ;
${beancounters{$vid}}{$resource}=[$held , $maxheld , $barrier , $limit ,$failcnt ];
if ( ($held > $barrier) && ($barrier != 0) ) {
print "WARNING: Limits on $vid: ".&url($resource ,$linked)." held->$held , barrier->$barrier ( limit->$limit ) " ;
$ret=1;
}
my $limit=$beancounters{$vmachine_id}{$resource}[3];
if ( $failcnt_old < $failcnt ){
print "CRITICAL: Incrased Increased failcnt $vmachine_id: ".url($resource ,$linked)." from $failcnt_old to $failcnt (held->$held , maxheld->$maxheld , barrier->$barrier , limit->$limit ) " ;
$ret=2;
}
}
sub url { my ($name,$with_link) = @_; 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 "\n";
exit $RET
</source>
The script needs to read the <code>/proc/user_beancounters</code> file. This is normally only readable for root. 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/local/nagios/libexec/check_ubc
 
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
 
[[Category: Monitoring]]