MediaWiki master
OutputFormats.php
Go to the documentation of this file.
1<?php
20declare( strict_types=1 );
21
22namespace Wikimedia\Stats;
23
32
40
41 public const NULL = 1;
42 public const STATSD = 2;
43 public const DOGSTATSD = 3;
44
45 private const SUPPORTED_FORMATS = [
46 'null' => self::NULL,
47 'statsd' => self::STATSD,
48 'dogstatsd' => self::DOGSTATSD
49 ];
50
57 public static function getFormatFromString( string $format ): int {
58 if ( self::SUPPORTED_FORMATS[$format] ?? false ) {
59 return self::SUPPORTED_FORMATS[$format];
60 }
62 "Format '" . $format . "' not supported. Expected one of "
63 . json_encode( array_keys( self::SUPPORTED_FORMATS ) )
64 );
65 }
66
73 public static function getNewFormatter( int $format ): FormatterInterface {
74 switch ( $format ) {
75 case self::DOGSTATSD:
76 return new DogStatsdFormatter();
77 case self::STATSD:
78 return new StatsdFormatter();
79 case self::NULL:
80 return new NullFormatter();
81 default:
83 "Unsupported metrics format '{$format}' - See OutputFormats::class."
84 );
85 }
86 }
87
97 public static function getNewEmitter(
98 string $prefix,
99 StatsCache $cache,
100 FormatterInterface $formatter,
101 ?string $target = null
103 $formatterClass = get_class( $formatter );
104 switch ( $formatterClass ) {
105 case StatsdFormatter::class:
106 case DogStatsdFormatter::class:
107 return new UDPEmitter( $prefix, $cache, $formatter, $target );
108 case NullFormatter::class:
109 return new NullEmitter;
110 default:
111 throw new UnsupportedFormatException( "Unsupported metrics formatter '{$formatterClass}'" );
112 }
113 }
114}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:82
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.