Example #1
0
 /**
  * Send a Metric object to datadog
  *
  * The metric object will be encapsulated into a
  * dummy series, as the datadog API requires.
  *
  * @param Metric $metric
  * @throws EmptyMetricException
  *
  * @return Client
  */
 public function sendMetric(Metric $metric)
 {
     $points = $metric->getPoints();
     if (empty($points)) {
         throw new EmptyMetricException('The metric must contain points to send');
     }
     $this->sendSeries(new Series($metric));
     return $this;
 }
Example #2
0
 /**
  * @param Metric $metric
  *
  * @return Series
  */
 public function addMetric(Metric $metric)
 {
     $this->metrics[$metric->getName()] = $metric;
     return $this;
 }
 public function testAddMultiplePoints()
 {
     // Some testing points
     $points = array(array(time(), 20), array(time(), 30), array(time(), 40));
     // Set multiple point in constructor
     $metric1 = new Metric('test.metric.name', $points);
     $this->assertCount(3, $metric1->getPoints());
     $this->assertEquals($points[0], $metric1->getPoints()[0]);
     // Add multiple points by method
     $metric2 = new Metric('test.metric.name', array(40));
     $this->assertCount(1, $metric2->getPoints());
     foreach ($points as $point) {
         $metric2->addPoint($point);
     }
     $this->assertCount(4, $metric2->getPoints());
     $this->assertEquals($points[0], $metric2->getPoints()[1]);
     // Set multiple points by method
     $metric3 = new Metric('test.metric.name', array(30));
     $this->assertCount(1, $metric3->getPoints());
     $metric3->setPoints($points);
     $this->assertCount(3, $metric3->getPoints());
     $this->assertEquals($points[0], $metric3->getPoints()[0]);
 }
 /**
  * @expectedException \Bayer\DataDogClient\Client\EmptyMetricException
  */
 public function testSendingEmptyMetricThrowsException()
 {
     $metric = new Metric('test.metric.name', array(20));
     $metric->removePoints();
     $this->client->sendMetric($metric);
 }