-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e63bb9
commit 58e9f16
Showing
7 changed files
with
122 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
<?php | ||
|
||
/* | ||
* You can place your custom package configuration in here. | ||
*/ | ||
return [ | ||
|
||
]; | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Monitoring Configuration File | ||
|-------------------------------------------------------------------------- | ||
*/ | ||
|
||
'key' => env('MONITOR_KEY'), | ||
|
||
|
||
]; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace chrissantiago82\monitor; | ||
|
||
|
||
class MonitorClass | ||
{ | ||
|
||
public $results = []; | ||
|
||
function __construct() | ||
{ | ||
$this->getDiskSpace(); | ||
$this->getMemory(); | ||
$this->getCpuLoad(); | ||
} | ||
|
||
|
||
protected function getDiskSpace() | ||
{ | ||
$this->results['freeDiskPro'] = round(100/(disk_total_space("/") / disk_free_space("/")), 1); | ||
$this->results['freeDiskGB'] = round(disk_free_space("/") / (1000 * 1000 * 1000), 1); | ||
} | ||
|
||
protected function getMemory() | ||
{ | ||
//RAM usage | ||
$free = shell_exec('free'); | ||
$free = (string) trim($free); | ||
$free_arr = explode("\n", $free); | ||
$mem = explode(" ", $free_arr[1]); | ||
$mem = array_filter($mem); | ||
$mem = array_merge($mem); | ||
$usedmem = $mem[2]; | ||
$usedmemInGB = number_format($usedmem / 1048576, 2) . ' GB'; | ||
$memory1 = $mem[2] / $mem[1] * 100; | ||
$memory = round($memory1, 1); | ||
$fh = fopen('/proc/meminfo', 'r'); | ||
$mem = 0; | ||
while ($line = fgets($fh)) { | ||
$pieces = array(); | ||
if (preg_match('/^MemTotal:\s+(\d+)\skB$/', $line, $pieces)) { | ||
$mem = $pieces[1]; | ||
break; | ||
} | ||
} | ||
fclose($fh); | ||
$totalram = number_format($mem / 1048576, 2) . ' GB'; | ||
|
||
$this->results['memoryLoad'] = $memory; | ||
|
||
|
||
} | ||
|
||
protected function getCpuLoad() | ||
{ | ||
$load2 = sys_getloadavg(); | ||
|
||
$command = "cat /proc/cpuinfo | grep processor | wc -l"; | ||
$coreCount = (int) shell_exec($command); | ||
$load2 = round($load2[2] / $coreCount, 2); | ||
|
||
$this->results['cpuLoad'] = $load2; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace chrissantiago82\monitor; | ||
|
||
use Illuminate\Http\Request; | ||
use App\Http\Requests; | ||
use App\Http\Controllers\Controller; | ||
|
||
|
||
class MonitorController extends Controller | ||
{ | ||
|
||
public function monitor($key) | ||
{ | ||
|
||
if (config('krebsmonitor.key') === null) { | ||
return; | ||
} | ||
|
||
if (config('krebsmonitor.key') != $key) { | ||
return; | ||
} | ||
|
||
//$monitorClass = new Monitor(); | ||
|
||
$monitorClass = new MonitorClass(); | ||
|
||
|
||
return response()->json($monitorClass->results); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
|
||
|
||
Route::GET('/krebscmonitor/{key}', 'chrissantiago82\monitor\MonitorController@monitor'); |