MediaWiki  REL1_21
lag.php
Go to the documentation of this file.
00001 <?php
00024 require_once( __DIR__ . '/Maintenance.php' );
00025 
00031 class DatabaseLag extends Maintenance {
00032         public function __construct() {
00033                 parent::__construct();
00034                 $this->mDescription = "Shows database lag";
00035                 $this->addOption( 'r', "Don't exit immediately, but show the lag every 5 seconds" );
00036         }
00037 
00038         public function execute() {
00039                 if ( $this->hasOption( 'r' ) ) {
00040                         $lb = wfGetLB();
00041                         echo 'time     ';
00042                         for ( $i = 1; $i < $lb->getServerCount(); $i++ ) {
00043                                 $hostname = $lb->getServerName( $i );
00044                                 printf( "%-12s ", $hostname );
00045                         }
00046                         echo "\n";
00047 
00048                         while ( 1 ) {
00049                                 $lb->clearLagTimeCache();
00050                                 $lags = $lb->getLagTimes();
00051                                 unset( $lags[0] );
00052                                 echo gmdate( 'H:i:s' ) . ' ';
00053                                 foreach ( $lags as $lag ) {
00054                                         printf( "%-12s ", $lag === false ? 'false' : $lag );
00055                                 }
00056                                 echo "\n";
00057                                 sleep( 5 );
00058                         }
00059                 } else {
00060                         $lb = wfGetLB();
00061                         $lags = $lb->getLagTimes();
00062                         foreach ( $lags as $i => $lag ) {
00063                                 $name = $lb->getServerName( $i );
00064                                 $this->output( sprintf( "%-20s %s\n", $name, $lag === false ? 'false' : $lag ) );
00065                         }
00066                 }
00067         }
00068 }
00069 
00070 $maintClass = "DatabaseLag";
00071 require_once( RUN_MAINTENANCE_IF_MAIN );