MediaWiki master
PrefixingStatsdDataFactoryProxy.php
Go to the documentation of this file.
1<?php
21namespace Wikimedia\Stats;
22
23use Liuggio\StatsdClient\Entity\StatsdDataInterface;
24use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
25
41class PrefixingStatsdDataFactoryProxy implements StatsdDataFactoryInterface {
42
46 private $prefix;
47
51 private $factory;
52
57 public function __construct(
58 StatsdDataFactoryInterface $factory,
59 $prefix
60 ) {
61 $this->factory = $factory;
62 $this->prefix = rtrim( $prefix, '.' );
63 }
64
69 private function addPrefixToKey( $key ) {
70 return $this->prefix . '.' . $key;
71 }
72
73 public function timing( $key, $time ) {
74 return $this->factory->timing( $this->addPrefixToKey( $key ), $time );
75 }
76
77 public function gauge( $key, $value ) {
78 return $this->factory->gauge( $this->addPrefixToKey( $key ), $value );
79 }
80
81 public function set( $key, $value ) {
82 return $this->factory->set( $this->addPrefixToKey( $key ), $value );
83 }
84
85 public function increment( $key ) {
86 return $this->factory->increment( $this->addPrefixToKey( $key ) );
87 }
88
89 public function decrement( $key ) {
90 return $this->factory->decrement( $this->addPrefixToKey( $key ) );
91 }
92
93 public function updateCount( $key, $delta ) {
94 return $this->factory->updateCount( $this->addPrefixToKey( $key ), $delta );
95 }
96
97 public function produceStatsdData(
98 $key,
99 $value = 1,
100 $metric = StatsdDataInterface::STATSD_METRIC_COUNT
101 ) {
102 return $this->factory->produceStatsdData(
103 $this->addPrefixToKey( $key ),
104 $value,
105 $metric
106 );
107 }
108}
109
111class_alias( PrefixingStatsdDataFactoryProxy::class, 'PrefixingStatsdDataFactoryProxy' );
Proxy to prefix metric keys sent to a StatsdDataFactoryInterface.
__construct(StatsdDataFactoryInterface $factory, $prefix)
produceStatsdData( $key, $value=1, $metric=StatsdDataInterface::STATSD_METRIC_COUNT)