X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FgetLagTimes.php;h=677bfa223fa84f25d5706911152b9134428e2146;hb=a7f993c7f2560d9c73999e96c3dade1d0c3dc0d8;hp=68be9f172a1322c8c102179553de038382d7bd76;hpb=3dc6844ae15512838c9ec70b4903090c2723967f;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/getLagTimes.php b/maintenance/getLagTimes.php index 68be9f172a..677bfa223f 100644 --- a/maintenance/getLagTimes.php +++ b/maintenance/getLagTimes.php @@ -21,7 +21,9 @@ * @ingroup Maintenance */ -require_once( __DIR__ . '/Maintenance.php' ); +require_once __DIR__ . '/Maintenance.php'; + +use MediaWiki\MediaWikiServices; /** * Maintenance script that displays replication lag times. @@ -31,32 +33,40 @@ require_once( __DIR__ . '/Maintenance.php' ); class GetLagTimes extends Maintenance { public function __construct() { parent::__construct(); - $this->mDescription = "Dump replication lag times"; + $this->addDescription( 'Dump replication lag times' ); + $this->addOption( 'report', "Report the lag values to StatsD" ); } public function execute() { - $lb = wfGetLB(); + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + $stats = MediaWikiServices::getInstance()->getStatsdDataFactory(); - if ( $lb->getServerCount() == 1 ) { - $this->error( "This script dumps replication lag times, but you don't seem to have\n" - . "a multi-host db server configuration." ); - } else { + $lbs = $lbFactory->getAllMainLBs() + $lbFactory->getAllExternalLBs(); + foreach ( $lbs as $cluster => $lb ) { + if ( $lb->getServerCount() <= 1 ) { + continue; + } $lags = $lb->getLagTimes(); - foreach ( $lags as $n => $lag ) { - $host = $lb->getServerName( $n ); + 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 ) ); + + if ( $this->hasOption( 'report' ) ) { + $stats->gauge( "loadbalancer.lag.$cluster.$host", $lag ); + } } } } } $maintClass = "GetLagTimes"; -require_once( RUN_MAINTENANCE_IF_MAIN ); +require_once RUN_MAINTENANCE_IF_MAIN;