]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - maintenance/getLagTimes.php
MediaWiki 1.17.0
[autoinstallsdev/mediawiki.git] / maintenance / getLagTimes.php
1 <?php
2 /**
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16  * http://www.gnu.org/copyleft/gpl.html
17  *
18  * @ingroup Maintenance
19  */
20
21 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
22
23 class GetLagTimes extends Maintenance {
24         public function __construct() {
25                 parent::__construct();
26                 $this->mDescription = "Dump replication lag times";
27         }
28
29         public function execute() {
30                 $lb = wfGetLB();
31
32                 if ( $lb->getServerCount() == 1 ) {
33                         $this->error( "This script dumps replication lag times, but you don't seem to have\n"
34                                                   . "a multi-host db server configuration." );
35                 } else {
36                         $lags = $lb->getLagTimes();
37                         foreach ( $lags as $n => $lag ) {
38                                 $host = $lb->getServerName( $n );
39                                 if ( IP::isValid( $host ) ) {
40                                         $ip = $host;
41                                         $host = gethostbyaddr( $host );
42                                 } else {
43                                         $ip = gethostbyname( $host );
44                                 }
45                                 $starLen = min( intval( $lag ), 40 );
46                                 $stars = str_repeat( '*', $starLen );
47                                 $this->output( sprintf( "%10s %20s %3d %s\n", $ip, $host, $lag, $stars ) );
48                         }
49                 }
50         }
51 }
52
53 $maintClass = "GetLagTimes";
54 require_once( RUN_MAINTENANCE_IF_MAIN );