Merge maintenance-work branch:
[lhc/web/wiklou.git] / maintenance / getLagTimes.php
1 <?php
2 /**
3 * @file
4 * @ingroup Maintenance
5 */
6
7 require_once( "Maintenance.php" );
8
9 class GetLagTimes extends Maintenance {
10 public function __construct() {
11 parent::__construct();
12 $this->mDescription = "Dump replication lag times";
13 }
14
15 public function execute() {
16 $lb = wfGetLB();
17
18 if( $lb->getServerCount() == 1 ) {
19 $this->error( "This script dumps replication lag times, but you don't seem to have\n"
20 . "a multi-host db server configuration.\n" );
21 } else {
22 $lags = $lb->getLagTimes();
23 foreach( $lags as $n => $lag ) {
24 $host = $lb->getServerName( $n );
25 if( IP::isValid( $host ) ) {
26 $ip = $host;
27 $host = gethostbyaddr( $host );
28 } else {
29 $ip = gethostbyname( $host );
30 }
31 $starLen = min( intval( $lag ), 40 );
32 $stars = str_repeat( '*', $starLen );
33 $this->output( sprintf( "%10s %20s %3d %s\n", $ip, $host, $lag, $stars ) );
34 }
35 }
36 }
37 }
38
39 $maintClass = "GetLagTimes";
40 require_once( DO_MAINTENANCE );