[Mon-commit] mon/mon.d mysql-replication.monitor,NONE,1.1
Brought to you by:
trockij
From: Augie S. <as...@us...> - 2007-12-01 00:28:17
|
Update of /cvsroot/mon/mon/mon.d In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv14856 Added Files: mysql-replication.monitor Log Message: Adding mysql-replication.monitor . --- NEW FILE: mysql-replication.monitor --- #!/usr/bin/perl # arguments: # [ --username=username --password=password --port=# ] hostname(s) use DBI; use Getopt::Long; my @details=(); my @failures=(); GetOptions( \%options, "port=i", "username=s", "password=s" , "seconds=i" ); # uncomment these two lines and provide suitable information if you don't # want to pass sensitive information on the command line $options{username} ||= "repl-check"; $options{password} ||= "m449kwf"; $options{port} ||= 3306; $options{seconds} ||= 3600; for $host( @ARGV ) { my( $dbh ) = DBI->connect( "DBI:mysql:host=$host:port=$options{port}", $options{username}, $options{password}, { PrintError => 0 } ); if( ! $dbh ) { push( @failures, $host); push( @details, "$host: Could not connect to MySQL server on $options{port}: " . $DBI::errstr . "\n"); next; } # Gather vital replication information. my $sth = $dbh->prepare('SHOW SLAVE STATUS'); $sth->execute; my $slave = $sth->fetchrow_hashref; $sth->finish; # Check those variables. if ( $slave->{Slave_IO_Running} ne 'Yes' ) { push( @failures, $host); push( @details, "$host: Slave IO thread is not running.\n"); next; } if ( $slave->{Slave_SQL_Running} ne 'Yes' ) { push( @failures, $host); push( @details, "$host: Slave SQL thread is not running.\n"); next; } if ( $slave->{Seconds_Behind_Master} > $options{seconds} ) { push( @failures, $host); push( @details, "$host: Slave is more than " . $options{seconds} . " seconds behind master.\n"); next; } $dbh->disconnect(); } if (@failures) { print join (" ", sort @failures), "\n"; print sort @details if (scalar @details > 0); exit 1; } else { exit 0; } |