Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7487650
StatsdFormatter.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
StatsdFormatter.php
View Options
<?php
/**
* @license GPL-2.0-or-later
* @file
*/
declare
(
strict_types
=
1
);
namespace
Wikimedia\Stats\Formatters
;
use
Wikimedia\Stats\Metrics\MetricInterface
;
/**
* StatsD Wire Format Implementation
*
* @author Cole White
* @since 1.41
*/
class
StatsdFormatter
implements
FormatterInterface
{
/** @inheritDoc */
public
function
getFormattedSamples
(
string
$prefix
,
MetricInterface
$metric
):
array
{
$output
=
[];
// append component to prefix if set
if
(
$metric
->
getComponent
()
!==
''
)
{
$prefix
.=
".{$metric->getComponent()}"
;
}
// Metrics used in HistogramMetrics are not compatible with StatsD
if
(
$metric
->
isHistogram
()
)
{
return
[];
}
foreach
(
$metric
->
getSamples
()
as
$sample
)
{
// dot-separate prefix, component, name, and label values `prefix.component.name.value1.value2`
$stat
=
implode
(
'.'
,
[
$prefix
,
$metric
->
getName
(),
...
$sample
->
getLabelValues
()
]
);
// merge value with separator `:42`
$value
=
':'
.
$sample
->
getValue
();
// merge type indicator with separator `|c`
$type
=
'|'
.
$metric
->
getTypeIndicator
();
// blank string if samplerate is 1.0, otherwise add samplerate indicator `|@0.5`
$sampleRate
=
$metric
->
getSampleRate
()
!==
1.0
?
'|@'
.
$metric
->
getSampleRate
()
:
''
;
// combine and append to output `prefix.component.name.value1.value2:42|c|@0.5`
$output
[]
=
$stat
.
$value
.
$type
.
$sampleRate
;
}
return
$output
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Nov 23, 16:14 (6 d, 49 m ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
53/6a/b9cd0cbf16e8e52cd486c93df6ed
Default Alt Text
StatsdFormatter.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment