From eacf5d376b2c6ef6b68a3fcadbfb5c8eac9a2407 Mon Sep 17 00:00:00 2001 From: "n.zbiranik" Date: Wed, 13 May 2020 11:08:40 +0700 Subject: [PATCH] add set command to Counter --- src/Prometheus/Counter.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Prometheus/Counter.php b/src/Prometheus/Counter.php index ae8e726..79e010d 100644 --- a/src/Prometheus/Counter.php +++ b/src/Prometheus/Counter.php @@ -45,4 +45,25 @@ public function incBy($count, array $labels = []): void ] ); } + + /** + * @param int $count e.g. 2 + * @param array $labels e.g. ['status', 'opcode'] + */ + public function set($count, array $labels = []): void + { + $this->assertLabelsAreDefinedCorrectly($labels); + + $this->storageAdapter->updateCounter( + [ + 'name' => $this->getName(), + 'help' => $this->getHelp(), + 'type' => $this->getType(), + 'labelNames' => $this->getLabelNames(), + 'labelValues' => $labels, + 'value' => $count, + 'command' => Adapter::COMMAND_SET, + ] + ); + } }