EndpointMysqlCommand.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 EndpointMysqlCommand extends ContainerAwareCommand
  8. {
  9. protected function configure()
  10. {
  11. $this
  12. ->setName('endpoint:mysql')
  13. ->setDescription('Test jsonendpoint mysql - Obtiene los últimos 10 registros de la métrica que se pasa')
  14. ->addArgument('metric', InputArgument::REQUIRED, 'Metric name')
  15. ;
  16. }
  17. /**
  18. * @param InputInterface $input
  19. * @param OutputInterface $output
  20. */
  21. protected function execute(InputInterface $input, OutputInterface $output)
  22. {
  23. //$json = '{"range":{"from":"2017-12-01T14:09:25.307Z","to":"2017-12-07T23:09:25.308Z"},"intervalMs":0,"targets":[{"target":"d_1_s_1_cmd_fiberhome_olt_scan"}],"format":"json","maxDataPoints":10}';
  24. $endpoint = $this->getContainer()->get('endpoint.mysql');
  25. $metric = $input->getArgument('metric');
  26. $data = array('targets' => array(0 => array("target" => $metric)), 'maxDataPoints' => 10);
  27. $json = json_encode($data);
  28. $result = $endpoint->get($json,'last');
  29. print_r($result);
  30. print_r(PHP_EOL);
  31. print_r(date("Y-m-d H:i:s"));
  32. print_r(PHP_EOL);
  33. }
  34. }