diff --git a/libexec/check_mysql_performance b/libexec/check_mysql_performance index 9a7e0a5..0e59d35 100755 --- a/libexec/check_mysql_performance +++ b/libexec/check_mysql_performance @@ -11,9 +11,9 @@ use Nagios::Plugin; my $np = Nagios::Plugin->new( 'usage' => < '1.00', + 'version' => '1.10', 'url' => 'http://www.capside.com', 'extra' => < qq{Copyright (c) CAPSiDE. - -This plugin montitors the % use of CPU usage on Linux systems for various types of CPU usage. EOH ); $np->add_arg( spec => 'perfdata=s', help => < 0, ); @@ -108,7 +107,8 @@ $SIG{'ALRM'} = sub { $np->nagios_exit( CRITICAL, 'ERROR: Timed out.' ); }; -my ( $code, $message ) = ( OK, 'All parameters OK' ); +my ( $code, $message ) = ( undef, undef ); +$np->add_message( OK, "All parameters OK" ); my @fields; if ( not $np->opts->perfdata ) { @@ -116,30 +116,50 @@ if ( not $np->opts->perfdata ) { } else { @fields = split( /,/, $np->opts->perfdata ); - - # @fields = split /,/, join ',', @{$np->opts->perfdata}; } # Add all performance data +my $thresholds; +my $value; +my $warning; +my $critical; +my $minimum; +my $maximum; foreach my $key (@fields) { + if ( $key =~ /=/ ) { + ($key, $thresholds) = split( /=/, $key ); + ($warning, $critical) = split ( /;/, $thresholds ); + } else { + $thresholds = undef; + $warning = undef; + $critical = undef; + } if ( $mysql->{'stats'}->{$key}->{'type'} eq 'ABS' ) { next if ( not defined $read_data->{$key} ); - $np->add_perfdata( - 'label' => $key, - 'value' => $read_data->{$key}, - 'uom' => '', - ); - } - elsif ( $mysql->{'stats'}->{$key}->{'type'} eq 'DERIVE' ) { + $value = $read_data->{$key}; + } elsif ( $mysql->{'stats'}->{$key}->{'type'} eq 'DERIVE' ) { next if ( not defined $stat->{$key} ); - $np->add_perfdata( - 'label' => $key, - 'value' => $stat->{$key}, - 'uom' => '', + $value = $stat->{$key}; + } + $np->add_perfdata( + 'label' => $key, + 'value' => $value, + 'uom' => '', + 'warning' => $warning, + 'critical' => $critical, + ); + if ( $thresholds ) { + $code = $np->check_threshold( + 'check' => $value, + 'warning' => $warning, + 'critical' => $critical, ); + if ( $code ) { + $np->add_message($code, "$key beyond thresholds,"); + } } } - +($code, $message) = $np->check_messages(); $np->nagios_exit( $code, $message ); package MySQL::Stats;