|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MohsenAbrishami\Stethoscope\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
use MohsenAbrishami\Stethoscope\LogRecord\Facades\Record; |
|
7
|
|
|
use MohsenAbrishami\Stethoscope\Services\Cpu; |
|
8
|
|
|
use MohsenAbrishami\Stethoscope\Services\HardDisk; |
|
9
|
|
|
use MohsenAbrishami\Stethoscope\Services\Memory; |
|
10
|
|
|
use MohsenAbrishami\Stethoscope\Services\Network; |
|
11
|
|
|
use MohsenAbrishami\Stethoscope\Services\WebServer; |
|
12
|
|
|
|
|
13
|
|
|
class MonitorCommand extends Command |
|
14
|
|
|
{ |
|
15
|
|
|
public function __construct(Cpu $cpu, Memory $memory, Network $network, WebServer $webServer, HardDisk $hardDisk) |
|
16
|
|
|
{ |
|
17
|
|
|
parent::__construct(); |
|
18
|
|
|
|
|
19
|
|
|
$this->cpu = $cpu; |
|
|
|
|
|
|
20
|
|
|
$this->memory = $memory; |
|
|
|
|
|
|
21
|
|
|
$this->network = $network; |
|
|
|
|
|
|
22
|
|
|
$this->webServer = $webServer; |
|
|
|
|
|
|
23
|
|
|
$this->hardDisk = $hardDisk; |
|
|
|
|
|
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* The name and signature of the console command. |
|
29
|
|
|
* |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $signature = 'stethoscope:monitor'; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* The console command description. |
|
36
|
|
|
* |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $description = 'monitor memory usage, cpu usage, network connection and nginx status'; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Execute the console command. |
|
43
|
|
|
* |
|
44
|
|
|
* @return int |
|
45
|
|
|
*/ |
|
46
|
|
|
public function handle() |
|
47
|
|
|
{ |
|
48
|
|
|
$cpuUsage = $this->cpu->check(); |
|
49
|
|
|
$memoryUsage = $this->memory->check(); |
|
50
|
|
|
$networkStatus = $this->network->check(); |
|
51
|
|
|
$webServerStatuses = $this->webServer->check(); |
|
52
|
|
|
$hardDiskFreeSpace = $this->hardDisk->check(); |
|
53
|
|
|
|
|
54
|
|
|
Record::record($cpuUsage, $memoryUsage, $networkStatus, $webServerStatuses, $hardDiskFreeSpace); |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|