/** * Process the metric. * * @param Metric $metric * @return bool|string */ protected function process(Metric &$metric) { // By the InfluxDb rules we have to have at least one value $value = $metric->getValue(); if (empty($value)) { return false; } // Sampling if ($metric instanceof SamplingMetricInterface && $metric->getSampleRate() < 1) { foreach ($value as $k => $v) { if (!is_string($v)) { $value[$k] = $v * $metric->getSampleRate(); } } } // Metric name $name = $this->quoteKey($metric->getName()); // Metric tags if ($metric->hasTags()) { $name .= ',' . $this->prepareTags($metric->getTags()); } // Metric values $name .= ' ' . $this->prepareValues($value); // Metric time (from milliseconds to nanoseconds) if ($metric->getTime()) { $name .= ' ' . $metric->getTime() * 1000000; } return $name; }
/** * 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; }