MediaWiki  master
BufferingStatsdDataFactory Class Reference

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

Inheritance diagram for BufferingStatsdDataFactory:
Collaboration diagram for BufferingStatsdDataFactory:

Public Member Functions

 __construct ( $prefix)
 
 clearData ()
 Clear all buffered data from the factory. More...
 
 decrement ( $key)
 
 gauge ( $key, $value)
 
 getData ()
 
 getDataCount ()
 Return the number of buffered statsd data entries. More...
 
 hasData ()
 Check whether this data factory has any buffered data. More...
 
 increment ( $key)
 
 produceStatsdData ( $key, $value=1, $metric=StatsdDataInterface::STATSD_METRIC_COUNT)
 
 set ( $key, $value)
 
 setEnabled ( $enabled)
 Set collection enable status. More...
 
 timing ( $key, $time)
 
 updateCount ( $key, $delta)
 

Protected Attributes

array $buffer = []
 
bool $enabled = true
 

Static Private Member Functions

static normalizeMetricKey ( $key)
 Normalize a metric key for StatsD. More...
 

Private Attributes

string $prefix
 

Detailed Description

MediaWiki 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 MediaWiki::emitBufferedStatsdData. For web requests, this happens pre-send via wfLogProfilingData. 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 47 of file BufferingStatsdDataFactory.php.

Constructor & Destructor Documentation

◆ __construct()

BufferingStatsdDataFactory::__construct (   $prefix)

Definition at line 55 of file BufferingStatsdDataFactory.php.

References $prefix.

Member Function Documentation

◆ clearData()

BufferingStatsdDataFactory::clearData ( )

Clear all buffered data from the factory.

Since
1.31

Implements IBufferingStatsdDataFactory.

Definition at line 202 of file BufferingStatsdDataFactory.php.

◆ decrement()

BufferingStatsdDataFactory::decrement (   $key)
Parameters
string$key
Returns
void

Definition at line 115 of file BufferingStatsdDataFactory.php.

◆ gauge()

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

Definition at line 81 of file BufferingStatsdDataFactory.php.

◆ getData()

BufferingStatsdDataFactory::getData ( )
Since
1.30
Returns
StatsdData[]

Implements IBufferingStatsdDataFactory.

Definition at line 186 of file BufferingStatsdDataFactory.php.

References produceStatsdData().

◆ getDataCount()

BufferingStatsdDataFactory::getDataCount ( )

Return the number of buffered statsd data entries.

Returns
int
Since
1.31

Implements IBufferingStatsdDataFactory.

Definition at line 206 of file BufferingStatsdDataFactory.php.

◆ hasData()

BufferingStatsdDataFactory::hasData ( )

Check whether this data factory has any buffered data.

Returns
bool

Implements IBufferingStatsdDataFactory.

Definition at line 178 of file BufferingStatsdDataFactory.php.

References $buffer.

◆ increment()

BufferingStatsdDataFactory::increment (   $key)
Parameters
string$key
Returns
void

Definition at line 104 of file BufferingStatsdDataFactory.php.

◆ normalizeMetricKey()

static BufferingStatsdDataFactory::normalizeMetricKey (   $key)
staticprivate

Normalize a metric key for StatsD.

The following are changes you may rely on:

  • Non-alphanumerical characters are converted to underscores.
  • Empty segments are removed, e.g. "foo..bar" becomes "foo.bar". This is mainly for StatsD-Graphite-Carbon setups where each segment is a directory and must have a non-empty name.
  • Deliberately invalid input that looks like __METHOD__ (namespaced PHP class and method) is changed from "\\\\Namespace\\\\Class::method" to "Namespace_Class.method". This is used by ProfilerOutputStats.
Parameters
string$key
Returns
string

Definition at line 150 of file BufferingStatsdDataFactory.php.

Referenced by produceStatsdData().

◆ produceStatsdData()

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

Definition at line 157 of file BufferingStatsdDataFactory.php.

References normalizeMetricKey().

Referenced by getData().

◆ set()

BufferingStatsdDataFactory::set (   $key,
  $value 
)
Parameters
string$key
float | int$value
Returns
void

Definition at line 93 of file BufferingStatsdDataFactory.php.

◆ setEnabled()

BufferingStatsdDataFactory::setEnabled (   $enabled)

Set collection enable status.

Parameters
bool$enabledWill collection be enabled?
Returns
void

Implements IBufferingStatsdDataFactory.

Definition at line 210 of file BufferingStatsdDataFactory.php.

References $enabled.

◆ timing()

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

Definition at line 69 of file BufferingStatsdDataFactory.php.

◆ updateCount()

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

Definition at line 127 of file BufferingStatsdDataFactory.php.

Member Data Documentation

◆ $buffer

array BufferingStatsdDataFactory::$buffer = []
protected

Definition at line 49 of file BufferingStatsdDataFactory.php.

Referenced by hasData().

◆ $enabled

bool BufferingStatsdDataFactory::$enabled = true
protected

Definition at line 51 of file BufferingStatsdDataFactory.php.

Referenced by setEnabled().

◆ $prefix

string BufferingStatsdDataFactory::$prefix
private

Definition at line 53 of file BufferingStatsdDataFactory.php.

Referenced by __construct().


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