45 $lbFactory = $services->getDBLoadBalancerFactory();
46 $stats = $services->getStatsFactory();
48 'main' => $lbFactory->getAllMainLBs(),
49 'external' => $lbFactory->getAllExternalLBs()
52 foreach ( $lbsByType as $type => $lbs ) {
53 foreach ( $lbs as $cluster => $lb ) {
54 if ( $lb->getServerCount() <= 1 ) {
57 $lags = $lb->getLagTimes();
58 foreach ( $lags as $serverIndex => $lag ) {
59 $host = $lb->getServerName( $serverIndex );
60 if ( IPUtils::isValid( $host ) ) {
62 $host = gethostbyaddr( $host );
64 $ip = gethostbyname( $host );
67 if ( $lag ===
false ) {
68 $stars =
'replication stopped or errored';
70 $starLen = min( intval( $lag ), 40 );
71 $stars = str_repeat(
'*', $starLen );
73 $this->
output( sprintf(
"%10s %20s %3d %s\n", $ip, $host, $lag, $stars ) );
76 $group = ( $type ===
'external' ) ?
'external' : $cluster;
80 $stats->getGauge(
'loadbalancer_lag_milliseconds' )
81 ->setLabel(
'group', $group )
82 ->setLabel(
'host', $host )
83 ->copyToStatsdAt(
"loadbalancer.lag.$group.$host" )
84 ->set( (
int)( $lag * 1e3 ) );
87 $stats->getGauge(
'loadbalancer_lag_seconds' )
88 ->setLabel(
'group', $group )
89 ->setLabel(
'host', $host )