Re: [Mon-devel] [Mon-commit] mon/mon.d mysql-replication.monitor, NONE, 1.1
Brought to you by:
trockij
From: Augie S. <aug...@gm...> - 2007-12-01 00:47:42
|
This is just a modified mysql.monitor that checks a few vital variables to see if MySQL replication is still working; it's working well here at work. --Augie On 11/30/07, Augie Schwer <as...@us...> wrote: > 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; > } > > > ------------------------------------------------------------------------- > SF.Net email is sponsored by: The Future of Linux Business White Paper > from Novell. From the desktop to the data center, Linux is going > mainstream. Let it simplify your IT future. > http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4 > _______________________________________________ > Mon-commit mailing list > Mon...@li... > https://lists.sourceforge.net/lists/listinfo/mon-commit > -- Augie Schwer - Augie@Schwer.us - http://schwer.us Key fingerprint = 9815 AE19 AFD1 1FE7 5DEE 2AC3 CB99 2784 27B0 C072 |