1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WZRD\Profiling; |
4
|
|
|
|
5
|
|
|
use League\StatsD\Client as Statsd; |
6
|
|
|
use WZRD\Contracts\Profiling\Profiler; |
7
|
|
|
|
8
|
|
|
class StatsdProfiler implements Profiler |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* StatsD instance. |
12
|
|
|
* |
13
|
|
|
* @var League\StatsD\Client |
14
|
|
|
*/ |
15
|
|
|
private $statsd; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Initialize measurer with StatsD instance. |
19
|
|
|
* |
20
|
|
|
* @param League\StatsD\Client $statsd |
21
|
|
|
*/ |
22
|
|
|
public function __construct(Statsd $statsd) |
23
|
|
|
{ |
24
|
|
|
$this->statsd = $statsd; |
|
|
|
|
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Increment a metric. |
29
|
|
|
* |
30
|
|
|
* @param string|array $metrics Metric(s) to increment |
31
|
|
|
* @param int $delta Value to decrement the metric by |
32
|
|
|
* @param int $sampleRate Sample rate of metric |
33
|
|
|
* |
34
|
|
|
* @return bool True if data transfer is successful |
35
|
|
|
*/ |
36
|
|
|
public function increment($metrics, $delta = 1, $sampleRate = 1) |
37
|
|
|
{ |
38
|
|
|
return $this->statsd->increment($metrics, $delta, $sampleRate); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Decrement a metric. |
43
|
|
|
* |
44
|
|
|
* @param string|array $metrics Metric(s) to decrement |
45
|
|
|
* @param int $delta Value to increment the metric by |
46
|
|
|
* @param int $sampleRate Sample rate of metric |
47
|
|
|
* |
48
|
|
|
* @return bool True if data transfer is successful |
49
|
|
|
*/ |
50
|
|
|
public function decrement($metrics, $delta = 1, $sampleRate = 1) |
51
|
|
|
{ |
52
|
|
|
return $this->statsd->decrement($metrics, $delta, $sampleRate); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Timing. |
57
|
|
|
* |
58
|
|
|
* @param string $metric Metric to track |
59
|
|
|
* @param float $time Time in milliseconds |
60
|
|
|
* |
61
|
|
|
* @return bool True if data transfer is successful |
62
|
|
|
*/ |
63
|
|
|
public function timing($metric, $time) |
64
|
|
|
{ |
65
|
|
|
return $this->statsd->timing($metric, $time); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Time a function. |
70
|
|
|
* |
71
|
|
|
* @param string $metric Metric to time |
72
|
|
|
* @param callable $func Function to record |
73
|
|
|
* |
74
|
|
|
* @return bool True if data transfer is successful |
75
|
|
|
*/ |
76
|
|
|
public function time($metric, $func) |
77
|
|
|
{ |
78
|
|
|
return $this->statsd->time($metric, $func); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Gauges. |
83
|
|
|
* |
84
|
|
|
* @param string $metric Metric to gauge |
85
|
|
|
* @param int $value Set the value of the gauge |
86
|
|
|
* |
87
|
|
|
* @return bool True if data transfer is successful |
88
|
|
|
*/ |
89
|
|
|
public function gauge($metric, $value) |
90
|
|
|
{ |
91
|
|
|
return $this->statsd->gauge($metric, $value); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Sets - count the number of unique values passed to a key. |
96
|
|
|
* |
97
|
|
|
* @param $metric |
98
|
|
|
* @param mixed $value |
99
|
|
|
* |
100
|
|
|
* @return bool True if data transfer is successful |
101
|
|
|
*/ |
102
|
|
|
public function set($metric, $value) |
103
|
|
|
{ |
104
|
|
|
return $this->statsd->set($metric, $value); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..