|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MohsenAbrishami\Stethoscope\LogRecord\Drivers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Storage; |
|
6
|
|
|
use MohsenAbrishami\Stethoscope\LogRecord\Contracts\LogRecordInterface; |
|
7
|
|
|
use MohsenAbrishami\Stethoscope\Traits\MessageCreatorTrait; |
|
8
|
|
|
|
|
9
|
|
|
class FileDriver implements LogRecordInterface |
|
10
|
|
|
{ |
|
11
|
|
|
use MessageCreatorTrait; |
|
12
|
|
|
|
|
13
|
|
|
public function record($cpuUsage, $memoryUsage, $networkStatus, $webServerStatuses, $hardDiskFreeSpace) |
|
14
|
|
|
{ |
|
15
|
|
|
$file = config('stethoscope.log_file_storage.path') . now()->format('Y-m-d'); |
|
16
|
|
|
|
|
17
|
|
|
$this->storage = Storage::disk(config('stethoscope.log_file_storage.driver')); |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
$log = ''; |
|
20
|
|
|
|
|
21
|
|
|
if ($cpuUsage > config(('stethoscope.thresholds.cpu')) && config('stethoscope.monitorable_resources.cpu')) |
|
22
|
|
|
$log .= $this->cpuMessage($cpuUsage) . "\n"; |
|
23
|
|
|
|
|
24
|
|
|
if ($memoryUsage > config(('stethoscope.thresholds.memory')) && config('stethoscope.monitorable_resources.memory')) |
|
25
|
|
|
$log .= $this->memoryMessage($memoryUsage) . "\n"; |
|
26
|
|
|
|
|
27
|
|
|
if (!$networkStatus && config('stethoscope.monitorable_resources.network')) |
|
28
|
|
|
$log .= $this->networkMessage($networkStatus) . "\n"; |
|
29
|
|
|
|
|
30
|
|
|
if (($webServerStatuses['nginx'] != 'active' && config('stethoscope.monitorable_resources.web_server'))) { |
|
31
|
|
|
$log .= $this->webServerMessage('nginx', $webServerStatuses['nginx']) . "\n"; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
if (($webServerStatuses['apache'] != 'active' && config('stethoscope.monitorable_resources.web_server'))) { |
|
35
|
|
|
$log .= $this->webServerMessage('apache', $webServerStatuses['apache']) . "\n"; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
if ($hardDiskFreeSpace < config(('stethoscope.thresholds.hard_disk')) && config('stethoscope.monitorable_resources.hard_disk')) |
|
39
|
|
|
$log .= $this->hardDiskMessage($hardDiskFreeSpace) . "\n"; |
|
40
|
|
|
|
|
41
|
|
|
if ($log != '') { |
|
42
|
|
|
$log = $this->timeMessage() . "\n" . $log; |
|
43
|
|
|
|
|
44
|
|
|
if ($this->storage->exists($file)) |
|
45
|
|
|
$log = $this->storage->get($file) . "\n \n" . $log; |
|
46
|
|
|
|
|
47
|
|
|
$this->storage->put($file, $log); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|