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 ( $prefix)
 
 clearData ()
 Clear all buffered data from the factory.
 
 decrement ( $key)
 
 gauge ( $key, $value)
 
 getData ()
 
 getDataCount ()
 Return the number of buffered statsd data entries.
 
 hasData ()
 Check whether this data factory has any buffered data.
 
 increment ( $key)
 
 produceStatsdData ( $key, $value=1, $metric=StatsdDataInterface::STATSD_METRIC_COUNT)
 
 set ( $key, $value)
 
 setEnabled ( $enabled)
 Set collection enable status.
 
 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 a database callback (see MWLBFactory::applyGlobalState).

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 @method StatsdData produceStatsdDataEntity() We use StatsdData::setKey, which is not in StatsdDataInterface https://gerrit.wikimedia.org/r/643976

Definition at line 49 of file BufferingStatsdDataFactory.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 57 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 206 of file BufferingStatsdDataFactory.php.

◆ decrement()

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

Definition at line 119 of file BufferingStatsdDataFactory.php.

◆ gauge()

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

Definition at line 83 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 210 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 182 of file BufferingStatsdDataFactory.php.

References Wikimedia\Stats\BufferingStatsdDataFactory\$buffer.

◆ increment()

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

Definition at line 107 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 95 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 214 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 71 of file BufferingStatsdDataFactory.php.

◆ updateCount()

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

Definition at line 131 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: