Skip to content

Commit

Permalink
log count of logged in users in Database (librenms#13137)
Browse files Browse the repository at this point in the history
* log count of logged in users in Database

* .

* rewrite Code

* create hrSystem Table

* .

* .

* db adjustments

* adjust db Table

* .

* adjust db Table

* table redesign

* .

* .
  • Loading branch information
SourceDoctor authored Oct 1, 2021
1 parent a828bb0 commit f47410e
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/Models/Device.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,11 @@ public function hostResources(): HasMany
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');
Expand Down
12 changes: 12 additions & 0 deletions app/Models/HrSystem.php
Original file line number Diff line number Diff line change
@@ -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';
}
33 changes: 33 additions & 0 deletions database/migrations/2021_09_26_164200_create_hrsystem_table.php
Original file line number Diff line number Diff line change
@@ -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');
}
}
10 changes: 9 additions & 1 deletion includes/polling/hr-mib.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -31,6 +35,10 @@

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';
}
Expand Down
10 changes: 10 additions & 0 deletions misc/db_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit f47410e

Please sign in to comment.