MediaWiki  1.30.0
getLagTimes.php
Go to the documentation of this file.
1 <?php
24 require_once __DIR__ . '/Maintenance.php';
25 
27 
33 class GetLagTimes extends Maintenance {
34  public function __construct() {
35  parent::__construct();
36  $this->addDescription( 'Dump replication lag times' );
37  $this->addOption( 'report', "Report the lag values to StatsD" );
38  }
39 
40  public function execute() {
41  $services = MediaWikiServices::getInstance();
42  $lbFactory = $services->getDBLoadBalancerFactory();
43  $stats = $services->getStatsdDataFactory();
44  $lbsByType = [
45  'main' => $lbFactory->getAllMainLBs(),
46  'external' => $lbFactory->getAllExternalLBs()
47  ];
48 
49  foreach ( $lbsByType as $type => $lbs ) {
50  foreach ( $lbs as $cluster => $lb ) {
51  if ( $lb->getServerCount() <= 1 ) {
52  continue;
53  }
54  $lags = $lb->getLagTimes();
55  foreach ( $lags as $serverIndex => $lag ) {
56  $host = $lb->getServerName( $serverIndex );
57  if ( IP::isValid( $host ) ) {
58  $ip = $host;
59  $host = gethostbyaddr( $host );
60  } else {
61  $ip = gethostbyname( $host );
62  }
63 
64  $starLen = min( intval( $lag ), 40 );
65  $stars = str_repeat( '*', $starLen );
66  $this->output( sprintf( "%10s %20s %3d %s\n", $ip, $host, $lag, $stars ) );
67 
68  if ( $this->hasOption( 'report' ) ) {
69  $group = ( $type === 'external' ) ? 'external' : $cluster;
70  $stats->gauge( "loadbalancer.lag.$group.$host", intval( $lag * 1e3 ) );
71  }
72  }
73  }
74  }
75  }
76 }
77 
78 $maintClass = "GetLagTimes";
79 require_once RUN_MAINTENANCE_IF_MAIN;
GetLagTimes\__construct
__construct()
Default constructor.
Definition: getLagTimes.php:34
GetLagTimes\execute
execute()
Do the actual work.
Definition: getLagTimes.php:40
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:287
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
$maintClass
$maintClass
Definition: getLagTimes.php:78
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:215
$services
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place or wrap services the preferred way to define a new service is the $wgServiceWiringFiles array $services
Definition: hooks.txt:2198
GetLagTimes
Maintenance script that displays replication lag times.
Definition: getLagTimes.php:33
IP\isValid
static isValid( $ip)
Validate an IP address.
Definition: IP.php:111
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:373
MediaWikiServices
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular param exists.
Definition: Maintenance.php:236
$type
$type
Definition: testCompression.php:48