-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathCounter.php
More file actions
50 lines (42 loc) · 1.22 KB
/
Counter.php
File metadata and controls
50 lines (42 loc) · 1.22 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
<?php
declare(strict_types=1);
namespace Prometheus;
use Prometheus\Storage\Adapter;
class Counter extends Collector
{
const TYPE = 'counter';
/**
* @return string
*/
public function getType(): string
{
return self::TYPE;
}
/**
* @param string[] $labels e.g. ['status', 'opcode']
*/
public function inc(array $labels = [], ?int $timestamp = null): void
{
$this->incBy(1, $labels, $timestamp);
}
/**
* @param int|float $count e.g. 2
* @param mixed[] $labels e.g. ['status', 'opcode']
*/
public function incBy($count, array $labels = [], ?int $timestamp = null): void
{
$this->assertLabelsAreDefinedCorrectly($labels);
$this->storageAdapter->updateCounter(
[
'name' => $this->getName(),
'help' => $this->getHelp(),
'type' => $this->getType(),
'labelNames' => $this->getLabelNames(),
'labelValues' => $labels,
'timestamp' => $timestamp,
'value' => $count,
'command' => is_float($count) ? Adapter::COMMAND_INCREMENT_FLOAT : Adapter::COMMAND_INCREMENT_INTEGER,
]
);
}
}