|
|
|
@ -24,13 +24,16 @@ use Symfony\Component\Console\Input\InputInterface; |
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
|
|
|
use vierbergenlars\AuthserverStatsBundle\Event\StatsEvent; |
|
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
|
|
|
use Symfony\Component\Console\Helper\Table; |
|
|
|
|
|
|
|
|
|
class DumpStatsCommand extends Command |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
protected function configure() |
|
|
|
|
{ |
|
|
|
|
$this->setName('stats:dump')->addOption('module', 'm', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Modules to fetch statistics for'); |
|
|
|
|
$this->setName('stats:dump') |
|
|
|
|
->addOption('module', 'm', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Modules to fetch statistics for') |
|
|
|
|
->addOption('munin', null, InputOption::VALUE_OPTIONAL, 'Output data for consumption by munin', false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
|
|
@ -45,7 +48,29 @@ class DumpStatsCommand extends Command |
|
|
|
|
$event = new StatsEvent($input->getOption('module')); |
|
|
|
|
$eventDispatcher->dispatch(StatsEvent::class, $event); |
|
|
|
|
|
|
|
|
|
foreach ($event->getStatistics() as $name => $value) |
|
|
|
|
$output->writeln(sprintf('%s:%s', $name, $value), OutputInterface::OUTPUT_RAW); |
|
|
|
|
if ($input->getOption('munin') !== false) { |
|
|
|
|
foreach ($event->getModules() as $module) { |
|
|
|
|
$output->writeln('multigraph authserver_' . $module, OutputInterface::OUTPUT_RAW); |
|
|
|
|
if ($input->getOption('munin') === 'config') { |
|
|
|
|
$stats = $event->getMuninConfig($module); |
|
|
|
|
$suffix = ' '; |
|
|
|
|
} else { |
|
|
|
|
$stats = $event->getModuleStatistics($module); |
|
|
|
|
$suffix = '.value '; |
|
|
|
|
} |
|
|
|
|
foreach ($stats as $k => $v) { |
|
|
|
|
$output->writeln($k . $suffix . $v, OutputInterface::OUTPUT_RAW); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
$table = new Table($output); |
|
|
|
|
foreach ($event->getStatistics() as $name => $value) { |
|
|
|
|
$table->addRow([ |
|
|
|
|
$name, |
|
|
|
|
$value |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
$table->render(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |