MediaWiki master
OutputFormats.php
Go to the documentation of this file.
1<?php
7declare( strict_types=1 );
8
9namespace Wikimedia\Stats;
10
19
27
28 public const NULL = 1;
29 public const STATSD = 2;
30 public const DOGSTATSD = 3;
31
32 private const SUPPORTED_FORMATS = [
33 'null' => self::NULL,
34 'statsd' => self::STATSD,
35 'dogstatsd' => self::DOGSTATSD
36 ];
37
44 public static function getFormatFromString( string $format ): int {
45 if ( self::SUPPORTED_FORMATS[$format] ?? false ) {
46 return self::SUPPORTED_FORMATS[$format];
47 }
49 "Format '" . $format . "' not supported. Expected one of "
50 . json_encode( array_keys( self::SUPPORTED_FORMATS ) )
51 );
52 }
53
60 public static function getNewFormatter( int $format ): FormatterInterface {
61 switch ( $format ) {
62 case self::DOGSTATSD:
63 return new DogStatsdFormatter();
64 case self::STATSD:
65 return new StatsdFormatter();
66 case self::NULL:
67 return new NullFormatter();
68 default:
70 "Unsupported metrics format '{$format}' - See OutputFormats::class."
71 );
72 }
73 }
74
84 public static function getNewEmitter(
85 string $prefix,
86 StatsCache $cache,
87 FormatterInterface $formatter,
88 ?string $target = null
90 $formatterClass = get_class( $formatter );
91 switch ( $formatterClass ) {
92 case StatsdFormatter::class:
93 case DogStatsdFormatter::class:
94 return new UDPEmitter( $prefix, $cache, $formatter, $target );
95 case NullFormatter::class:
96 return new NullEmitter;
97 default:
98 throw new UnsupportedFormatException( "Unsupported metrics formatter '{$formatterClass}'" );
99 }
100 }
101}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:68
Metrics Null Emitter Implementation.
Metrics UDP Emitter Implementation.
DogStatsD Wire Format Implementation.
Null Formatter Implementation.
StatsD Wire Format Implementation.
Metrics Format and Output Helpers.
static getNewFormatter(int $format)
Returns an instance of the requested formatter.
static getFormatFromString(string $format)
Convert friendly format name to integer.
static getNewEmitter(string $prefix, StatsCache $cache, FormatterInterface $formatter, ?string $target=null)
Returns an emitter instance appropriate the formatter instance.
Singleton cache for Metric instances.