Oprava chyb v Logging.php, uprava tabuliek

- oprava tabuliek created_at, CURRENT_TIMESTAMP
- pridanie memory_total, load
- apcu fix
This commit is contained in:
2019-11-22 10:38:09 +01:00
parent 8caa7c227b
commit 72dbd62686
5 changed files with 28 additions and 25 deletions

View File

@@ -8,7 +8,7 @@ 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 $_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', 'load' => 'f', 'username' =>'s', 'computer' => 's'];
private $_values = [];
private $_ucache = [];
@@ -26,7 +26,7 @@ class Logging extends Controller
foreach ($q as $v) {
$this->_ucache[$v->name] = $v->id;
}
\apcu_add('users',$this->_ucache);
\apcu_store('users',$this->_ucache);
}
$this->_ccache = \apcu_fetch('computers',$ret);
if ($ret == false ) {
@@ -34,31 +34,32 @@ class Logging extends Controller
foreach ($q as $v) {
$this->_ucache[$v->computer] = $v->id;
}
\apcu_add('computers',$this->_ccache);
\apcu_store('computers',$this->_ccache);
}
}
private function get_computer_id($comp){
if ($this->_ccache[$comp]) {
if (isset($this->_ccache[$comp])) {
return $this->_ccache[$comp];
}
$id = DB::table('computers')->insertGetId(['computer' => $comp]);
$this->_ccache[$comp] = $id;
\apcu_add('computers',$this->_ccache);
\apc_store('computers',$this->_ccache);
return $id;
}
private function get_user_id($user) {
if ($this->_ucache[$user]) {
if (isset($this->_ucache[$user])) {
return $this->_ucache[$user];
}
$id = DB::table('users')->insertGetId(['name' => $user]);
$id = DB::table('users')->insertGetId(['name' => $user, 'email' => $user]);
$this->_ucache[$user] = $id;
\apcu_add('users',$this->_ucache);
\apcu_store('users',$this->_ucache);
return $id;
}
@@ -116,9 +117,9 @@ class Logging extends Controller
$this->parse($v);
$ia = array_filter($this->_values, function($v) {
return $v != 's';
});
$ia = array_merge($this->_values);
unset($ia["computer"]);
unset($ia["username"]);
$cid = $this->get_computer_id($this->_values["computer"]);
$uid = $this->get_user_id($this->_values["username"]);

View File

@@ -17,11 +17,11 @@ class CreateUsersTable extends Migration
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->string('full_name');
$table->string('ou');
$table->string('password')->nullable();
$table->string('full_name')->nullable();
$table->string('ou')->nullable();
$table->rememberToken();
$table->timestamps();
$table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
$table->index([DB::raw('email(191)')]);
});

View File

@@ -15,8 +15,8 @@ class CreateComputersTable extends Migration
{
Schema::create('computers', function (Blueprint $table) {
$table->increments('id');
$table->string('computer');
$table->timestamps();
$table->string('computer');
$table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
});
}

View File

@@ -15,15 +15,15 @@ class CreateUserIpTable extends Migration
{
Schema::create('user_ip', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('ip');
$table->string('ip');
$table->unsignedInteger('computer_id');
$table->foreign('computer_id')->references('id')->on('computers');
$table->unsignedInteger('computer_id');
$table->foreign('computer_id')->references('id')->on('computers');
$table->unsignedInteger('user_id');
$table->foreign('user_id')->references('id')->on('users');
$table->unsignedInteger('user_id');
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
$table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
});
}

View File

@@ -17,15 +17,17 @@ class CreateValuesTable extends Migration
$table->bigIncrements('id');
$table->bigInteger('netstat_sent')->nullable();
$table->bigInteger('netstat_recv')->nullable();
$table->bigInteger('memory_total')->nullable();
$table->bigInteger('memory_free')->nullable();
$table->bigInteger('memory_used')->nullable();
$table->bigInteger('disk_free')->nullable();
$table->float('disk_percent',8,2)->nullable();
$table->float('disk_percent',8,2)->nullable();
$table->float('load',8,2)->nullable();
$table->bigInteger('disk_used')->nullable();
$table->bigInteger('disk_total')->nullable();
$table->integer('processes')->nullable();
$table->integer('temp')->nullable();
$table->timestamps();
$table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
$table->unsignedBigInteger('computer_id');
$table->foreign('computer_id')->references('id')->on('computers');