Skip to content

Commit 8a501d8

Browse files
committed
Resources check command: add param for parth and danger mb level
1 parent cf75690 commit 8a501d8

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

Diff for: src/Command/Crons/CronServerResourcesCheckCommand.php

+15-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use App\Controller\Core\Application;
77
use Exception;
88
use Symfony\Component\Console\Command\Command;
9+
use Symfony\Component\Console\Input\InputArgument;
910
use Symfony\Component\Console\Input\InputInterface;
1011
use Symfony\Component\Console\Output\OutputInterface;
1112
use Symfony\Component\Console\Style\SymfonyStyle;
@@ -15,7 +16,8 @@ class CronServerResourcesCheckCommand extends Command
1516
{
1617
protected static $defaultName = 'cron:check-server-resources';
1718

18-
const LEFT_SERVER_DISC_SPACE_DANGER_VALUE_MBYTES = 122000;
19+
const ARGUMENT_LOW_DISC_SPACE_DANGER_MBYTES = "dangerLowSpace";
20+
const ARGUMENT_CHECKED_PATH = "checkedPath";
1921

2022
/**
2123
* @var SymfonyStyle $io
@@ -35,7 +37,10 @@ public function __construct(Application $app, string $name = null) {
3537
protected function configure()
3638
{
3739
$this
38-
->setDescription('This command allows to make backup of files for given upload modules and database, must be called as sudo to ensure directories creating. ');
40+
->setDescription('This command checks the free resources left on the server')
41+
->addArgument(self::ARGUMENT_CHECKED_PATH, InputArgument::REQUIRED, "Path that should be checked for space left")
42+
->addArgument(self::ARGUMENT_LOW_DISC_SPACE_DANGER_MBYTES, InputArgument::REQUIRED, "Number of MBytes left for which mail is being sent")
43+
->addUsage(" '/' 2000");
3944
}
4045

4146
/**
@@ -54,12 +59,14 @@ function initialize(InputInterface $input, OutputInterface $output)
5459
* @return int
5560
* @throws Exception
5661
*/
57-
protected function execute(InputInterface $input, OutputInterface $output)
62+
protected function execute(InputInterface $input, OutputInterface $output): int
5863
{
5964
$this->io->note("Started checking server resources");
6065
{
6166
try{
62-
$this->checkServerDiscSpaceLeft();
67+
$dangerLowSpace = $input->getArgument(self::ARGUMENT_LOW_DISC_SPACE_DANGER_MBYTES);
68+
$checkedPath = $input->getArgument(self::ARGUMENT_CHECKED_PATH);
69+
$this->checkServerDiscSpaceLeft($dangerLowSpace, $checkedPath);
6370
}catch(Exception | TypeError $e){
6471
$this->app->logger->emergency("Exception was thrown while trying to check the server resources.", [
6572
"exceptionMessage" => $e->getMessage(),
@@ -77,15 +84,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
7784
* Will check how much left disc space is there,
7885
* Triggers emergency logger if value is below given threshold
7986
*/
80-
private function checkServerDiscSpaceLeft(): void
87+
private function checkServerDiscSpaceLeft(int $dangerLowSpace, string $checkedPath): void
8188
{
82-
$discFreeSpaceInBytes = disk_free_space("/");
89+
$discFreeSpaceInBytes = disk_free_space($checkedPath);
8390
$discFreeSpaceInMBytes = round($discFreeSpaceInBytes / 1024 / 1024);
8491

85-
if( $discFreeSpaceInMBytes <= self::LEFT_SERVER_DISC_SPACE_DANGER_VALUE_MBYTES ){
92+
if( $discFreeSpaceInMBytes <= $dangerLowSpace ){
8693
$this->app->logger->emergency("Low disc space!", [
8794
"discSpaceLeft" => $discFreeSpaceInMBytes,
88-
"warningValue" => self::LEFT_SERVER_DISC_SPACE_DANGER_VALUE_MBYTES,
95+
"warningValue" => $dangerLowSpace,
8996
]);
9097
}
9198
}

0 commit comments

Comments
 (0)