3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
21 use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface
;
22 use Liuggio\StatsdClient\Entity\StatsdDataInterface
;
25 * Proxy to prefix metric keys sent to a StatsdDataFactoryInterface
29 class PrefixingStatsdDataFactoryProxy
implements StatsdDataFactoryInterface
{
37 * @var StatsdDataFactoryInterface
42 * @param StatsdDataFactoryInterface $factory
43 * @param string $prefix
45 public function __construct(
46 StatsdDataFactoryInterface
$factory,
49 $this->factory
= $factory;
50 $this->prefix
= rtrim( $prefix, '.' );
57 private function addPrefixToKey( $key ) {
58 return $this->prefix
. '.' . $key;
61 public function timing( $key, $time ) {
62 return $this->factory
->timing( $this->addPrefixToKey( $key ), $time );
65 public function gauge( $key, $value ) {
66 return $this->factory
->gauge( $this->addPrefixToKey( $key ), $value );
69 public function set( $key, $value ) {
70 return $this->factory
->set( $this->addPrefixToKey( $key ), $value );
73 public function increment( $key ) {
74 return $this->factory
->increment( $this->addPrefixToKey( $key ) );
77 public function decrement( $key ) {
78 return $this->factory
->decrement( $this->addPrefixToKey( $key ) );
81 public function updateCount( $key, $delta ) {
82 return $this->factory
->updateCount( $this->addPrefixToKey( $key ), $delta );
85 public function produceStatsdData(
88 $metric = StatsdDataInterface
::STATSD_METRIC_COUNT
90 return $this->factory
->produceStatsdData(
91 $this->addPrefixToKey( $key ),