MediaWiki master
Wikimedia\Stats\Metrics\BaseMetric Class Reference

Base Metric Implementation V1. More...

Inherits Wikimedia\Stats\Metrics\BaseMetricInterface.

Collaboration diagram for Wikimedia\Stats\Metrics\BaseMetric:

Public Member Functions

 __construct (string $component, string $name)
 
Parameters
string$componentThe component this metric will track.
string$nameThe Metric Name.

 
 addLabel (string $key, string $value)
 Add a label with key => value.Note that the order in which labels are added is significant for StatsD output.Static Labels always appear first.Example:

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

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

Parameters
string$key
string$value
Returns
void

 
 addSample (Sample $sample)
 Records a Metric Sample.
Parameters
Sample$sample
Returns
void

 
 clearLabels ()
 Clears the working labels.
Returns
void

 
 getComponent ()
 Returns the Metric Component.
Returns
string

 
 getLabelKeys ()
 
 getLabelValues ()
 Combines the provided associative array of labels with the associative array of staticLabels and returns the values in the order of labelKeys.
 
 getName ()
 Returns the Metric Name.
Returns
string

 
 getSampleCount ()
 Returns a count of samples recorded by the metric.
Returns
int

 
 getSampleRate ()
 Returns the configured sample rate.
Returns
float

 
 getSamples ()
 Returns subset of samples corresponding to sample rate setting.
Returns
Sample[]

 
 getStatsdDataFactory ()
 Gets StatsD Data Factory instance or null.
 
 getStatsdNamespaces ()
 Returns the configured legacy StatsD namespaces.
Returns
string[]

 
 setSampleRate (float $sampleRate)
 Sets the sample rate.
Parameters
float$sampleRate

 
 setStatsdNamespaces ( $statsdNamespaces)
 Validates and sets legacy StatsD namespaces.
Parameters
string | string[]$statsdNamespaces
Returns
void

 
 withStaticLabels (array $labelKeys, array $labelValues)
 Configures the metric with static labels.
Parameters
string[]$labelKeys
string[]$labelValues
Returns
BaseMetricInterface

 
 withStatsdDataFactory ( $statsdDataFactory)
 
- Public Member Functions inherited from Wikimedia\Stats\Metrics\BaseMetricInterface
 withStatsdDataFactory (IBufferingStatsdDataFactory $statsdDataFactory)
 StatsD Data Factory instance to copy metrics to.
 

Detailed Description

Base Metric Implementation V1.

Implements shared Metric functionality:

  • Label validation and handling
  • Sample rate validation and handling
  • Sample generation
  • Common properties
  • StatsD transition support
Author
Cole White
Since
1.41

Definition at line 43 of file BaseMetric.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Stats\Metrics\BaseMetric::__construct ( string  $component,
string  $name 
)

Parameters
string$componentThe component this metric will track.
string$nameThe Metric Name.

Implements Wikimedia\Stats\Metrics\BaseMetricInterface.

Definition at line 73 of file BaseMetric.php.

References Wikimedia\Stats\StatsUtils\normalizeString().

Member Function Documentation

◆ addLabel()

Wikimedia\Stats\Metrics\BaseMetric::addLabel ( string  $key,
string  $value 
)

Add a label with key => value.Note that the order in which labels are added is significant for StatsD output.Static Labels always appear first.Example:

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

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

Parameters
string$key
string$value
Returns
void

Implements Wikimedia\Stats\Metrics\BaseMetricInterface.

Definition at line 121 of file BaseMetric.php.

◆ addSample()

Wikimedia\Stats\Metrics\BaseMetric::addSample ( Sample  $sample)

Records a Metric Sample.

Parameters
Sample$sample
Returns
void

Implements Wikimedia\Stats\Metrics\BaseMetricInterface.

Definition at line 79 of file BaseMetric.php.

◆ clearLabels()

Wikimedia\Stats\Metrics\BaseMetric::clearLabels ( )

Clears the working labels.

Returns
void

Implements Wikimedia\Stats\Metrics\BaseMetricInterface.

