MediaWiki master
Wikimedia\Stats\BufferingStatsdDataFactory Class Reference

MediaWiki's adaption of StatsdDataFactory that provides buffering and metric prefixing. More...

Inherits StatsdDataFactory, and Wikimedia\Stats\IBufferingStatsdDataFactory.

Collaboration diagram for Wikimedia\Stats\BufferingStatsdDataFactory:

Public Member Functions

 __construct (string $prefix)
 
 clearData ()
 Clear all buffered data from the factory.
Since
1.31

 
 decrement ( $key)
 
 gauge ( $key, $value)
 
 getData ()
 
 getDataCount ()
 Return the number of buffered statsd data entries.
Returns
int
Since
1.31

 
 hasData ()
 Check whether this data factory has any buffered data.
Returns
bool

 
 increment ( $key)
 
 produceStatsdData ( $key, $value=1, $metric=StatsdDataInterface::STATSD_METRIC_COUNT)
 
 set ( $key, $value)
 
 setEnabled ( $enabled)
 Set collection enable status.
Parameters
bool$enabledWill collection be enabled?
Returns
void

 
 timing ( $key, $time)
 
 updateCount ( $key, $delta)
 

Protected Attributes

array $buffer = []
 
bool $enabled = true
 

Detailed Description

MediaWiki's adaption of StatsdDataFactory that provides buffering and metric prefixing.

The buffering functionality exists as a performance optimisation to reduce network traffic and StatsD processing by maximally utilizing StatsdClient's ability to compress counter increments, and send all data in a few large UDP packets over a single connection.

These buffers are sent from MediaWikiEntryPoint::emitBufferedStats. For web requests, this happens post-send. For command-line scripts, this happens periodically from calls to Maintenance::commitTransaction() and Maintenance::commitTransactionRound().

Todo
Evaluate upstream's StatsdService class, which implements similar buffering logic and was released in statsd-php-client 1.0.13, shortly after we implemented this here for statsd-php-client 1.0.12 at the time.
Since
1.25
Deprecated
since 1.45, use https://www.mediawiki.org/wiki/Manual:Stats @method StatsdData produceStatsdDataEntity() We use StatsdData::setKey, which is not in StatsdDataInterface https://gerrit.wikimedia.org/r/643976

Definition at line 36 of file BufferingStatsdDataFactory.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Stats\BufferingStatsdDataFactory::__construct ( string $prefix)

Definition at line 44 of file BufferingStatsdDataFactory.php.

Member Function Documentation

◆ clearData()

Wikimedia\Stats\BufferingStatsdDataFactory::clearData ( )

Clear all buffered data from the factory.

Since
1.31

Implements Wikimedia\Stats\IBufferingStatsdDataFactory.

Definition at line 196 of file BufferingStatsdDataFactory.php.

◆ decrement()

Wikimedia\Stats\BufferingStatsdDataFactory::decrement ( $key)
Parameters
string$key
Returns
void

Definition at line 106 of file BufferingStatsdDataFactory.php.

◆ gauge()

Wikimedia\Stats\BufferingStatsdDataFactory::gauge ( $key,
$value )
Parameters
string$key
float | int$value
Returns
void

Definition at line 70 of file BufferingStatsdDataFactory.php.

◆ getData()

Wikimedia\Stats\BufferingStatsdDataFactory::getData ( )

◆ getDataCount()

Wikimedia\Stats\BufferingStatsdDataFactory::getDataCount ( )

Return the number of buffered statsd data entries.

Returns
int
Since
1.31

Implements Wikimedia\Stats\IBufferingStatsdDataFactory.

Definition at line 201 of file BufferingStatsdDataFactory.php.

◆ hasData()

Wikimedia\Stats\BufferingStatsdDataFactory::hasData ( )

Check whether this data factory has any buffered data.

Returns
bool

Implements Wikimedia\Stats\IBufferingStatsdDataFactory.

Definition at line 171 of file BufferingStatsdDataFactory.php.

References Wikimedia\Stats\BufferingStatsdDataFactory\$buffer.

◆ increment()

Wikimedia\Stats\BufferingStatsdDataFactory::increment ( $key)
Parameters
string$key
Returns
array

Definition at line 94 of file BufferingStatsdDataFactory.php.

◆ produceStatsdData()

Wikimedia\Stats\BufferingStatsdDataFactory::produceStatsdData ( $key,
$value = 1,
$metric = StatsdDataInterface::STATSD_METRIC_COUNT )

◆ set()

Wikimedia\Stats\BufferingStatsdDataFactory::set ( $key,
$value )
Parameters
string$key
float | int$value
Returns
array

Definition at line 82 of file BufferingStatsdDataFactory.php.

◆ setEnabled()

Wikimedia\Stats\BufferingStatsdDataFactory::setEnabled ( $enabled)

Set collection enable status.

Parameters
bool$enabledWill collection be enabled?
Returns
void

Implements Wikimedia\Stats\IBufferingStatsdDataFactory.

Definition at line 206 of file BufferingStatsdDataFactory.php.

References Wikimedia\Stats\BufferingStatsdDataFactory\$enabled.

◆ timing()

Wikimedia\Stats\BufferingStatsdDataFactory::timing ( $key,
$time )
Parameters
string$key
float | int$time
Returns
void

Definition at line 58 of file BufferingStatsdDataFactory.php.

◆ updateCount()

Wikimedia\Stats\BufferingStatsdDataFactory::updateCount ( $key,
$delta )
Parameters
string$key
int$delta
Returns
void

Definition at line 118 of file BufferingStatsdDataFactory.php.

Member Data Documentation

◆ $buffer

array Wikimedia\Stats\BufferingStatsdDataFactory::$buffer = []
protected

◆ $enabled

bool Wikimedia\Stats\BufferingStatsdDataFactory::$enabled = true
protected

The documentation for this class was generated from the following file: