http://www.mediawiki.org/wiki/Special:Code/MediaWiki/83617
Revision: 83617 Author: tstarling Date: 2011-03-10 00:00:34 +0000 (Thu, 10 Mar 2011) Log Message: ----------- * 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. Modified Paths: -------------- trunk/phase3/RELEASE-NOTES trunk/phase3/includes/DefaultSettings.php trunk/phase3/includes/GlobalFunctions.php trunk/phase3/includes/job/JobQueue.php Modified: trunk/phase3/RELEASE-NOTES =================================================================== --- trunk/phase3/RELEASE-NOTES 2011-03-09 23:34:07 UTC (rev 83616) +++ trunk/phase3/RELEASE-NOTES 2011-03-10 00:00:34 UTC (rev 83617) @@ -94,6 +94,8 @@ * 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 Modified: trunk/phase3/includes/DefaultSettings.php =================================================================== --- trunk/phase3/includes/DefaultSettings.php 2011-03-09 23:34:07 UTC (rev 83616) +++ trunk/phase3/includes/DefaultSettings.php 2011-03-10 00:00:34 UTC (rev 83617) @@ -3940,6 +3940,14 @@ */ $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). */ Modified: trunk/phase3/includes/GlobalFunctions.php =================================================================== --- trunk/phase3/includes/GlobalFunctions.php 2011-03-09 23:34:07 UTC (rev 83616) +++ trunk/phase3/includes/GlobalFunctions.php 2011-03-10 00:00:34 UTC (rev 83617) @@ -2071,15 +2071,20 @@ /** * 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 @@ $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 @@ } 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 Modified: trunk/phase3/includes/job/JobQueue.php =================================================================== --- trunk/phase3/includes/job/JobQueue.php 2011-03-09 23:34:07 UTC (rev 83616) +++ trunk/phase3/includes/job/JobQueue.php 2011-03-10 00:00:34 UTC (rev 83617) @@ -74,6 +74,7 @@ return false; } + wfIncrStats( 'job-pop' ); $namespace = $row->job_namespace; $dbkey = $row->job_title; $title = Title::makeTitleSafe( $namespace, $dbkey ); @@ -163,6 +164,7 @@ // 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 @@ } } if ( $rows ) { + wfIncrStats( 'job-insert', count( $rows ) ); $dbw->begin(); $dbw->insert( 'job', $rows, __METHOD__, 'IGNORE' ); $dbw->commit(); @@ -280,6 +283,7 @@ return; } } + wfIncrStats( 'job-insert' ); return $dbw->insert( 'job', $fields, __METHOD__ ); } _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs