2009-09-15 00:24:24 +00:00
|
|
|
<?php
|
2009-11-13 22:43:16 +00:00
|
|
|
/**
|
|
|
|
|
* Shows database lag
|
|
|
|
|
*
|
2010-12-16 19:15:12 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
2009-11-13 22:43:16 +00:00
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2009-09-15 00:24:24 +00:00
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2009-11-13 22:43:16 +00:00
|
|
|
|
2012-07-25 19:31:06 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script to show database lag.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2009-11-13 22:43:16 +00:00
|
|
|
class DatabaseLag extends Maintenance {
|
2024-02-26 16:31:41 +00:00
|
|
|
|
2024-09-12 19:59:28 +00:00
|
|
|
/** @var bool */
|
2024-02-26 16:31:41 +00:00
|
|
|
protected $stopReporting = false;
|
|
|
|
|
|
2009-11-13 22:43:16 +00:00
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription( 'Shows database lag' );
|
2009-11-13 22:43:16 +00:00
|
|
|
$this->addOption( 'r', "Don't exit immediately, but show the lag every 5 seconds" );
|
2009-09-15 00:24:24 +00:00
|
|
|
}
|
2009-11-13 22:43:16 +00:00
|
|
|
|
|
|
|
|
public function execute() {
|
2023-08-31 09:21:12 +00:00
|
|
|
$lb = $this->getServiceContainer()->getDBLoadBalancer();
|
2009-11-13 22:43:16 +00:00
|
|
|
if ( $this->hasOption( 'r' ) ) {
|
2020-03-18 00:17:40 +00:00
|
|
|
$this->output( 'time ' );
|
2014-04-22 21:25:04 +00:00
|
|
|
|
|
|
|
|
$serverCount = $lb->getServerCount();
|
|
|
|
|
for ( $i = 1; $i < $serverCount; $i++ ) {
|
2009-11-13 22:43:16 +00:00
|
|
|
$hostname = $lb->getServerName( $i );
|
2020-03-18 00:17:40 +00:00
|
|
|
$this->output( sprintf( "%-12s ", $hostname ) );
|
2009-11-13 22:43:16 +00:00
|
|
|
}
|
2020-03-18 00:17:40 +00:00
|
|
|
$this->output( "\n" );
|
2009-11-13 22:43:16 +00:00
|
|
|
|
2024-02-26 16:31:41 +00:00
|
|
|
do {
|
2009-11-13 22:43:16 +00:00
|
|
|
$lags = $lb->getLagTimes();
|
|
|
|
|
unset( $lags[0] );
|
2020-03-18 00:17:40 +00:00
|
|
|
$this->output( gmdate( 'H:i:s' ) . ' ' );
|
2010-10-14 20:53:04 +00:00
|
|
|
foreach ( $lags as $lag ) {
|
2024-02-26 13:50:06 +00:00
|
|
|
$this->output(
|
|
|
|
|
sprintf(
|
|
|
|
|
"%-12s ",
|
|
|
|
|
$lag === false ? 'replication stopped or errored' : $lag
|
|
|
|
|
)
|
|
|
|
|
);
|
2009-11-13 22:43:16 +00:00
|
|
|
}
|
2020-03-18 00:17:40 +00:00
|
|
|
$this->output( "\n" );
|
2009-11-13 22:43:16 +00:00
|
|
|
sleep( 5 );
|
2024-02-26 16:31:41 +00:00
|
|
|
} while ( !$this->stopReporting );
|
|
|
|
|
|
2009-11-13 22:43:16 +00:00
|
|
|
} else {
|
|
|
|
|
$lags = $lb->getLagTimes();
|
2010-05-22 16:50:39 +00:00
|
|
|
foreach ( $lags as $i => $lag ) {
|
2009-11-13 22:43:16 +00:00
|
|
|
$name = $lb->getServerName( $i );
|
2024-02-26 13:50:06 +00:00
|
|
|
$this->output(
|
|
|
|
|
sprintf(
|
|
|
|
|
"%-20s %s\n",
|
|
|
|
|
$name,
|
|
|
|
|
$lag === false ? 'replication stopped or errored' : $lag
|
|
|
|
|
)
|
|
|
|
|
);
|
2009-11-13 22:43:16 +00:00
|
|
|
}
|
2009-09-15 00:24:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-11-13 22:43:16 +00:00
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = DatabaseLag::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|