Warning: Cannot modify header information - headers already sent by (output started at /home/destefa1/public_html/nf/function.php:1) in /home/destefa1/public_html/nf/function.php on line 215

Warning: Cannot modify header information - headers already sent by (output started at /home/destefa1/public_html/nf/function.php:1) in /home/destefa1/public_html/nf/function.php on line 216

Warning: Cannot modify header information - headers already sent by (output started at /home/destefa1/public_html/nf/function.php:1) in /home/destefa1/public_html/nf/function.php on line 217

Warning: Cannot modify header information - headers already sent by (output started at /home/destefa1/public_html/nf/function.php:1) in /home/destefa1/public_html/nf/function.php on line 218

Warning: Cannot modify header information - headers already sent by (output started at /home/destefa1/public_html/nf/function.php:1) in /home/destefa1/public_html/nf/function.php on line 219

Warning: Cannot modify header information - headers already sent by (output started at /home/destefa1/public_html/nf/function.php:1) in /home/destefa1/public_html/nf/function.php on line 220
#!/usr/bin/perl # Copyright (c) 2012 Jason Hancock # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is furnished # to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # This file is part of the nagios-mysql bundle that can be found # at https://github.com/jasonhancock/nagios-mysql # # This plugin reports on mysql's command counters as reported by the # 'SHOW GLOBAL STATUS' command. use strict; use warnings; use Nagios::Plugin; use DBI; my $np = Nagios::Plugin->new( usage => "Usage: %s [-H|--host= ] [ -t|--type= ]", shortname => 'MySQL Command Counters', ); $np->add_arg( spec => 'host|H=s', help => '-H, --host=hostname or IP', required => 1, ); $np->add_arg( spec => 'port|P=s', help => '-P, --port=port', default => 3306, ); $np->add_arg( spec => 'user|u=s', help => '-u, --user=username', required => 1, ); $np->add_arg( spec => 'pass|p=s', help => '-p, --pass=password', required => 1, ); $np->getopts; my @keys = ( 'select', 'insert', 'update', 'delete', 'replace', 'load', 'deletemulti', 'insertselect', 'updatemulti', 'replaceselect', ); my %interests = ( 'Com_select' => 'select', 'Com_insert' => 'insert', 'Com_update' => 'update', 'Com_delete' => 'delete', 'Com_replace' => 'replace', 'Com_load' => 'load', 'Com_delete_multi' => 'deletemulti', 'Com_insert_select' => 'insertselect', 'Com_update_multi' => 'updatemulti', 'Com_replace_select' => 'replaceselect', ); my %data; # Connect to the database my $ds = sprintf('DBI:mysql::%s:%d', $np->opts->host, $np->opts->port); my $dbh = DBI->connect($ds, $np->opts->user, $np->opts->pass, { PrintError => 0 }) or $np->nagios_exit('UNKNOWN', 'Unable to connect to database'); # Run the query my $qh = $dbh->prepare('SHOW GLOBAL STATUS LIKE \'Com_%\'') or $np->nagios_exit('UNKNOWN', 'UNABLE to prepare query'); $qh->execute(); while(my ($name, $value) = $qh->fetchrow_array()) { $data{$interests{$name}} = $value if defined($interests{$name}); } $qh->finish(); $dbh->disconnect(); foreach my $key(@keys) { $np->add_perfdata( label => $key, value => $data{$key}, uom => undef, ); } $np->nagios_exit('OK', '');