コード例 #1
0
ファイル: LineFormatter.php プロジェクト: hitmeister/metrics
 /**
  * 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;
 }
コード例 #2
0
ファイル: MetricTestCase.php プロジェクト: hitmeister/metrics
 /**
  * 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());
 }