|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Krenor\Prometheus\Metrics; |
|
4
|
|
|
|
|
5
|
|
|
use Krenor\Prometheus\Contracts\Metric; |
|
6
|
|
|
use Tightenco\Collect\Support\Collection; |
|
7
|
|
|
use Krenor\Prometheus\Contracts\Types\Settable; |
|
8
|
|
|
use Krenor\Prometheus\Contracts\SamplesBuilder; |
|
9
|
|
|
use Krenor\Prometheus\Contracts\Types\Incrementable; |
|
10
|
|
|
use Krenor\Prometheus\Contracts\Types\Decrementable; |
|
11
|
|
|
use Krenor\Prometheus\Storage\Builders\GaugeSamplesBuilder; |
|
12
|
|
|
|
|
13
|
|
|
abstract class Gauge extends Metric implements Incrementable, Decrementable, Settable |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* {@inheritdoc} |
|
17
|
|
|
*/ |
|
18
|
15 |
|
final public function builder(Collection $items): SamplesBuilder |
|
19
|
|
|
{ |
|
20
|
15 |
|
return new GaugeSamplesBuilder($this, $items); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritdoc} |
|
25
|
|
|
*/ |
|
26
|
15 |
|
final public function type(): string |
|
27
|
|
|
{ |
|
28
|
15 |
|
return 'gauge'; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* {@inheritdoc} |
|
33
|
|
|
*/ |
|
34
|
|
|
public function increment(array $labels): self |
|
35
|
|
|
{ |
|
36
|
|
|
return $this->incrementBy(1, $labels); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* {@inheritdoc} |
|
41
|
|
|
*/ |
|
42
|
10 |
|
public function incrementBy(float $value, array $labels): self |
|
43
|
|
|
{ |
|
44
|
10 |
|
static::$storage->increment($this, $value, $labels); |
|
45
|
|
|
|
|
46
|
10 |
|
return $this; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
|
|
public function decrement(array $labels): self |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->decrementBy(1, $labels); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* {@inheritdoc} |
|
59
|
|
|
*/ |
|
60
|
5 |
|
public function decrementBy(float $value, array $labels): self |
|
61
|
|
|
{ |
|
62
|
5 |
|
static::$storage->decrement($this, $value, $labels); |
|
63
|
|
|
|
|
64
|
5 |
|
return $this; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* {@inheritdoc} |
|
69
|
|
|
*/ |
|
70
|
5 |
|
public function set(float $value, array $labels): self |
|
71
|
|
|
{ |
|
72
|
5 |
|
static::$storage->set($this, $value, $labels); |
|
73
|
|
|
|
|
74
|
5 |
|
return $this; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|