MediaWiki master
PrefixingStatsdDataFactoryProxy.php
Go to the documentation of this file.
1<?php
7namespace Wikimedia\Stats;
8
9use Liuggio\StatsdClient\Entity\StatsdDataInterface;
10use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
11
27class PrefixingStatsdDataFactoryProxy implements StatsdDataFactoryInterface {
28
32 private $prefix;
33
37 private $factory;
38
43 public function __construct(
44 StatsdDataFactoryInterface $factory,
45 $prefix
46 ) {
47 $this->factory = $factory;
48 $this->prefix = rtrim( $prefix, '.' );
49 }
50
55 private function addPrefixToKey( $key ) {
56 return $this->prefix . '.' . $key;
57 }
58
60 public function timing( $key, $time ) {
61 return $this->factory->timing( $this->addPrefixToKey( $key ), $time );
62 }
63
65 public function gauge( $key, $value ) {
66 return $this->factory->gauge( $this->addPrefixToKey( $key ), $value );
67 }
68
70 public function set( $key, $value ) {
71 return $this->factory->set( $this->addPrefixToKey( $key ), $value );
72 }
73
75 public function increment( $key ) {
76 return $this->factory->increment( $this->addPrefixToKey( $key ) );
77 }
78
80 public function decrement( $key ) {
81 return $this->factory->decrement( $this->addPrefixToKey( $key ) );
82 }
83
85 public function updateCount( $key, $delta ) {
86 return $this->factory->updateCount( $this->addPrefixToKey( $key ), $delta );
87 }
88
90 public function produceStatsdData(
91 $key,
92 $value = 1,
93 $metric = StatsdDataInterface::STATSD_METRIC_COUNT
94 ) {
95 return $this->factory->produceStatsdData(
96 $this->addPrefixToKey( $key ),
97 $value,
98 $metric
99 );
100 }
101}
102
104class_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)