| 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 |
|