-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathGauge.php
87 lines (75 loc) · 1.96 KB
/
Gauge.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
declare(strict_types=1);
namespace Prometheus;
use Prometheus\Storage\Adapter;
class Gauge extends Collector
{
const TYPE = 'gauge';
/**
* @param double $value e.g. 123
* @param string[] $labels e.g. ['status', 'opcode']
*/
public function set(float $value, array $labels = []): void
{
$this->assertLabelsAreDefinedCorrectly($labels);
$this->storageAdapter->updateGauge(
[
'name' => $this->getName(),
'help' => $this->getHelp(),
'type' => $this->getType(),
'labelNames' => $this->getLabelNames(),
'labelValues' => $labels,
'value' => $value,
'command' => Adapter::COMMAND_SET,
]
);
}
/**
* @return string
*/
public function getType(): string
{
return self::TYPE;
}
/**
* @param string[] $labels
*/
public function inc(array $labels = []): void
{
$this->incBy(1, $labels);
}
/**
* @param int|float $value
* @param string[] $labels
*/
public function incBy($value, array $labels = []): void
{
$this->assertLabelsAreDefinedCorrectly($labels);
$this->storageAdapter->updateGauge(
[
'name' => $this->getName(),
'help' => $this->getHelp(),
'type' => $this->getType(),
'labelNames' => $this->getLabelNames(),
'labelValues' => $labels,
'value' => $value,
'command' => Adapter::COMMAND_INCREMENT_FLOAT,
]
);
}
/**
* @param string[] $labels
*/
public function dec(array $labels = []): void
{
$this->decBy(1, $labels);
}
/**
* @param int|float $value
* @param string[] $labels
*/
public function decBy($value, array $labels = []): void
{
$this->incBy(-$value, $labels);
}
}