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