Definition at line 216 of file BaseMetric.php.

◆ getComponent()

Wikimedia\Stats\Metrics\BaseMetric::getComponent ( )

Returns the Metric Component.

Returns
string

Implements Wikimedia\Stats\Metrics\BaseMetricInterface.

Definition at line 221 of file BaseMetric.php.

◆ getLabelKeys()

Wikimedia\Stats\Metrics\BaseMetric::getLabelKeys ( )
Returns
string[]

Implements Wikimedia\Stats\Metrics\BaseMetricInterface.

Definition at line 187 of file BaseMetric.php.

◆ getLabelValues()

Wikimedia\Stats\Metrics\BaseMetric::getLabelValues ( )

Combines the provided associative array of labels with the associative array of staticLabels and returns the values in the order of labelKeys.

Returns
string[]

Implements Wikimedia\Stats\Metrics\BaseMetricInterface.

Definition at line 198 of file BaseMetric.php.

◆ getName()

Wikimedia\Stats\Metrics\BaseMetric::getName ( )

Returns the Metric Name.

Returns
string

Implements Wikimedia\Stats\Metrics\BaseMetricInterface.

Definition at line 94 of file BaseMetric.php.

◆ getSampleCount()

Wikimedia\Stats\Metrics\BaseMetric::getSampleCount ( )

Returns a count of samples recorded by the metric.

Returns
int

Implements Wikimedia\Stats\Metrics\BaseMetricInterface.

Definition at line 109 of file BaseMetric.php.

◆ getSampleRate()

Wikimedia\Stats\Metrics\BaseMetric::getSampleRate ( )

Returns the configured sample rate.

Returns
float

Implements Wikimedia\Stats\Metrics\BaseMetricInterface.

Definition at line 99 of file BaseMetric.php.

◆ getSamples()

Wikimedia\Stats\Metrics\BaseMetric::getSamples ( )

Returns subset of samples corresponding to sample rate setting.

Returns
Sample[]

Implements Wikimedia\Stats\Metrics\BaseMetricInterface.

Definition at line 104 of file BaseMetric.php.

◆ getStatsdDataFactory()

Wikimedia\Stats\Metrics\BaseMetric::getStatsdDataFactory ( )

Gets StatsD Data Factory instance or null.

Implements Wikimedia\Stats\Metrics\BaseMetricInterface.

Definition at line 130 of file BaseMetric.php.

◆ getStatsdNamespaces()

Wikimedia\Stats\Metrics\BaseMetric::getStatsdNamespaces ( )

Returns the configured legacy StatsD namespaces.

Returns
string[]

Implements Wikimedia\Stats\Metrics\BaseMetricInterface.

Definition at line 159 of file BaseMetric.php.

◆ setSampleRate()

Wikimedia\Stats\Metrics\BaseMetric::setSampleRate ( float  $sampleRate)

Sets the sample rate.

Parameters
float$sampleRate

Implements Wikimedia\Stats\Metrics\BaseMetricInterface.

Definition at line 84 of file BaseMetric.php.

◆ setStatsdNamespaces()

Wikimedia\Stats\Metrics\BaseMetric::setStatsdNamespaces (   $statsdNamespaces)

Validates and sets legacy StatsD namespaces.

Parameters
string | string[]$statsdNamespaces
Returns
void

Implements Wikimedia\Stats\Metrics\BaseMetricInterface.

Definition at line 141 of file BaseMetric.php.

◆ withStaticLabels()

Wikimedia\Stats\Metrics\BaseMetric::withStaticLabels ( array  $labelKeys,
array  $labelValues 
)

Configures the metric with static labels.

Parameters
string[]$labelKeys
string[]$labelValues
Returns
BaseMetricInterface

Implements Wikimedia\Stats\Metrics\BaseMetricInterface.

Definition at line 114 of file BaseMetric.php.

◆ withStatsdDataFactory()

Wikimedia\Stats\Metrics\BaseMetric::withStatsdDataFactory (   $statsdDataFactory)

Definition at line 135 of file BaseMetric.php.


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