77 lines
1.7 KiB
PHP
77 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class Logging extends Controller
|
|
{
|
|
|
|
private $_items = [ 'netstat_sent' => 'i', 'netstat_recv' => 'i', 'memory_free' => 'f', 'memory_total' => 'f', 'memory_used' => 'f', 'disk_free' => 'B', 'disk_percent' => 'f', 'disk_used' => 'B', 'disk_total' => 'B', 'processes' => 'i', 'temp' => 'i', 'username' =>'s', 'computer' => 's'];
|
|
|
|
private $_values = [];
|
|
|
|
public function __construct() {
|
|
|
|
}
|
|
|
|
function conv_bytes($v) {
|
|
$units = explode(' ', ' K M G T P E Z Y');
|
|
|
|
preg_match('/([0-9]+)([GKMTgkmT])?B/',$v,$vu);
|
|
$v1 = $vu[1];
|
|
if (count($vu) == 3)
|
|
$v2 = $vu[2];
|
|
else
|
|
$v2 = '';
|
|
|
|
$pos = array_search($v2,$units);
|
|
|
|
$num = floatval($v1) * pow(1024,$pos);
|
|
|
|
return $num;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function parse($vals) {
|
|
foreach ($vals as $k => $v)
|
|
{
|
|
if (is_array($k)) {
|
|
foreach ($v as $k2 => $v2) {
|
|
$this->_values["$k"."_"."$k2"] = $v2;
|
|
}
|
|
} else {
|
|
$this->_values[$k] = $v;
|
|
}
|
|
}
|
|
|
|
foreach ($this->_items as $k => $v) {
|
|
$t = $this->_items[$k];
|
|
if ($t == 's') continue;
|
|
|
|
if ($t == 'B') $v = $this->conv_bytes($v);
|
|
|
|
if ($t == 'f') $v = floatval($v);
|
|
if ($t == 'i') $v = intval($v);
|
|
|
|
$this->_values[$k] = $v;
|
|
}
|
|
}
|
|
|
|
public function log(Request $request) {
|
|
$data = json_decode($request->getContent(), true);
|
|
$v = $data["values"];
|
|
$i = $data["items"];
|
|
var_export($v);
|
|
// $this->parse($v);
|
|
|
|
// var_dump($this->_values);
|
|
|
|
return "OK";
|
|
//DB::insert('insert into values (user,computer,recv,send) values (?, ?, ?, ?)', [$u, $c, $r, $s]);
|
|
}
|
|
}
|