Difference between revisions of "Monitoring openvz resources using nagios and snmp"
(→nagios configuration) |
|||
Line 30: | Line 30: | ||
== nagios configuration == | == nagios configuration == | ||
=== nagios plugin === | === nagios plugin === | ||
+ | It is shell script: | ||
+ | <pre> | ||
+ | # cat /usr/local/bin/check_snmp_openvz.sh | ||
+ | #!/bin/bash | ||
+ | HOST=$1 | ||
+ | PORT=$2 | ||
+ | USER=$3 | ||
+ | PASS=$4 | ||
+ | export FILE=/tmp/$HOST.beancounters | ||
+ | RET=0 | ||
+ | |||
+ | DATA=`snmpwalk -v 3 -u $USER -l authPriv -a MD5 -A $PASS -x DES -X $PASS $HOST:$PORT .1.3.6.1.4.1.2021.51.4 \ | ||
+ | | perl -ne '/"(.*)"/ ; print "$1\n" ;'` | ||
+ | |||
+ | if [ "$?" != "0" ]; then | ||
+ | echo "Unknown snmp error" | ||
+ | exit 1 | ||
+ | fi | ||
+ | |||
+ | if [ -f $FILE ]; then | ||
+ | echo "$DATA" | perl -n -e' | ||
+ | use Data::Dumper; | ||
+ | my $file=$ENV{"FILE"}; | ||
+ | my $ret=0 ; | ||
+ | my $vid ; | ||
+ | my $resource ; | ||
+ | my $held ; | ||
+ | my $maxheld ; | ||
+ | my $barrier ; | ||
+ | my $limit ; | ||
+ | my $failcnt ; | ||
+ | my %beancounters ; | ||
+ | my %beancounters_old ; | ||
+ | while(<STDIN>){ | ||
+ | my %vmachine; | ||
+ | if ( /\D*(\d+):.*/ ){ $vid=$1; $beancounters{$vid}=\%vmachine ; } | ||
+ | if ( /^[\W\d]+([a-z]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+).*/ ) { | ||
+ | $resource=$1 ; | ||
+ | $held=$2 ; | ||
+ | $maxheld=$3 ; | ||
+ | $barrier=$4 ; | ||
+ | $limit=$5 ; | ||
+ | $failcnt=$6 ; | ||
+ | ${beancounters{$vid}}{$resource}=[$held , $maxheld , $barrier , $limit ,$failcnt ]; | ||
+ | if ( ($held > $barrier) && ($barrier != 0) ) { | ||
+ | print "WARNING: Limits on $vid: $resource held->$held , barrier->$barrier ( limit->$limit ) \n" ; | ||
+ | $ret=1; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | # read and parse old data | ||
+ | open(MYINPUTFILE, "<$file"); | ||
+ | while(<MYINPUTFILE>){ | ||
+ | my %vmachine; | ||
+ | if ( /\D*(\d+):.*/ ){ $vid=$1; $beancounters_old{$vid}=\%vmachine ; } | ||
+ | if ( /^[\W\d]+([a-z]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+).*/ ) { | ||
+ | $resource=$1 ; | ||
+ | $held=$2 ; | ||
+ | $maxheld=$3 ; | ||
+ | $barrier=$4 ; | ||
+ | $limit=$5 ; | ||
+ | $failcnt=$6 ; | ||
+ | ${beancounters_old{$vid}}{$resource}=[$held , $maxheld , $barrier , $limit ,$failcnt ]; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | foreach my $vmachine_id (keys %beancounters) { | ||
+ | foreach my $resource (keys %{$beancounters{$vmachine_id}} ) { | ||
+ | if ( defined($beancounters{$vmachine_id}{$resource}[4]) && defined($beancounters_old{$vmachine_id}{$resource}[4]) ){ | ||
+ | my $failcnt=$beancounters{$vmachine_id}{$resource}[4]; | ||
+ | my $failcnt_old=$beancounters_old{$vmachine_id}{$resource}[4]; | ||
+ | my $held=$beancounters{$vmachine_id}{$resource}[0]; | ||
+ | my $maxheld=$beancounters{$vmachine_id}{$resource}[1]; | ||
+ | my $barrier=$beancounters{$vmachine_id}{$resource}[2]; | ||
+ | my $limit=$beancounters{$vmachine_id}{$resource}[3]; | ||
+ | if ( $failcnt_old < $failcnt ){ | ||
+ | print "CRITICAL: Incrased failcnt $vmachine_id: $resource from $failcnt_old to $failcnt (held->$held , maxheld->$maxheld , barrier->$barrier , limit->$limit ) \n" ; | ||
+ | $ret=2; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | if ($ret == 0 ) { print "Ok. \n" ; } | ||
+ | # print Dumper(%beancounters_old) ; | ||
+ | exit($ret); | ||
+ | ' | ||
+ | |||
+ | RET=$? | ||
+ | fi | ||
+ | |||
+ | echo "$DATA" > $FILE | ||
+ | |||
+ | exit $RET | ||
+ | </pre> |
Revision as of 07:56, 4 October 2006
snmpd configuration
Debian Etch example:
apt-get install snmpd
edit /etc/default/snmpd : remove -u snmp and repleace 127.0.0.1 witch your ip, Full/etc/default/snmpd example:
export MIBDIRS=/usr/share/snmp/mibs SNMPDRUN=yes SNMPDOPTS='-Lsd -Lf /dev/null -I -smux -p /var/run/snmpd.pid 207.46.250.119' TRAPDRUN=no TRAPDOPTS='-Lsd -p /var/run/snmptrapd.pid'
Create user(my_username) and add new mib:
/etc/init.d/snmpd stop echo rouser my_username priv > /etc/snmp/snmpd.conf echo "extend .1.3.6.1.4.1.2021.51 beancounters /bin/cat /proc/user_beancounters" >> /etc/snmp/snmpd.conf echo createUser my_username MD5 my_password DES >> /var/lib/snmp/snmpd.conf /etc/init.d/snmpd start
Testing snmp:
snmpwalk -v 3 -u my_usrname -l authPriv -a MD5 -A my_password -x DES -X my_password 207.46.250.119
nagios configuration
nagios plugin
It is shell script:
# cat /usr/local/bin/check_snmp_openvz.sh #!/bin/bash HOST=$1 PORT=$2 USER=$3 PASS=$4 export FILE=/tmp/$HOST.beancounters RET=0 DATA=`snmpwalk -v 3 -u $USER -l authPriv -a MD5 -A $PASS -x DES -X $PASS $HOST:$PORT .1.3.6.1.4.1.2021.51.4 \ | perl -ne '/"(.*)"/ ; print "$1\n" ;'` if [ "$?" != "0" ]; then echo "Unknown snmp error" exit 1 fi if [ -f $FILE ]; then echo "$DATA" | perl -n -e' use Data::Dumper; my $file=$ENV{"FILE"}; my $ret=0 ; my $vid ; my $resource ; my $held ; my $maxheld ; my $barrier ; my $limit ; my $failcnt ; my %beancounters ; my %beancounters_old ; while(<STDIN>){ my %vmachine; if ( /\D*(\d+):.*/ ){ $vid=$1; $beancounters{$vid}=\%vmachine ; } if ( /^[\W\d]+([a-z]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+).*/ ) { $resource=$1 ; $held=$2 ; $maxheld=$3 ; $barrier=$4 ; $limit=$5 ; $failcnt=$6 ; ${beancounters{$vid}}{$resource}=[$held , $maxheld , $barrier , $limit ,$failcnt ]; if ( ($held > $barrier) && ($barrier != 0) ) { print "WARNING: Limits on $vid: $resource held->$held , barrier->$barrier ( limit->$limit ) \n" ; $ret=1; } } } # read and parse old data open(MYINPUTFILE, "<$file"); while(<MYINPUTFILE>){ my %vmachine; if ( /\D*(\d+):.*/ ){ $vid=$1; $beancounters_old{$vid}=\%vmachine ; } if ( /^[\W\d]+([a-z]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+).*/ ) { $resource=$1 ; $held=$2 ; $maxheld=$3 ; $barrier=$4 ; $limit=$5 ; $failcnt=$6 ; ${beancounters_old{$vid}}{$resource}=[$held , $maxheld , $barrier , $limit ,$failcnt ]; } } foreach my $vmachine_id (keys %beancounters) { foreach my $resource (keys %{$beancounters{$vmachine_id}} ) { if ( defined($beancounters{$vmachine_id}{$resource}[4]) && defined($beancounters_old{$vmachine_id}{$resource}[4]) ){ my $failcnt=$beancounters{$vmachine_id}{$resource}[4]; my $failcnt_old=$beancounters_old{$vmachine_id}{$resource}[4]; my $held=$beancounters{$vmachine_id}{$resource}[0]; my $maxheld=$beancounters{$vmachine_id}{$resource}[1]; my $barrier=$beancounters{$vmachine_id}{$resource}[2]; my $limit=$beancounters{$vmachine_id}{$resource}[3]; if ( $failcnt_old < $failcnt ){ print "CRITICAL: Incrased failcnt $vmachine_id: $resource from $failcnt_old to $failcnt (held->$held , maxheld->$maxheld , barrier->$barrier , limit->$limit ) \n" ; $ret=2; } } } } if ($ret == 0 ) { print "Ok. \n" ; } # print Dumper(%beancounters_old) ; exit($ret); ' RET=$? fi echo "$DATA" > $FILE exit $RET