Followup to r59869, add to MySQL section, and copy patch to SQLite directory
[lhc/web/wiklou.git] / maintenance / lag.php
1 <?php
2
3 /**
4 * Shows database lag
5 *
6 * @ingroup Maintenance
7 */
8
9 require_once( dirname(__FILE__) . '/Maintenance.php' );
10
11 class DatabaseLag extends Maintenance {
12 public function __construct() {
13 parent::__construct();
14 $this->mDescription = "Shows database lag";
15 $this->addOption( 'r', "Don't exit immediately, but show the lag every 5 seconds" );
16 }
17
18 public function execute() {
19 if ( $this->hasOption( 'r' ) ) {
20 $lb = wfGetLB();
21 $this->output( 'time ' );
22 for( $i = 0; $i < $lb->getServerCount(); $i++ ) {
23 $hostname = $lb->getServerName( $i );
24 $this->output( sprintf( "%-12s ", $hostname ) );
25 }
26 $this->output( "\n" );
27
28 while( 1 ) {
29 $lags = $lb->getLagTimes();
30 unset( $lags[0] );
31 $this->output( gmdate( 'H:i:s' ) . ' ' );
32 foreach( $lags as $i => $lag ) {
33 $this->output( sprintf( "%-12s " , $lag === false ? 'false' : $lag ) );
34 }
35 $this->output( "\n" );
36 sleep( 5 );
37 }
38 } else {
39 $lb = wfGetLB();
40 $lags = $lb->getLagTimes();
41 foreach( $lags as $i => $lag ) {
42 $name = $lb->getServerName( $i );
43 $this->output( sprintf( "%-20s %s\n" , $name, $lag === false ? 'false' : $lag ) );
44 }
45 }
46 }
47 }
48
49 $maintClass = "DatabaseLag";
50 require_once( DO_MAINTENANCE );