/**
  * @inheritdoc
  */
 protected function classSetUp()
 {
     $this->collectorBase = new Collector();
     $this->collectorBase->setBuffer(new OnShutdownBuffer());
     $this->collectorBase->setHandler(new StatsDaemonHandler());
     $this->collectorPrefix = new Collector();
     $this->collectorPrefix->setBuffer(new OnShutdownBuffer());
     $this->collectorPrefix->setHandler(new StatsDaemonHandler());
     $this->collectorPrefix->setPrefix('prefix_');
     $this->collectorTags = new Collector();
     $this->collectorTags->setBuffer(new OnShutdownBuffer());
     $this->collectorTags->setHandler(new StatsDaemonHandler());
     $this->collectorTags->setTags(['env' => 'prod', 'server' => 'web01']);
     $this->collectorTagsPrefix = new Collector();
     $this->collectorTagsPrefix->setBuffer(new OnShutdownBuffer());
     $this->collectorTagsPrefix->setHandler(new StatsDaemonHandler());
     $this->collectorTagsPrefix->setTags(['env' => 'prod', 'server' => 'web01']);
     $this->collectorTagsPrefix->setPrefix('prefix_');
 }
Exemplo n.º 2
0
<?php

/**
 * User: Maksim Naumov <*****@*****.**>
 * Date: 6/18/15
 * Time: 9:30 PM
 */
$loader = (require __DIR__ . '/../vendor/autoload.php');
use Hitmeister\Component\Metrics\Buffer\OnShutdownBuffer;
use Hitmeister\Component\Metrics\Collector;
use Hitmeister\Component\Metrics\Handler\StatsDaemonHandler;
// Create new handler
$handler = new StatsDaemonHandler('127.0.0.1', 8125);
// Create buffer
$buffer = new OnShutdownBuffer();
$buffer->setHandler($handler);
// Create new collector and set buffer
$collector = new Collector();
$collector->setBuffer($buffer);
// Increment some stats
for ($i = 0; $i < 100; $i++) {
    $collector->increment('stats_' . $i);
}
// All metrics will be flushed to the stats daemon after script shutdown
// It uses `register_shutdown_function` function under the hood
Exemplo n.º 3
0
 /**
  *
  */
 public function testClosureError()
 {
     /** @var m\MockInterface|BufferInterface $mockBuffer */
     $mockBuffer = m::mock('\\Hitmeister\\Component\\Metrics\\Buffer\\BufferInterface');
     $mockBuffer->shouldNotReceive('addBatch');
     $exception = null;
     $collector = new Collector();
     $collector->setBuffer($mockBuffer);
     try {
         $collector->closure('closure_metric', 'no_function');
     } catch (\Exception $e) {
         $exception = $e;
     }
     $this->assertInstanceOf('\\LogicException', $exception);
 }