StatsdClient::setNamespace()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Werkspot\Bundle\StatsdBundle\Client;
4
5
use Domnikl\Statsd\Client;
6
use Domnikl\Statsd\Connection;
7
8
class StatsdClient implements StatsdClientInterface
9
{
10
    /**
11
     * @var Client
12
     */
13
    private $client;
14
15
    /**
16
     * @param Connection $connection
17
     * @param string $namespace
18
     */
19
    public function __construct(Connection $connection, $namespace = '')
20
    {
21
        $this->client = new Client($connection, $namespace);
22
    }
23
24
    /**
25
     * increments the key by 1
26
     *
27
     * @param string $key
28
     * @param int $sampleRate
29
     *
30
     * @return void
31
     */
32
    public function increment($key, $sampleRate = 1)
33
    {
34
        $this->client->increment($key, $sampleRate);
35
    }
36
37
    /**
38
     * decrements the key by 1
39
     *
40
     * @param string $key
41
     * @param int $sampleRate
42
     *
43
     * @return void
44
     */
45
    public function decrement($key, $sampleRate = 1)
46
    {
47
        $this->client->decrement($key, $sampleRate);
48
    }
49
    /**
50
     * sends a count to statsd
51
     *
52
     * @param string $key
53
     * @param int $value
54
     * @param int $sampleRate (optional) the default is 1
55
     *
56
     * @return void
57
     */
58
    public function count($key, $value, $sampleRate = 1)
59
    {
60
        $this->client->count($key, $value, $sampleRate);
61
    }
62
63
    /**
64
     * sends a timing to statsd (in ms)
65
     *
66
     * @param string $key
67
     * @param int $value the timing in ms
68
     * @param int $sampleRate the sample rate, if < 1, statsd will send an average timing
69
     *
70
     * @return void
71
     */
72
    public function timing($key, $value, $sampleRate = 1)
73
    {
74
        $this->client->timing($key, $value, $sampleRate);
75
    }
76
77
    /**
78
     * starts the timing for a key
79
     *
80
     * @param string $key
81
     *
82
     * @return void
83
     */
84
    public function startTiming($key)
85
    {
86
        $this->client->startTiming($key);
87
    }
88
89
    /**
90
     * ends the timing for a key and sends it to statsd
91
     *
92
     * @param string $key
93
     * @param int $sampleRate (optional)
94
     *
95
     * @return void
96
     */
97
    public function endTiming($key, $sampleRate = 1)
98
    {
99
        $this->client->endTiming($key, $sampleRate);
100
    }
101
102
    /**
103
     * start memory "profiling"
104
     *
105
     * @param string $key
106
     *
107
     * @return void
108
     */
109
    public function startMemoryProfile($key)
110
    {
111
        $this->client->startMemoryProfile($key);
112
    }
113
114
    /**
115
     * ends the memory profiling and sends the value to the server
116
     *
117
     * @param string $key
118
     * @param int $sampleRate
119
     *
120
     * @return void
121
     */
122
    public function endMemoryProfile($key, $sampleRate = 1)
123
    {
124
        $this->client->endMemoryProfile($key, $sampleRate);
125
    }
126
127
    /**
128
     * report memory usage to statsd. if memory was not given report peak usage
129
     *
130
     * @param string $key
131
     * @param int $memory
132
     * @param int $sampleRate
133
     *
134
     * @return void
135
     */
136
    public function memory($key, $memory = null, $sampleRate = 1)
137
    {
138
        $this->client->memory($key, $memory, $sampleRate);
139
    }
140
141
    /**
142
     * executes a Closure and records it's execution time and sends it to statsd
143
     * returns the value the Closure returned
144
     *
145
     * @param string $key
146
     * @param \Closure $_block
147
     * @param int $sampleRate (optional) default = 1
148
     *
149
     * @return mixed
150
     */
151
    public function time($key, \Closure $_block, $sampleRate = 1)
152
    {
153
        return $this->client->time($key, $_block, $sampleRate);
154
    }
155
156
    /**
157
     * sends a gauge, an arbitrary value to StatsD
158
     *
159
     * @param string $key
160
     * @param int $value
161
     *
162
     * @return void
163
     */
164
    public function gauge($key, $value)
165
    {
166
        $this->client->gauge($key, $value);
167
    }
168
169
    /**
170
     * sends a set member
171
     *
172
     * @param string $key
173
     * @param int $value
174
     *
175
     * @return void
176
     */
177
    public function set($key, $value)
178
    {
179
        $this->client->set($key, $value);
180
    }
181
182
    /**
183
     * changes the global key namespace
184
     *
185
     * @param string $namespace
186
     *
187
     * @return void
188
     */
189
    public function setNamespace($namespace)
190
    {
191
        $this->client->setNamespace($namespace);
192
    }
193
194
    /**
195
     * gets the global key namespace
196
     *
197
     * @return string
198
     */
199
    public function getNamespace()
200
    {
201
        return $this->client->getNamespace();
202
    }
203
204
    /**
205
     * is batch processing running?
206
     *
207
     * @return boolean
208
     */
209
    public function isBatch()
210
    {
211
        return $this->client->isBatch();
212
    }
213
214
    /**
215
     * start batch-send-recording
216
     *
217
     * @return void
218
     */
219
    public function startBatch()
220
    {
221
        $this->client->startBatch();
222
    }
223
224
    /**
225
     * ends batch-send-recording and sends the recorded messages to the connection
226
     *
227
     * @return void
228
     */
229
    public function endBatch()
230
    {
231
        $this->client->endBatch();
232
    }
233
234
    /**
235
     * stops batch-recording and resets the batch
236
     *
237
     * @return void
238
     */
239
    public function cancelBatch()
240
    {
241
        $this->client->cancelBatch();
242
    }
243
}
244