MediaWiki master
Wikimedia\Stats\Metrics\TimingMetric Class Reference

Timing Metric Implementation. More...

Inherits Wikimedia\Stats\Metrics\MetricInterface.

Collaboration diagram for Wikimedia\Stats\Metrics\TimingMetric:

Public Member Functions

 __construct ( $baseMetric, $logger)
 
 copyToStatsdAt ( $statsdNamespaces)
 Copies metric operation to StatsD at provided namespace.Takes a namespace or multiple namespaces.
Parameters
string | string[]$statsdNamespaces
Returns
CounterMetric|GaugeMetric|TimingMetric|NullMetric

 
 fresh ()
 Returns metric with cleared labels.
Returns
CounterMetric|GaugeMetric|TimingMetric|NullMetric

 
 getComponent ()
 
Returns
string

 
 getLabelKeys ()
 Returns the list of defined label keys.
Returns
string[]

 
 getName ()
 
Returns
string

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

 
 getSampleRate ()
 
Returns
float

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

 
 getTypeIndicator ()
 
Returns
string

 
 observe (float $milliseconds)
 Records a previously calculated observation in milliseconds.
 
 observeNanoseconds (float $nanoseconds)
 Record a previously calculated observation in nanoseconds.
 
 observeSeconds (float $seconds)
 Record a previously calculated observation in seconds.
 
 setLabel (string $key, string $value)
 Adds a label $key with $value.Note that the order in which labels are added is significant for StatsD output.Example:

$statsFactory->getCounter( 'testMetric_total' )
->setLabel( 'first', 'foo' )
->setLabel( 'second', 'bar' )
->increment();

statsd: "mediawiki.testMetric_total.foo.bar" prometheus: "mediawiki_testMetric_total{ first='foo', second='bar' }

Parameters
string$key
string$value
Returns
CounterMetric|GaugeMetric|TimingMetric|NullMetric

 
 setSampleRate (float $sampleRate)
 Sets sample rate on a new metric instance.
Parameters
float$sampleRate
Returns
CounterMetric|GaugeMetric|TimingMetric|NullMetric

 
 start ()
 Starts a timer.
 
 stop ()
 Stops a running timer.
 
- Public Member Functions inherited from Wikimedia\Stats\Metrics\MetricInterface
 __construct (BaseMetricInterface $baseMetric, LoggerInterface $logger)
 

Detailed Description

Timing Metric Implementation.

Timing metrics track duration data which can be broken into histograms. They are identified by type "ms".

Author
Cole White
Since
1.38

Definition at line 38 of file TimingMetric.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Stats\Metrics\TimingMetric::__construct ( $baseMetric,
$logger )

Definition at line 59 of file TimingMetric.php.

Member Function Documentation

◆ copyToStatsdAt()

Wikimedia\Stats\Metrics\TimingMetric::copyToStatsdAt ( $statsdNamespaces)

Copies metric operation to StatsD at provided namespace.Takes a namespace or multiple namespaces.

Parameters
string | string[]$statsdNamespaces
Returns
CounterMetric|GaugeMetric|TimingMetric|NullMetric

Implements Wikimedia\Stats\Metrics\MetricInterface.

Definition at line 201 of file TimingMetric.php.

◆ fresh()

Wikimedia\Stats\Metrics\TimingMetric::fresh ( )

Returns metric with cleared labels.

Returns
CounterMetric|GaugeMetric|TimingMetric|NullMetric

Implements Wikimedia\Stats\Metrics\MetricInterface.

Definition at line 213 of file TimingMetric.php.

◆ getComponent()

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

Returns
string

Implements Wikimedia\Stats\Metrics\MetricInterface.

Definition at line 147 of file TimingMetric.php.

◆ getLabelKeys()

Wikimedia\Stats\Metrics\TimingMetric::getLabelKeys ( )

Returns the list of defined label keys.

Returns
string[]

Implements Wikimedia\Stats\Metrics\MetricInterface.

Definition at line 184 of file TimingMetric.php.

◆ getName()

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

Returns
string

Implements Wikimedia\Stats\Metrics\MetricInterface.

Definition at line 142 of file TimingMetric.php.

◆ getSampleCount()

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

Returns a count of samples recorded by the metric.

Returns
int

Implements Wikimedia\Stats\Metrics\MetricInterface.

Definition at line 162 of file TimingMetric.php.

◆ getSampleRate()

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

Returns
float

Implements Wikimedia\Stats\Metrics\MetricInterface.

Definition at line 167 of file TimingMetric.php.

◆ getSamples()

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

Returns subset of samples corresponding to sample rate setting.

Returns
Sample[]

Implements Wikimedia\Stats\Metrics\MetricInterface.

Definition at line 157 of file TimingMetric.php.

◆ getTypeIndicator()

Wikimedia\Stats\Metrics\TimingMetric::getTypeIndicator ( )

Returns
string

Implements Wikimedia\Stats\Metrics\MetricInterface.

Definition at line 152 of file TimingMetric.php.

◆ observe()

Wikimedia\Stats\Metrics\TimingMetric::observe ( float $milliseconds)

Records a previously calculated observation in milliseconds.

Parameters
float$milliseconds
Returns
void

Definition at line 93 of file TimingMetric.php.

◆ observeNanoseconds()

Wikimedia\Stats\Metrics\TimingMetric::observeNanoseconds ( float $nanoseconds)

Record a previously calculated observation in nanoseconds.

Common usage:

$startTime = hrtime( true )
# work to be measured...
$metric->observeNanoseconds( hrtime( true ) - $startTime )
Parameters
float$nanoseconds
Returns
void
Since
1.43

Definition at line 137 of file TimingMetric.php.

◆ observeSeconds()

Wikimedia\Stats\Metrics\TimingMetric::observeSeconds ( float $seconds)

Record a previously calculated observation in seconds.

Common usage:

$startTime = microtime( true )
# work to be measured...
$metric->observeSeconds( microtime( true ) - $startTime )
Parameters
float$seconds
Returns
void
Since
1.43

Definition at line 120 of file TimingMetric.php.

◆ setLabel()

Wikimedia\Stats\Metrics\TimingMetric::setLabel ( string $key,
string $value )

Adds a label $key with $value.Note that the order in which labels are added is significant for StatsD output.Example:

$statsFactory->getCounter( 'testMetric_total' )
->setLabel( 'first', 'foo' )
->setLabel( 'second', 'bar' )
->increment();

statsd: "mediawiki.testMetric_total.foo.bar" prometheus: "mediawiki_testMetric_total{ first='foo', second='bar' }

Parameters
string$key
string$value
Returns
CounterMetric|GaugeMetric|TimingMetric|NullMetric

Implements Wikimedia\Stats\Metrics\MetricInterface.

Definition at line 189 of file TimingMetric.php.

◆ setSampleRate()

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

Sets sample rate on a new metric instance.

Parameters
float$sampleRate
Returns
CounterMetric|GaugeMetric|TimingMetric|NullMetric

Implements Wikimedia\Stats\Metrics\MetricInterface.

Definition at line 172 of file TimingMetric.php.

◆ start()

Wikimedia\Stats\Metrics\TimingMetric::start ( )

Starts a timer.

Returns
void

Definition at line 69 of file TimingMetric.php.

◆ stop()

Wikimedia\Stats\Metrics\TimingMetric::stop ( )

Stops a running timer.

Returns
void

Definition at line 78 of file TimingMetric.php.


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