MediaWiki 1.42.0
Wikimedia\Stats\StatsFactory Class Reference

StatsFactory Implementation. More...

Public Member Functions

 __construct (StatsCache $cache, EmitterInterface $emitter, LoggerInterface $logger, string $component='')
 StatsFactory builds, configures, and caches Metrics.
 
 addStaticLabel (string $key, string $value)
 Adds a label key-value pair to all metrics created by this StatsFactory instance.
 
 flush ()
 Send all buffered metrics to the target and destroy the cache.
 
 getCounter (string $name)
 Makes a new CounterMetric or fetches one from cache.
 
 getGauge (string $name)
 Makes a new GaugeMetric or fetches one from cache.
 
 getTiming (string $name)
 Makes a new TimingMetric or fetches one from cache.
 
 withComponent (string $component)
 Returns a new StatsFactory instance prefixed by component.
 
 withStatsdDataFactory (?IBufferingStatsdDataFactory $statsdDataFactory)
 

Static Public Member Functions

static newNull ()
 Returns an instance of StatsFactory as a NULL value object as a default for consumer code to fall back to.
 

Detailed Description

StatsFactory Implementation.

This is the primary interface for validating metrics definitions caching defined metrics, and returning metric instances from cache if previously defined.

Author
Cole White
Since
1.41

Definition at line 49 of file StatsFactory.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Stats\StatsFactory::__construct ( StatsCache $cache,
EmitterInterface $emitter,
LoggerInterface $logger,
string $component = '' )

StatsFactory builds, configures, and caches Metrics.

Parameters
StatsCache$cache
EmitterInterface$emitter
LoggerInterface$logger
string$component

Definition at line 80 of file StatsFactory.php.

References Wikimedia\Stats\StatsUtils\normalizeString().

Member Function Documentation

◆ addStaticLabel()

Wikimedia\Stats\StatsFactory::addStaticLabel ( string $key,
string $value )

Adds a label key-value pair to all metrics created by this StatsFactory instance.

Note that the order in which labels are added is significant for StatsD output.

Example:

$statsFactory->withComponent( 'demo' )
->addStaticLabel( 'first', 'foo' )
->addStaticLabel( 'second', 'bar' )
->getCounter( 'testMetric_total' )
->setLabel( 'third', 'baz' )
->increment();

outputs statsd: "mediawiki.demo.testMetric_total.foo.bar.baz" outputs prometheus: "mediawiki_demo_testMetric_total{first='foo',second='bar',third='baz'}

Parameters
string$key
string$value
Returns
$this

Definition at line 123 of file StatsFactory.php.

◆ flush()

Wikimedia\Stats\StatsFactory::flush ( )

Send all buffered metrics to the target and destroy the cache.

Definition at line 181 of file StatsFactory.php.

◆ getCounter()

Wikimedia\Stats\StatsFactory::getCounter ( string $name)

Makes a new CounterMetric or fetches one from cache.

If a collision occurs, returns a NullMetric to suppress exceptions.

Parameters
string$name
Returns
CounterMetric|NullMetric

Definition at line 150 of file StatsFactory.php.

◆ getGauge()

Wikimedia\Stats\StatsFactory::getGauge ( string $name)

Makes a new GaugeMetric or fetches one from cache.

If a collision occurs, returns a NullMetric to suppress exceptions.

Parameters
string$name
Returns
GaugeMetric|NullMetric

Definition at line 162 of file StatsFactory.php.

◆ getTiming()

Wikimedia\Stats\StatsFactory::getTiming ( string $name)

Makes a new TimingMetric or fetches one from cache.

If a collision occurs, returns a NullMetric to suppress exceptions.

Parameters
string$name
Returns
TimingMetric|NullMetric

Definition at line 174 of file StatsFactory.php.

◆ newNull()

static Wikimedia\Stats\StatsFactory::newNull ( )
static

Returns an instance of StatsFactory as a NULL value object as a default for consumer code to fall back to.

This can also be used in tests environment where we don't need the full UDP emitter object.

Since
1.42
Returns
self

Definition at line 242 of file StatsFactory.php.

◆ withComponent()

Wikimedia\Stats\StatsFactory::withComponent ( string $component)

Returns a new StatsFactory instance prefixed by component.

Parameters
string$component
Returns
StatsFactory

Definition at line 98 of file StatsFactory.php.

◆ withStatsdDataFactory()

Wikimedia\Stats\StatsFactory::withStatsdDataFactory ( ?IBufferingStatsdDataFactory $statsdDataFactory)

Definition at line 137 of file StatsFactory.php.


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