diff --git a/src/Command/Metrics/MetricsCommandBase.php b/src/Command/Metrics/MetricsCommandBase.php index fe1402da5..f800b8e5c 100644 --- a/src/Command/Metrics/MetricsCommandBase.php +++ b/src/Command/Metrics/MetricsCommandBase.php @@ -26,10 +26,11 @@ abstract class MetricsCommandBase extends CommandBase { - const MIN_INTERVAL = 60; // 1 minute + const MIN_INTERVAL = 60; // 1 minute - const MIN_RANGE = 300; // 5 minutes - const DEFAULT_RANGE = 600; + const MIN_RANGE = 300; // 5 minutes + const DEFAULT_RANGE = 600; // 10 minutes + const LATEST_GRAIN = 300; // 5 minutes /** * @var bool whether services have been identified that use high memory @@ -64,7 +65,7 @@ protected function addMetricsOptions() . "\n" . \sprintf('Minimum %s.', $duration->humanize(self::MIN_INTERVAL)) ); $this->addOption('to', null, InputOption::VALUE_REQUIRED, 'The end time. Defaults to now.'); - $this->addOption('latest', '1', InputOption::VALUE_NONE, 'Show only the latest single data point'); + $this->addOption('latest', '1', InputOption::VALUE_NONE, 'Show only the latest single data point' . "\n" . 'Defaults to a 5-minute aggregation window to ensure all containers are included. Override with --interval.'); $this->addOption('service', 's', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Filter by service or application name' . "\n" . Wildcard::HELP); $this->addOption('type', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Filter by service type (if --service is not provided). The version is not required.' . "\n" . Wildcard::HELP); @@ -231,6 +232,8 @@ private function getServices(InputInterface $input, Environment $environment) */ protected function validateTimeInput(InputInterface $input) { + $isLatest = $input->getOption('latest'); + if ($to = $input->getOption('to')) { $endTime = \strtotime($to); if (!$endTime) { @@ -253,6 +256,8 @@ protected function validateTimeInput(InputInterface $input) return false; } $rangeSeconds = (int) $rangeSeconds; + } elseif ($isLatest && !$input->getOption('interval')) { + $rangeSeconds = self::LATEST_GRAIN; } else { $rangeSeconds = self::DEFAULT_RANGE; } @@ -274,6 +279,8 @@ protected function validateTimeInput(InputInterface $input) return false; } + } elseif ($isLatest) { + $interval = self::LATEST_GRAIN; } return new TimeSpec($startTime, $endTime, $interval);