/** * Test create function * * @dataProvider createProvider * @param Metric $metric * @param array $expected */ public function testCreate(Metric $metric, array $expected) { list($name, $value, $tags, $time) = $expected; $this->assertEquals($name, $metric->getName()); $this->assertEquals($value, $metric->getValue()); $this->assertEquals($tags, $metric->getTags()); $this->assertEquals($time, $metric->getTime()); }
/** * Converts all gauge values to float * * @param Metric $metric * @return bool|string */ protected function processGauge(Metric &$metric) { // All items should be int or float (currently values are: 10, +10, -10) $value = $metric->getValue(); foreach ($value as $k => $v) { $value[$k] = (double) $v; } $metric->setValue($value); return $this->process($metric); }
/** * Formats metric to stats daemon format * @see https://github.com/etsy/statsd/blob/master/docs/metric_types.md * * @param Metric $metric * @param string $daemonType * @return bool|string */ protected function process(Metric &$metric, $daemonType) { // If no value, nothing to add $value = $metric->getValue(); if (!isset($value['value'])) { return false; } $value = $value['value']; $name = $metric->getName(); // Add tags to the beginning of the name if ($metric->hasTags()) { $name = Helper::mapAsString($metric->getTags()) . '.' . $name; } // Name with value and type $result = $name . ':' . $value . '|' . $daemonType; // Add sampling rate if ($metric instanceof SamplingMetricInterface) { if ($metric->getSampleRate() < 1.0) { $result .= '|@' . $metric->getSampleRate(); } } return $result; }