MediaWiki REL1_41
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:
82 throw new UnsupportedFormatException( 'Unsupported metrics format. Got format: ' . $format );
83 }
84 }
85
95 public static function getNewEmitter(
96 string $prefix,
97 StatsCache $cache,
98 FormatterInterface $formatter,
99 string $target = null
101 switch ( get_class( $formatter ) ) {
102 case StatsdFormatter::class:
103 case DogStatsdFormatter::class:
104 return new UDPEmitter( $prefix, $cache, $formatter, $target );
105 case NullFormatter::class:
106 return new NullEmitter;
107 default:
109 'Unsupported metrics format. Got format: ' . get_class( $formatter )
110 );
111 }
112 }
113}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:88
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 getNewEmitter(string $prefix, StatsCache $cache, FormatterInterface $formatter, string $target=null)
Returns an emitter instance appropriate the formatter instance.
static getNewFormatter(int $format)
Returns an instance of the requested formatter.
static getFormatFromString(string $format)
Convert friendly format name to integer.
Singleton cache for Metric instances.