From 83743e7bb3786028d209bb49df54d833e8dd2522 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 7 Jul 2007 04:53:07 +0000 Subject: [PATCH] API: (bug 10211) Added db server replication lag information in meta=siteinfo --- RELEASE-NOTES | 1 + includes/api/ApiQuerySiteinfo.php | 37 +++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 195b59f698..bd284525ea 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -305,6 +305,7 @@ Full API documentation is available at http://www.mediawiki.org/wiki/API * backlinks, embeddedin and imageusage lists should use (bl|ei|iu)title parameter instead of titles. Titles for these lists is obsolete and might stop working soon. * Added prop=imageinfo - gets image properties and upload history +* (bug 10211) Added db server replication lag information in meta=siteinfo == Maintenance script changes since 1.10 == diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index 734f62438a..a05ea12394 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -57,6 +57,9 @@ class ApiQuerySiteinfo extends ApiQueryBase { $filteriw = isset($params['filteriw']) ? $params['filteriw'] : false; $this->appendInterwikiMap($p, $filteriw); break; + case 'dbserverlag' : + $this->appendDbServerLagInfo($p, $params['showalldb']); + break; } } } @@ -127,6 +130,31 @@ class ApiQuerySiteinfo extends ApiQueryBase { $this->getResult()->setIndexedTagName($data, 'iw'); $this->getResult()->addValue('query', $property, $data); } + + protected function appendDbServerLagInfo($property, $includeAll) { + global $wgLoadBalancer; + + $data = array(); + + if ($includeAll) { + global $wgDBservers; + $lags = $wgLoadBalancer->getLagTimes(); + foreach( $lags as $i => $lag ) { + $data[] = array ( + 'host' => $wgDBservers[$i]['host'], + 'lag' => $lag); + } + } else { + list( $host, $lag ) = $wgLoadBalancer->getMaxLag(); + $data[] = array ( + 'host' => $host, + 'lag' => $lag); + } + + $result = $this->getResult(); + $result->setIndexedTagName($data, 'db'); + $result->addValue('query', $property, $data); + } protected function getAllowedParams() { return array ( @@ -137,7 +165,8 @@ class ApiQuerySiteinfo extends ApiQueryBase { ApiBase :: PARAM_TYPE => array ( 'general', 'namespaces', - 'interwikimap' + 'interwikimap', + 'dbserverlag', )), 'filteriw' => array ( @@ -145,6 +174,8 @@ class ApiQuerySiteinfo extends ApiQueryBase { 'local', '!local', )), + + 'showalldb' => false, ); } @@ -154,9 +185,11 @@ class ApiQuerySiteinfo extends ApiQueryBase { 'Which sysinfo properties to get:', ' "general" - Overall system information', ' "namespaces" - List of registered namespaces (localized)', - ' "interwikimap" - Return interwiki map (optionally filtered)' + ' "interwikimap" - Return interwiki map (optionally filtered)', + ' "dbserverlag" - Get highest database replication server lag', ), 'filteriw' => 'Return only local or only nonlocal entries of the interwiki map', + 'showalldb' => 'List all DB servers, not just the one lagging the most', ); } -- 2.20.1