PluginProbe
DecaLog / 4.4.0
DecaLog v4.4.0
3.0.2 3.1.0 3.10.0 3.2.0 3.3.0 3.4.0 3.4.1 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.6.3 3.7.0 3.7.1 3.8.0 3.9.0 3.9.1 4.0.0 4.1.0 4.2.0 4.3.0 4.3.1 4.4.0 4.5.0 All 75 releases
decalog / includes / libraries / prometheus / Counter.php

Counter.php in DecaLog 4.4.0, at includes/libraries/prometheus/Counter.php

50 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Prometheus;
6
7 use Prometheus\Storage\Adapter;
8
9 class Counter extends Collector
10 {
11 const TYPE = 'counter';
12
13 /**
14 * @return string
15 */
16 public function getType(): string
17 {
18 return self::TYPE;
19 }
20
21 /**
22 * @param string[] $labels e.g. ['status', 'opcode']
23 */
24 public function inc(array $labels = []): void
25 {
26 $this->incBy(1, $labels);
27 }
28
29 /**
30 * @param int|float $count e.g. 2
31 * @param mixed[] $labels e.g. ['status', 'opcode']
32 */
33 public function incBy($count, array $labels = []): void
34 {
35 $this->assertLabelsAreDefinedCorrectly($labels);
36
37 $this->storageAdapter->updateCounter(
38 [
39 'name' => $this->getName(),
40 'help' => $this->getHelp(),
41 'type' => $this->getType(),
42 'labelNames' => $this->getLabelNames(),
43 'labelValues' => $labels,
44 'value' => $count,
45 'command' => is_float($count) ? Adapter::COMMAND_INCREMENT_FLOAT : Adapter::COMMAND_INCREMENT_INTEGER,
46 ]
47 );
48 }
49 }
50