summaryrefslogtreecommitdiff
path: root/src/Metrics/Metrics.php
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-10-28 16:05:39 +0300
committerGitHub <[email protected]>2020-10-28 16:05:39 +0300
commitde53c3ad12a8afb379610f87399373c4d0626ef6 (patch)
treed4ed0d2a879fc9515062b77fc54ec80e66cf0054 /src/Metrics/Metrics.php
parent47a570c220a36ae7b770ea594a41637fa31fc8e8 (diff)
parent175c02e501a3b5110f8882599d5d033fde5bf81b (diff)
Merge pull request #378 from spiral/feature/loggingv2.0.0-alpha14
Feature/logging
Diffstat (limited to 'src/Metrics/Metrics.php')
-rw-r--r--src/Metrics/Metrics.php80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/Metrics/Metrics.php b/src/Metrics/Metrics.php
new file mode 100644
index 00000000..d6b6e1da
--- /dev/null
+++ b/src/Metrics/Metrics.php
@@ -0,0 +1,80 @@
+<?php
+
+/**
+ * Spiral Framework.
+ *
+ * @license MIT
+ * @author Anton Titov (Wolfy-J)
+ */
+declare(strict_types=1);
+
+namespace Spiral\RoadRunner;
+
+use Spiral\Goridge\Exceptions\RPCException;
+use Spiral\Goridge\RPC;
+use Spiral\RoadRunner\Exception\MetricException;
+
+/**
+ * Application metrics.
+ */
+final class Metrics implements MetricsInterface
+{
+ /** @var RPC */
+ private $rpc;
+
+ /**
+ * @param RPC $rpc
+ */
+ public function __construct(RPC $rpc)
+ {
+ $this->rpc = $rpc;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function add(string $name, float $value, array $labels = []): void
+ {
+ try {
+ $this->rpc->call('metrics.Add', compact('name', 'value', 'labels'));
+ } catch (RPCException $e) {
+ throw new MetricException($e->getMessage(), $e->getCode(), $e);
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function sub(string $name, float $value, array $labels = []): void
+ {
+ try {
+ $this->rpc->call('metrics.Sub', compact('name', 'value', 'labels'));
+ } catch (RPCException $e) {
+ throw new MetricException($e->getMessage(), $e->getCode(), $e);
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function observe(string $name, float $value, array $labels = []): void
+ {
+ try {
+ $this->rpc->call('metrics.Observe', compact('name', 'value', 'labels'));
+ } catch (RPCException $e) {
+ throw new MetricException($e->getMessage(), $e->getCode(), $e);
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function set(string $name, float $value, array $labels = []): void
+ {
+ try {
+ $this->rpc->call('metrics.Set', compact('name', 'value', 'labels'));
+ } catch (RPCException $e) {
+ throw new MetricException($e->getMessage(), $e->getCode(), $e);
+ }
+ }
+}