MediaWiki REL1_33
getLagTimes.php
Go to the documentation of this file.
1<?php
24require_once __DIR__ . '/Maintenance.php';
25
27
33class GetLagTimes extends Maintenance {
34 public function __construct() {
35 parent::__construct();
36 $this->addDescription( 'Dump replication lag times' );
37 $this->addOption( 'report', "Report the lag values to StatsD" );
38 }
39
40 public function execute() {
41 $services = MediaWikiServices::getInstance();
42 $lbFactory = $services->getDBLoadBalancerFactory();
43 $stats = $services->getStatsdDataFactory();
44 $lbsByType = [
45 'main' => $lbFactory->getAllMainLBs(),
46 'external' => $lbFactory->getAllExternalLBs()
47 ];
48
49 foreach ( $lbsByType as $type => $lbs ) {
50 foreach ( $lbs as $cluster => $lb ) {
51 if ( $lb->getServerCount() <= 1 ) {
52 continue;
53 }
54 $lags = $lb->getLagTimes();
55 foreach ( $lags as $serverIndex => $lag ) {
56 $host = $lb->getServerName( $serverIndex );
57 if ( IP::isValid( $host ) ) {
58 $ip = $host;
59 $host = gethostbyaddr( $host );
60 } else {
61 $ip = gethostbyname( $host );
62 }
63
64 $starLen = min( intval( $lag ), 40 );
65 $stars = str_repeat( '*', $starLen );
66 $this->output( sprintf( "%10s %20s %3d %s\n", $ip, $host, $lag, $stars ) );
67
68 if ( $this->hasOption( 'report' ) ) {
69 $group = ( $type === 'external' ) ? 'external' : $cluster;
70 $stats->gauge( "loadbalancer.lag.$group.$host", intval( $lag * 1e3 ) );
71 }
72 }
73 }
74 }
75 }
76}
77
78$maintClass = GetLagTimes::class;
79require_once RUN_MAINTENANCE_IF_MAIN;
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
Maintenance script that displays replication lag times.
execute()
Do the actual work.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option exists.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
MediaWikiServices is the service locator for the application scope of MediaWiki.
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place or wrap services the preferred way to define a new service is the $wgServiceWiringFiles array $services
Definition hooks.txt:2290
$maintClass
require_once RUN_MAINTENANCE_IF_MAIN