This repository was archived by the owner on Oct 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 210
Expand file tree
/
Copy pathCounter.php
More file actions
67 lines (58 loc) · 1.61 KB
/
Counter.php
File metadata and controls
67 lines (58 loc) · 1.61 KB
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
<?php
namespace Prometheus;
use Prometheus\Storage\Adapter;
class Counter extends Collector
{
const TYPE = 'counter';
/**
* @return string
*/
public function getType()
{
return self::TYPE;
}
/**
* @param array $labels e.g. ['status', 'opcode']
*/
public function inc(array $labels = array())
{
$this->incBy(1, $labels);
}
/**
* @param int $count e.g. 2
* @param array $labels e.g. ['status', 'opcode']
*/
public function incBy($count, array $labels = array())
{
$this->assertLabelsAreDefinedCorrectly($labels);
$this->storageAdapter->updateCounter(
array(
'name' => $this->getName(),
'help' => $this->getHelp(),
'type' => $this->getType(),
'labelNames' => $this->getLabelNames(),
'labelValues' => $labels,
'value' => $count,
'command' => Adapter::COMMAND_INCREMENT_INTEGER
)
);
}
/**
* @param array $labels e.g. ['status', 'opcode']
*/
public function reset(array $labels = array())
{
$this->assertLabelsAreDefinedCorrectly($labels);
$this->storageAdapter->updateCounter(
array(
'name' => $this->getName(),
'help' => $this->getHelp(),
'type' => $this->getType(),
'labelNames' => $this->getLabelNames(),
'labelValues' => $labels,
'value' => 0,
'command' => Adapter::COMMAND_SET
)
);
}
}