summaryrefslogtreecommitdiff
path: root/StatsdData.php
diff options
context:
space:
mode:
authorwiki <wiki@proton.parabola.nu>2016-08-02 21:10:30 +0100
committerwiki <wiki@proton.parabola.nu>2016-08-02 21:10:30 +0100
commitd386934962c15a79703588812dc5815f32d70cbf (patch)
tree1251b086744a5305855c107eacbcf3e96005ab6e /StatsdData.php
parenta5f917bbc55e295896b8084f6657eb8b6abaf8a8 (diff)
files were sitting here on productionemulatorman/master
Diffstat (limited to 'StatsdData.php')
-rw-r--r--StatsdData.php102
1 files changed, 102 insertions, 0 deletions
diff --git a/StatsdData.php b/StatsdData.php
new file mode 100644
index 00000000..2f030859
--- /dev/null
+++ b/StatsdData.php
@@ -0,0 +1,102 @@
+<?php
+
+namespace Liuggio\StatsdClient\Entity;
+
+use Liuggio\StatsdClient\Entity\StatsdDataInterface;
+
+class StatsdData implements StatsdDataInterface
+{
+
+ private $key;
+ private $value;
+ private $metric;
+ private $sampleRate = 1;
+
+ /**
+ * @param string $key
+ */
+ public function setKey($key)
+ {
+ $this->key = $key;
+ }
+
+ /**
+ * @return string
+ */
+ public function getKey()
+ {
+ return $this->key;
+ }
+
+ /**
+ * @param int $value
+ */
+ public function setValue($value)
+ {
+ $this->value = $value;
+ }
+
+ /**
+ * @return int
+ */
+ public function getValue()
+ {
+ return $this->value;
+ }
+
+
+ public function setMetric($metric)
+ {
+ $this->metric = $metric;
+ }
+
+ public function getMetric()
+ {
+ return $this->metric;
+ }
+
+ /**
+ * @param float $sampleRate
+ */
+ public function setSampleRate($sampleRate)
+ {
+ $this->sampleRate = $sampleRate;
+ }
+
+ /**
+ * @return float
+ */
+ public function getSampleRate()
+ {
+ return $this->sampleRate;
+ }
+
+ /**
+ * @param bool $withMetric
+ *
+ * @return string
+ */
+ public function getMessage($withMetric = true)
+ {
+ if (!$withMetric) {
+ $result = sprintf('%s:%s', $this->getKey(), $this->getValue());
+ } else {
+ $result = sprintf('%s:%s|%s', $this->getKey(), $this->getValue(), $this->getMetric());
+ }
+
+ $sampleRate = $this->getSampleRate();
+ if($sampleRate < 1){
+ $result.= "|@$sampleRate";
+ }
+
+ return $result;
+ }
+
+ /**
+ * @return string
+ */
+ public function __toString()
+ {
+ return $this->getMessage();
+ }
+}