Example #1
0
 /**
  * @inheritdoc
  */
 protected function classSetUp()
 {
     $this->formatter = new StatsDaemonFormatter();
     $this->metricName = new CounterMetric('metric_name', 10);
     $this->metricTags = new CounterMetric('metric_name', 10, ['env' => 'prod', 'server' => 'web01']);
     $this->metricTagsSample = new CounterMetric('metric_name', 10, ['env' => 'prod', 'server' => 'web01']);
     $this->metricTagsSample->setSampleRate(0.4);
 }
Example #2
0
 /**
  * @inheritdoc
  */
 protected function classSetUp()
 {
     $this->formatter = new InfluxDbLineFormatter();
     $this->metricName = new CounterMetric('metric_name', 10);
     $this->metricTags = new CounterMetric('metric_name', 10, ['env' => 'prod', 'server' => 'web01']);
     $this->metricTagsSample = new CounterMetric('metric_name', ['counter1' => 10, 'counter2' => 20], ['env' => 'production baby', 'server' => 'web01']);
     $this->metricTagsSample->setSampleRate(0.4);
 }
 /**
  * Tests one message handle
  */
 public function testHandleOne()
 {
     $handler = new UdpHandler($this->testHost, $this->testPort, $this->testTimeout);
     $handler->setFactory($this->mockFactory);
     // Normal metric
     $metric1 = new CounterMetric('metric_name1', 10);
     $metric1->setSampleRate(0.5);
     $expectedMessage = self::$formatter->format($metric1);
     $this->mockSocket->shouldReceive('write')->withArgs([$expectedMessage])->once();
     $handler->handle($metric1);
 }
 /**
  * Tests counter formatter
  */
 public function testCounterMetric()
 {
     $metric1 = new CounterMetric('metric_name1', 10);
     $expected1 = 'metric_name1:10|c';
     $this->assertEquals($expected1, $this->formatter->format($metric1));
     $metric2 = new CounterMetric('metric_name2', 40, ['env' => 'dev']);
     $expected2 = 'env.dev.metric_name2:40|c';
     $this->assertEquals($expected2, $this->formatter->format($metric2));
     $metric3 = new CounterMetric('metric_name3', 40, ['env' => 'dev']);
     $metric3->setSampleRate(0.5);
     $expected3 = 'env.dev.metric_name3:40|c|@0.5';
     $this->assertEquals($expected3, $this->formatter->format($metric3));
     $metric4 = new CounterMetric('metric_name4', ['internal' => 10]);
     $this->assertFalse($this->formatter->format($metric4));
 }
Example #5
0
 public function testSampleRate()
 {
     $metric = new CounterMetric('name', 1);
     $this->assertEquals(1.0, $metric->getSampleRate());
     $metric->setSampleRate(0.2);
     $this->assertEquals(0.2, $metric->getSampleRate());
     $metric->setSampleRate(10);
     $this->assertEquals(1.0, $metric->getSampleRate());
     $metric->setSampleRate(-10);
     $this->assertEquals(0.0, $metric->getSampleRate());
 }
 /**
  * Tests sampling
  */
 public function testMetricSample()
 {
     $metric1 = new CounterMetric('metric_name1', 10);
     $metric1->setSampleRate(0.2);
     $expected1 = 'metric_name1 value=' . 10 * 0.2;
     $this->assertEquals($expected1, $this->formatter->format($metric1));
 }