|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MohsenAbrishami\Stethoscope\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\DB; |
|
6
|
|
|
use MohsenAbrishami\Stethoscope\Models\ResourceLog; |
|
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 MonitorController extends Controller |
|
14
|
|
|
{ |
|
15
|
|
|
public function current(Cpu $cpu, Memory $memory, Network $network, WebServer $webServer, HardDisk $hardDisk) |
|
16
|
|
|
{ |
|
17
|
|
|
return response()->json([ |
|
18
|
|
|
'cpu' => $cpu->check(), |
|
19
|
|
|
'memory' => $memory->check(), |
|
20
|
|
|
'network' => $network->check(), |
|
21
|
|
|
'web_server' => $webServer->check(), |
|
22
|
|
|
'hard_disk' => $hardDisk->check(), |
|
23
|
|
|
]); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function history($from, $to) |
|
27
|
|
|
{ |
|
28
|
|
|
$resourceLogs = ResourceLog::select('date', DB::raw('count(date)'))->orderBy('date') |
|
29
|
|
|
->from( |
|
30
|
|
|
ResourceLog::whereDate('created_at', '>=', $from) |
|
31
|
|
|
->whereDate('created_at', '<=', $to) |
|
32
|
|
|
->select(DB::raw('date(created_at) as date')), |
|
33
|
|
|
'count' |
|
34
|
|
|
)->groupBy('date')->get(); |
|
35
|
|
|
|
|
36
|
|
|
return response()->json($resourceLogs); |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|