24 require_once __DIR__ .
'/Maintenance.php';
26 use Wikimedia\IPUtils;
35 parent::__construct();
37 $this->
addOption(
'report',
"Report the lag values to StatsD" );
42 $lbFactory = $services->getDBLoadBalancerFactory();
43 $stats = $services->getStatsdDataFactory();
45 'main' => $lbFactory->getAllMainLBs(),
46 'external' => $lbFactory->getAllExternalLBs()
49 foreach ( $lbsByType as $type => $lbs ) {
50 foreach ( $lbs as $cluster => $lb ) {
51 if ( $lb->getServerCount() <= 1 ) {
54 $lags = $lb->getLagTimes();
55 foreach ( $lags as $serverIndex => $lag ) {
56 $host = $lb->getServerName( $serverIndex );
57 if ( IPUtils::isValid( $host ) ) {
59 $host = gethostbyaddr( $host );
61 $ip = gethostbyname( $host );
64 $starLen = min( intval( $lag ), 40 );
65 $stars = str_repeat(
'*', $starLen );
66 $this->
output( sprintf(
"%10s %20s %3d %s\n", $ip, $host, $lag, $stars ) );
69 $group = ( $type ===
'external' ) ?
'external' : $cluster;
70 $stats->gauge(
"loadbalancer.lag.$group.$host", (
int)( $lag * 1e3 ) );
79 require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script that displays replication lag times.
execute()
Do the actual work.
__construct()
Default constructor.
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.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.