/** * @return \Exolnet\Instruments\Drivers\StatsdDriver */ protected function createStatsdDriver() { $options = config('instruments.statsd') + ['namespace' => $this->getNamespace()]; $client = new Client(); $client->configure($options); return new StatsdDriver($client); }
/** * @test */ public function preConsume_with_postConsume_should_add_timing_entry() { $timing = 2342; $deliveryTag = 1; $consumerName = 'consumer'; $eventName = $consumerName . '-' . $deliveryTag; $message = new AMQPMessage('body'); $message->delivery_info['delivery_tag'] = $deliveryTag; $container = $this->prophesize(ConsumerContainer::class); $container->getConsumerName()->willReturn($consumerName); $args = new ConsumerEvent($message, $container->reveal()); $event = $this->prophesize(StopwatchEvent::class); $event->getDuration()->willReturn($timing); $this->stopwatch->start($eventName)->shouldBeCalled(); $this->stopwatch->stop($eventName)->willReturn($event->reveal()); $this->subscriber->preConsume($args); $this->subscriber->postConsume($args); $this->statsdClient->timing($consumerName, $timing)->shouldHaveBeenCalled(); }
public function testStaticInstance() { $client1 = Client::instance('instance1'); $this->assertTrue($client1 instanceof Client); $client2 = Client::instance('instance2'); $client3 = Client::instance('instance1'); $this->assertEquals('StatsD\\Client::[instance2]', (string) $client2); $this->assertFalse((string) $client1 === (string) $client2); $this->assertTrue((string) $client1 === (string) $client3); }
/** * Register Service Provider * @param Application $app Silex application instance */ public function register(Application $app) { $app['statsd'] = $app->share(function () use($app) { // Set Default host and port $options = array(); if (isset($app['statsd.host'])) { $options['host'] = $app['statsd.host']; } if (isset($app['statsd.port'])) { $options['port'] = $app['statsd.port']; } if (isset($app['statsd.namespace'])) { $options['namespace'] = $app['statsd.namespace']; } // Create $statsd = new StatsdClient(); $statsd->configure($options); return $statsd; }); }
/** * Register Statsd * * @return void */ protected function registerStatsD() { $this->app['statsd'] = $this->app->share(function ($app) { // Set Default host and port $options = array(); if (isset($app['config']['statsd.host'])) { $options['host'] = $app['config']['statsd.host']; } if (isset($app['config']['statsd.port'])) { $options['port'] = $app['config']['statsd.port']; } if (isset($app['config']['statsd.namespace'])) { $options['namespace'] = $app['config']['statsd.namespace']; } // Create $statsd = new Statsd(); $statsd->configure($options); return $statsd; }); }
/** * @param ConsumerEvent $args */ public function postConsume(ConsumerEvent $args) { $consumerName = $args->getConsumerContainer()->getConsumerName(); $event = $this->stopwatch->stop($this->getEventName($args)); $this->statsdClient->timing($consumerName, $event->getDuration()); }
/** * Sets - count the number of unique values passed to a key * * @param string $metric * @param mixed $value * @return $this */ public function set($metric, $value) { $this->client->set($metric, $value); return $this; }