1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- namespace StatsDBundle\Command;
- use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
- use Symfony\Component\Console\Input\InputArgument;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- class StatsDCommand extends ContainerAwareCommand
- {
- protected function configure()
- {
- $this
- ->setName('statsd:statsd')
- ->setDescription('Insert metric in statsd service')
- ->addArgument('metric', InputArgument::REQUIRED, 'Metric name')
- ->addArgument('value', InputArgument::REQUIRED, 'Metric value')
- ->addArgument('function', InputArgument::OPTIONAL, 'StatsD service function', 'gauge')
- ;
- }
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- */
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $function = $input->getArgument('function');
- $metric = $input->getArgument('metric');
- $value = $input->getArgument('value');
- $output->writeln("statsd: <info>{$function}</info> metric: <info>{$metric}</info> value: <info>{$value}</info>");
- $statsdService = $this->getContainer()->get('statsd');
- $statsdService->$function($metric, $value);
- }
- }
|