Passed
Pull Request — main (#85)
by mohsen
11:07
created

MonitorController::current()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 5
dl 0
loc 8
rs 10
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