/** * Execute CLI command * * @throws \InvalidArgumentException When namespace doesn't end with Bundle * @throws \RuntimeException When bundle can't be executed */ protected function execute(InputInterface $input, OutputInterface $output) { $connection = new \Domnikl\Statsd\Connection\UdpSocket('graphite.beaast.com', 8125); $statsd = new \Domnikl\Statsd\Client($connection, "test.namespace"); // the global namespace is prepended to every key (optional) $statsd->setNamespace("test"); // simple counts $statsd->increment("foo.bar"); $statsd->decrement("foo.bar"); $statsd->count("foo.bar", 1000); $statsd->gauge('foobar', 3); $statsd->startTiming("foo.bar"); $statsd->startMemoryProfile('memory.foo'); // Getting needed info $bundleName = $this->getBundleName($input); $bundleNamespace = $this->getBundleNamespace($input); $bundleDir = $this->getBundleDir($bundleNamespace); $generator = $this->getGenerator(); $generator->generate($bundleNamespace, $bundleName, $bundleDir); $output->writeln('Generating the bundle stub code: <info>OK</info>'); $errors = array(); // App kernal update $this->updateKernel($input, $output, $this->getContainer()->get('kernel'), $bundleNamespace, $bundleName); // Check that the namespace is already autoloaded $this->checkAutoloader($output, $bundleNamespace, $bundleName, $bundleDir); // Check cache $command = $this->getApplication()->find('cache:clear'); $cacheInput = new ArrayInput(array('command' => 'cache:clear')); $command->run($cacheInput, $output); $statsd->endTiming("foo.bar"); $statsd->endMemoryProfile('memory.foo'); $statsd->memory('foo.memory_peak_usage'); $statsd->gauge('foobar', '+11'); }
<?php require __DIR__ . '/../../vendor/autoload.php'; $connection = new \Domnikl\Statsd\Connection\TcpSocket('127.0.0.1', 8126); $statsd = new \Domnikl\Statsd\Client($connection, "tcp.test.namespace"); while (true) { $statsd->startTiming('timing.while'); $statsd->increment('customer.signed_up', 10); sleep(2); $statsd->count('products.viewed', rand(1, 100)); $statsd->endTiming('timing.while'); $statsd->startBatch(); for ($i = 0; $i < 1000; $i++) { $statsd->increment('batch'); } $statsd->increment('batch.end'); $statsd->endBatch(); }
<?php /** * Simulate a page load */ require __DIR__ . '/vendor/autoload.php'; $connection = new \Domnikl\Statsd\Connection\UdpSocket('statsd', 8125); $statsd = new \Domnikl\Statsd\Client($connection, "app.demo"); $statsd->startTiming("loadtime"); $time = rand(1000, 10000000); $sleep = usleep($time); $statsd->endTiming("loadtime"); echo $time;