MediaWiki  master
lag.php
Go to the documentation of this file.
1 <?php
24 require_once __DIR__ . '/Maintenance.php';
25 
27 
33 class DatabaseLag extends Maintenance {
34  public function __construct() {
35  parent::__construct();
36  $this->addDescription( 'Shows database lag' );
37  $this->addOption( 'r', "Don't exit immediately, but show the lag every 5 seconds" );
38  }
39 
40  public function execute() {
41  $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
42  if ( $this->hasOption( 'r' ) ) {
43  echo 'time ';
44 
45  $serverCount = $lb->getServerCount();
46  for ( $i = 1; $i < $serverCount; $i++ ) {
47  $hostname = $lb->getServerName( $i );
48  printf( "%-12s ", $hostname );
49  }
50  echo "\n";
51 
52  while ( 1 ) {
53  $lags = $lb->getLagTimes();
54  unset( $lags[0] );
55  echo gmdate( 'H:i:s' ) . ' ';
56  foreach ( $lags as $lag ) {
57  printf( "%-12s ", $lag === false ? 'false' : $lag );
58  }
59  echo "\n";
60  sleep( 5 );
61  }
62  } else {
63  $lags = $lb->getLagTimes();
64  foreach ( $lags as $i => $lag ) {
65  $name = $lb->getServerName( $i );
66  $this->output( sprintf( "%-20s %s\n", $name, $lag === false ? 'false' : $lag ) );
67  }
68  }
69  }
70 }
71 
72 $maintClass = DatabaseLag::class;
73 require_once RUN_MAINTENANCE_IF_MAIN;
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:86
hasOption( $name)
Checks to see if a particular option exists.
execute()
Definition: lag.php:40
addDescription( $text)
Set the description text.
output( $out, $channel=null)
Throw some output to the user.
__construct()
Definition: lag.php:34
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
$maintClass
Definition: lag.php:72
Maintenance script to show database lag.
Definition: lag.php:33