MediaWiki
REL1_41
StatsdFormatter.php
Go to the documentation of this file.
1
<?php
20
declare( strict_types=1 );
21
22
namespace
Wikimedia\Stats\Formatters
;
23
24
use
Wikimedia\Stats\Metrics\MetricInterface
;
25
32
class
StatsdFormatter
implements
FormatterInterface
{
34
public
function
getFormattedSamples
(
string
$prefix,
MetricInterface
$metric ): array {
35
$output = [];
36
37
// append component to prefix if set
38
if
( $metric->
getComponent
() !==
''
) {
39
$prefix .=
".{$metric->getComponent()}"
;
40
}
41
42
foreach
( $metric->
getSamples
() as $sample ) {
43
// dot-separate prefix, component, name, and label values `prefix.component.name.value1.value2`
44
$stat = implode(
'.'
, array_merge( [ $prefix, $metric->
getName
() ], $sample->getLabelValues() ) );
45
46
// merge value with separator `:42`
47
$value =
':'
. $sample->getValue();
48
49
// merge type indicator with separator `|c`
50
$type =
'|'
. $metric->
getTypeIndicator
();
51
52
// blank string if samplerate is 1.0, otherwise add samplerate indicator `|@0.5`
53
$sampleRate = $metric->
getSampleRate
() !== 1.0 ?
'|@'
. $metric->
getSampleRate
() :
''
;
54
55
// combine and append to output `prefix.component.name.value1.value2:42|c|@0.5`
56
$output[] = $stat . $value . $type . $sampleRate;
57
}
58
return
$output;
59
}
60
}
Wikimedia\Stats\Formatters\StatsdFormatter
StatsD Wire Format Implementation.
Definition
StatsdFormatter.php:32
Wikimedia\Stats\Formatters\StatsdFormatter\getFormattedSamples
getFormattedSamples(string $prefix, MetricInterface $metric)
Renders metric to line format.string[]
Definition
StatsdFormatter.php:34
Wikimedia\Stats\Formatters\FormatterInterface
Metrics Formatter Interface.
Definition
FormatterInterface.php:30
Wikimedia\Stats\Metrics\MetricInterface
Metric Interface.
Definition
MetricInterface.php:31
Wikimedia\Stats\Metrics\MetricInterface\getSamples
getSamples()
Returns subset of samples corresponding to sample rate setting.
Wikimedia\Stats\Metrics\MetricInterface\getTypeIndicator
getTypeIndicator()
Wikimedia\Stats\Metrics\MetricInterface\getSampleRate
getSampleRate()
Wikimedia\Stats\Metrics\MetricInterface\getComponent
getComponent()
Wikimedia\Stats\Metrics\MetricInterface\getName
getName()
Wikimedia\Stats\Formatters
Definition
DogStatsdFormatter.php:22
includes
libs
Stats
Formatters
StatsdFormatter.php
Generated on Sat Nov 23 2024 08:23:57 for MediaWiki by
1.10.0