X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FgetLagTimes.php;h=c2c7983347f54f7b27dba86006e756d5c0132747;hb=4e8eed74233db1db69f178fb0f4f1f8d6416bd52;hp=677bfa223fa84f25d5706911152b9134428e2146;hpb=1f83b424294a6fd78cb73cf43db3464ca7481774;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/getLagTimes.php b/maintenance/getLagTimes.php index 677bfa223f..c2c7983347 100644 --- a/maintenance/getLagTimes.php +++ b/maintenance/getLagTimes.php @@ -38,35 +38,42 @@ class GetLagTimes extends Maintenance { } public function execute() { - $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); - $stats = MediaWikiServices::getInstance()->getStatsdDataFactory(); + $services = MediaWikiServices::getInstance(); + $lbFactory = $services->getDBLoadBalancerFactory(); + $stats = $services->getStatsdDataFactory(); + $lbsByType = [ + 'main' => $lbFactory->getAllMainLBs(), + 'external' => $lbFactory->getAllExternalLBs() + ]; - $lbs = $lbFactory->getAllMainLBs() + $lbFactory->getAllExternalLBs(); - foreach ( $lbs as $cluster => $lb ) { - if ( $lb->getServerCount() <= 1 ) { - continue; - } - $lags = $lb->getLagTimes(); - foreach ( $lags as $serverIndex => $lag ) { - $host = $lb->getServerName( $serverIndex ); - if ( IP::isValid( $host ) ) { - $ip = $host; - $host = gethostbyaddr( $host ); - } else { - $ip = gethostbyname( $host ); + foreach ( $lbsByType as $type => $lbs ) { + foreach ( $lbs as $cluster => $lb ) { + if ( $lb->getServerCount() <= 1 ) { + continue; } + $lags = $lb->getLagTimes(); + foreach ( $lags as $serverIndex => $lag ) { + $host = $lb->getServerName( $serverIndex ); + if ( IP::isValid( $host ) ) { + $ip = $host; + $host = gethostbyaddr( $host ); + } else { + $ip = gethostbyname( $host ); + } - $starLen = min( intval( $lag ), 40 ); - $stars = str_repeat( '*', $starLen ); - $this->output( sprintf( "%10s %20s %3d %s\n", $ip, $host, $lag, $stars ) ); + $starLen = min( intval( $lag ), 40 ); + $stars = str_repeat( '*', $starLen ); + $this->output( sprintf( "%10s %20s %3d %s\n", $ip, $host, $lag, $stars ) ); - if ( $this->hasOption( 'report' ) ) { - $stats->gauge( "loadbalancer.lag.$cluster.$host", $lag ); + if ( $this->hasOption( 'report' ) ) { + $group = ( $type === 'external' ) ? 'external' : $cluster; + $stats->gauge( "loadbalancer.lag.$group.$host", intval( $lag * 1e3 ) ); + } } } } } } -$maintClass = "GetLagTimes"; +$maintClass = GetLagTimes::class; require_once RUN_MAINTENANCE_IF_MAIN;