MediaWiki  REL1_24
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 
00043             $serverCount = $lb->getServerCount();
00044             for ( $i = 1; $i < $serverCount; $i++ ) {
00045                 $hostname = $lb->getServerName( $i );
00046                 printf( "%-12s ", $hostname );
00047             }
00048             echo "\n";
00049 
00050             while ( 1 ) {
00051                 $lb->clearLagTimeCache();
00052                 $lags = $lb->getLagTimes();
00053                 unset( $lags[0] );
00054                 echo gmdate( 'H:i:s' ) . ' ';
00055                 foreach ( $lags as $lag ) {
00056                     printf( "%-12s ", $lag === false ? 'false' : $lag );
00057                 }
00058                 echo "\n";
00059                 sleep( 5 );
00060             }
00061         } else {
00062             $lb = wfGetLB();
00063             $lags = $lb->getLagTimes();
00064             foreach ( $lags as $i => $lag ) {
00065                 $name = $lb->getServerName( $i );
00066                 $this->output( sprintf( "%-20s %s\n", $name, $lag === false ? 'false' : $lag ) );
00067             }
00068         }
00069     }
00070 }
00071 
00072 $maintClass = "DatabaseLag";
00073 require_once RUN_MAINTENANCE_IF_MAIN;