StatsDCommand.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace StatsDBundle\Command;
  3. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  4. use Symfony\Component\Console\Input\InputArgument;
  5. use Symfony\Component\Console\Input\InputInterface;
  6. use Symfony\Component\Console\Output\OutputInterface;
  7. class StatsDCommand extends ContainerAwareCommand
  8. {
  9. protected function configure()
  10. {
  11. $this
  12. ->setName('statsd:statsd')
  13. ->setDescription('Insert metric in statsd service')
  14. ->addArgument('metric', InputArgument::REQUIRED, 'Metric name')
  15. ->addArgument('value', InputArgument::REQUIRED, 'Metric value')
  16. ->addArgument('function', InputArgument::OPTIONAL, 'StatsD service function', 'gauge')
  17. ;
  18. }
  19. /**
  20. * @param InputInterface $input
  21. * @param OutputInterface $output
  22. */
  23. protected function execute(InputInterface $input, OutputInterface $output)
  24. {
  25. $function = $input->getArgument('function');
  26. $metric = $input->getArgument('metric');
  27. $value = $input->getArgument('value');
  28. $output->writeln("statsd: <info>{$function}</info> metric: <info>{$metric}</info> value: <info>{$value}</info>");
  29. $statsdService = $this->getContainer()->get('statsd');
  30. $statsdService->$function($metric, $value);
  31. }
  32. }