mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
log count of logged in users in Database (#13137)
* log count of logged in users in Database * . * rewrite Code * create hrSystem Table * . * . * db adjustments * adjust db Table * . * adjust db Table * table redesign * . * .
This commit is contained in:
@@ -631,6 +631,11 @@ class Device extends BaseModel
|
||||
return $this->hasMany(HrDevice::class, 'device_id');
|
||||
}
|
||||
|
||||
public function hostResourceValues(): HasMany
|
||||
{
|
||||
return $this->hasMany(HrSystem::class, 'device_id');
|
||||
}
|
||||
|
||||
public function entityPhysical(): HasMany
|
||||
{
|
||||
return $this->hasMany(EntPhysical::class, 'device_id');
|
||||
|
12
app/Models/HrSystem.php
Normal file
12
app/Models/HrSystem.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class HrSystem extends DeviceRelatedModel
|
||||
{
|
||||
public $timestamps = false;
|
||||
protected $table = 'hrSystem';
|
||||
protected $fillable = ['hrSystemNumUsers', 'hrSystemProcesses', 'hrSystemMaxProcesses'];
|
||||
|
||||
protected $primaryKey = 'hrSystem_id';
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class CreateHrSystemTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('hrSystem', function (Blueprint $table) {
|
||||
$table->increments('hrSystem_id');
|
||||
$table->unsignedInteger('device_id')->index();
|
||||
$table->integer('hrSystemNumUsers')->default(0);
|
||||
$table->integer('hrSystemProcesses')->default(0);
|
||||
$table->integer('hrSystemMaxProcesses')->default(0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('hrSystem');
|
||||
}
|
||||
}
|
@@ -2,11 +2,15 @@
|
||||
|
||||
// HOST-RESOURCES-MIB
|
||||
// Generic System Statistics
|
||||
|
||||
use App\Models\Device;
|
||||
use LibreNMS\RRD\RrdDefinition;
|
||||
|
||||
$oid_list = ['hrSystemProcesses.0', 'hrSystemNumUsers.0'];
|
||||
$oid_list = ['hrSystemMaxProcesses.0', 'hrSystemProcesses.0', 'hrSystemNumUsers.0'];
|
||||
$hrSystem = snmp_get_multi($device, $oid_list, '-OUQs', 'HOST-RESOURCES-MIB');
|
||||
|
||||
$current_device = Device::find($device['device_id']);
|
||||
|
||||
if (is_numeric($hrSystem[0]['hrSystemProcesses'])) {
|
||||
$tags = [
|
||||
'rrd_def' => RrdDefinition::make()->addDataset('procs', 'GAUGE', 0),
|
||||
@@ -31,6 +35,10 @@ if (is_numeric($hrSystem[0]['hrSystemNumUsers'])) {
|
||||
|
||||
data_update($device, 'hr_users', $tags, $fields);
|
||||
|
||||
$current_device->hostResourceValues()->updateOrCreate(['device_id' => $current_device->id, 'key' => 'num_users'],
|
||||
['hrSystemNumUsers' => $hrSystem[0]['hrSystemNumUsers'],
|
||||
'hrSystemProcesses' => $hrSystem[0]['hrSystemProcesses'],
|
||||
'hrSystemMaxProcesses' => $hrSystem[0]['hrSystemMaxProcesses'], ]);
|
||||
$os->enableGraph('hr_users');
|
||||
echo ' Users';
|
||||
}
|
||||
|
@@ -729,6 +729,16 @@ hrDevice:
|
||||
Indexes:
|
||||
PRIMARY: { Name: PRIMARY, Columns: [hrDevice_id], Unique: true, Type: BTREE }
|
||||
hrdevice_device_id_index: { Name: hrdevice_device_id_index, Columns: [device_id], Unique: false, Type: BTREE }
|
||||
hrSystem:
|
||||
Columns:
|
||||
- { Field: hrSystem_id, Type: 'int unsigned', 'Null': false, Extra: auto_increment }
|
||||
- { Field: device_id, Type: 'int unsigned', 'Null': false, Extra: '' }
|
||||
- { Field: hrSystemNumUsers, Type: int, 'Null': false, Extra: '', Default: '0' }
|
||||
- { Field: hrSystemProcesses, Type: int, 'Null': false, Extra: '', Default: '0' }
|
||||
- { Field: hrSystemMaxProcesses, Type: int, 'Null': false, Extra: '', Default: '0' }
|
||||
Indexes:
|
||||
PRIMARY: { Name: PRIMARY, Columns: [hrSystem_id], Unique: true, Type: BTREE }
|
||||
hrsystem_device_id_index: { Name: hrsystem_device_id_index, Columns: [device_id], Unique: false, Type: BTREE }
|
||||
ipsec_tunnels:
|
||||
Columns:
|
||||
- { Field: tunnel_id, Type: 'int unsigned', 'Null': false, Extra: auto_increment }
|
||||
|
Reference in New Issue
Block a user