From 24bf07cc86fdf7cde997e7cb5ed79142f4c030c9 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Thu, 10 Mar 2011 00:00:34 +0000 Subject: [PATCH] * Add a $count argument to wfIncrStats(), to allow it to increase the count by more than one at a time. * Added stats to job insert and pop. * Formalised live patch for UDP stats aggregation, adding $wgAggregateStatsID. --- RELEASE-NOTES | 2 ++ includes/DefaultSettings.php | 8 ++++++++ includes/GlobalFunctions.php | 17 +++++++++++------ includes/job/JobQueue.php | 4 ++++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 1153ff4caf..f2cbf0a697 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -94,6 +94,8 @@ PHP if you have not done so prior to upgrading MediaWiki. * Added UserGetLanguageObject hook to change the language used in $wgLang * (bug 14645) When $wgMiserMode is on, expensive special pages are styled differently (italicized by default) on Special:SpecialPages +* Added $wgAggregateStatsID, which allows UDP stats to be aggregated over + several wikis. === Bug fixes in 1.18 === * (bug 23119) WikiError class and subclasses are now marked as deprecated diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 339dc037da..889fa99b5c 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -3940,6 +3940,14 @@ $wgDebugFunctionEntry = 0; */ $wgStatsMethod = 'cache'; +/** + * When $wgStatsMethod is 'udp', setting this to a string allows statistics to + * be aggregated over more than one wiki. The string will be used in place of + * the DB name in outgoing UDP packets. If this is set to false, the DB name + * will be used. + */ +$wgAggregateStatsID = false; + /** Whereas to count the number of time an article is viewed. * Does not work if pages are cached (for example with squid). */ diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index cd6beee51a..bdb18b8496 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2071,15 +2071,20 @@ function wfMkdirParents( $dir, $mode = null, $caller = null ) { /** * Increment a statistics counter */ -function wfIncrStats( $key ) { +function wfIncrStats( $key, $count = 1 ) { global $wgStatsMethod; + $count = intval( $count ); + if( $wgStatsMethod == 'udp' ) { - global $wgUDPProfilerHost, $wgUDPProfilerPort, $wgDBname; + global $wgUDPProfilerHost, $wgUDPProfilerPort, $wgDBname, $wgAggregateStatsID; static $socket; + + $id = $wgAggregateStatsID !== false ? $wgAggregateStatsID : $wgDBname; + if ( !$socket ) { $socket = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP ); - $statline = "stats/{$wgDBname} - 1 1 1 1 1 -total\n"; + $statline = "stats/{$id} - {$count} 1 1 1 1 -total\n"; socket_sendto( $socket, $statline, @@ -2089,7 +2094,7 @@ function wfIncrStats( $key ) { $wgUDPProfilerPort ); } - $statline = "stats/{$wgDBname} - 1 1 1 1 1 {$key}\n"; + $statline = "stats/{$id} - {$count} 1 1 1 1 {$key}\n"; wfSuppressWarnings(); socket_sendto( $socket, @@ -2103,8 +2108,8 @@ function wfIncrStats( $key ) { } elseif( $wgStatsMethod == 'cache' ) { global $wgMemc; $key = wfMemcKey( 'stats', $key ); - if ( is_null( $wgMemc->incr( $key ) ) ) { - $wgMemc->add( $key, 1 ); + if ( is_null( $wgMemc->incr( $key, $count ) ) ) { + $wgMemc->add( $key, $count ); } } else { // Disabled diff --git a/includes/job/JobQueue.php b/includes/job/JobQueue.php index 7cc339eb93..95f9c777ac 100644 --- a/includes/job/JobQueue.php +++ b/includes/job/JobQueue.php @@ -74,6 +74,7 @@ abstract class Job { return false; } + wfIncrStats( 'job-pop' ); $namespace = $row->job_namespace; $dbkey = $row->job_title; $title = Title::makeTitleSafe( $namespace, $dbkey ); @@ -163,6 +164,7 @@ abstract class Job { // If execution got to here, there's a row in $row that has been deleted from the database // by this thread. Hence the concurrent pop was successful. + wfIncrStats( 'job-pop' ); $namespace = $row->job_namespace; $dbkey = $row->job_title; $title = Title::makeTitleSafe( $namespace, $dbkey ); @@ -238,6 +240,7 @@ abstract class Job { } } if ( $rows ) { + wfIncrStats( 'job-insert', count( $rows ) ); $dbw->begin(); $dbw->insert( 'job', $rows, __METHOD__, 'IGNORE' ); $dbw->commit(); @@ -280,6 +283,7 @@ abstract class Job { return; } } + wfIncrStats( 'job-insert' ); return $dbw->insert( 'job', $fields, __METHOD__ ); } -- 2.20.1