MediaWiki fundraising/REL1_35
lag.php
Go to the documentation of this file.
1<?php
24require_once __DIR__ . '/Maintenance.php';
25
27
33class 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 $this->output( 'time ' );
44
45 $serverCount = $lb->getServerCount();
46 for ( $i = 1; $i < $serverCount; $i++ ) {
47 $hostname = $lb->getServerName( $i );
48 $this->output( sprintf( "%-12s ", $hostname ) );
49 }
50 $this->output( "\n" );
51
52 // @phan-suppress-next-line PhanInfiniteLoop
53 while ( 1 ) {
54 $lags = $lb->getLagTimes();
55 unset( $lags[0] );
56 $this->output( gmdate( 'H:i:s' ) . ' ' );
57 foreach ( $lags as $lag ) {
58 $this->output( sprintf( "%-12s ", $lag === false ? 'false' : $lag ) );
59 }
60 $this->output( "\n" );
61 sleep( 5 );
62 }
63 } else {
64 $lags = $lb->getLagTimes();
65 foreach ( $lags as $i => $lag ) {
66 $name = $lb->getServerName( $i );
67 $this->output( sprintf( "%-20s %s\n", $name, $lag === false ? 'false' : $lag ) );
68 }
69 }
70 }
71}
72
73$maintClass = DatabaseLag::class;
74require_once RUN_MAINTENANCE_IF_MAIN;
const RUN_MAINTENANCE_IF_MAIN
Maintenance script to show database lag.
Definition lag.php:33
execute()
Do the actual work.
Definition lag.php:40
__construct()
Default constructor.
Definition lag.php:34
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
MediaWikiServices is the service locator for the application scope of MediaWiki.
$maintClass
Definition lag.php:73