31 $lbFactory = $services->getDBLoadBalancerFactory();
32 $stats = $services->getStatsFactory();
34 'main' => $lbFactory->getAllMainLBs(),
35 'external' => $lbFactory->getAllExternalLBs()
38 foreach ( $lbsByType as $type => $lbs ) {
39 foreach ( $lbs as $cluster => $lb ) {
40 if ( $lb->getServerCount() <= 1 ) {
43 $lags = $lb->getLagTimes();
44 foreach ( $lags as $serverIndex => $lag ) {
45 $host = $lb->getServerName( $serverIndex );
46 if ( IPUtils::isValid( $host ) ) {
48 $host = gethostbyaddr( $host );
50 $ip = gethostbyname( $host );
53 if ( $lag ===
false ) {
54 $stars =
'replication stopped or errored';
56 $starLen = min( intval( $lag ), 40 );
57 $stars = str_repeat(
'*', $starLen );
59 $this->
output( sprintf(
"%10s %20s %3d %s\n", $ip, $host, $lag, $stars ) );
62 $group = ( $type ===
'external' ) ?
'external' : $cluster;
66 $stats->getGauge(
'loadbalancer_lag_milliseconds' )
67 ->setLabel(
'group', $group )
68 ->setLabel(
'host', $host )
69 ->copyToStatsdAt(
"loadbalancer.lag.$group.$host" )
70 ->set( (
int)( $lag * 1e3 ) );
73 $stats->getGauge(
'loadbalancer_lag_seconds' )
74 ->setLabel(
'group', $group )
75 ->setLabel(
'host', $host )