Send integer ms to DB lag time guage instead of seconds
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 23 Mar 2017 18:55:07 +0000 (11:55 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 4 Apr 2017 03:40:22 +0000 (20:40 -0700)
Previously, this sent the floating point value in seconds,
which is not what statsd expects here.

Bug: T149210
Change-Id: I8fcd58d7c9e183952df1257b1520d9426a42fd26

maintenance/getLagTimes.php

index 677bfa2..ad2fdf8 100644 (file)
@@ -38,30 +38,37 @@ 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 ) );
+                                       }
                                }
                        }
                }