MediaWiki master
lag.php
Go to the documentation of this file.
1<?php
24// @codeCoverageIgnoreStart
25require_once __DIR__ . '/Maintenance.php';
26// @codeCoverageIgnoreEnd
27
33class DatabaseLag extends Maintenance {
34
36 protected $stopReporting = false;
37
38 public function __construct() {
39 parent::__construct();
40 $this->addDescription( 'Shows database lag' );
41 $this->addOption( 'r', "Don't exit immediately, but show the lag every 5 seconds" );
42 }
43
44 public function execute() {
45 $lb = $this->getServiceContainer()->getDBLoadBalancer();
46 if ( $this->hasOption( 'r' ) ) {
47 $this->output( 'time ' );
48
49 $serverCount = $lb->getServerCount();
50 for ( $i = 1; $i < $serverCount; $i++ ) {
51 $hostname = $lb->getServerName( $i );
52 $this->output( sprintf( "%-12s ", $hostname ) );
53 }
54 $this->output( "\n" );
55
56 do {
57 $lags = $lb->getLagTimes();
58 unset( $lags[0] );
59 $this->output( gmdate( 'H:i:s' ) . ' ' );
60 foreach ( $lags as $lag ) {
61 $this->output(
62 sprintf(
63 "%-12s ",
64 $lag === false ? 'replication stopped or errored' : $lag
65 )
66 );
67 }
68 $this->output( "\n" );
69 sleep( 5 );
70 } while ( !$this->stopReporting );
71
72 } else {
73 $lags = $lb->getLagTimes();
74 foreach ( $lags as $i => $lag ) {
75 $name = $lb->getServerName( $i );
76 $this->output(
77 sprintf(
78 "%-20s %s\n",
79 $name,
80 $lag === false ? 'replication stopped or errored' : $lag
81 )
82 );
83 }
84 }
85 }
86}
87
88// @codeCoverageIgnoreStart
89$maintClass = DatabaseLag::class;
90require_once RUN_MAINTENANCE_IF_MAIN;
91// @codeCoverageIgnoreEnd
Maintenance script to show database lag.
Definition lag.php:33
execute()
Definition lag.php:44
__construct()
Definition lag.php:38
bool $stopReporting
Definition lag.php:36
$maintClass
Definition lag.php:89