mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Availability Calculation for all Devices (#12004)
* Availability Calculation for all Devices * remove not more need uptime column
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class DropUptimeColumnOutages extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('device_outages', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'uptime',
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('device_outages', function (Blueprint $table) {
|
||||
$table->bigInteger('uptime')->nullable();
|
||||
});
|
||||
}
|
||||
}
|
@@ -2125,35 +2125,33 @@ function device_is_up($device, $record_perf = false)
|
||||
array($device['device_id'])
|
||||
);
|
||||
|
||||
$uptime = $device['uptime'] ?: 0;
|
||||
|
||||
if ($response['status']) {
|
||||
$type = 'up';
|
||||
$reason = $device['status_reason'];
|
||||
|
||||
if ($device['uptime']) {
|
||||
$going_down = dbFetchCell('SELECT going_down FROM device_outages WHERE device_id=? AND up_again IS NULL', array($device['device_id']));
|
||||
if (!empty($going_down)) {
|
||||
$up_again = time() - $device['uptime'];
|
||||
if ($up_again <= $going_down) {
|
||||
# network connection loss, not device down
|
||||
$up_again = time();
|
||||
}
|
||||
dbUpdate(
|
||||
array('device_id' => $device['device_id'], 'up_again' => $up_again),
|
||||
'device_outages',
|
||||
'device_id=? and up_again is NULL',
|
||||
array($device['device_id'])
|
||||
);
|
||||
$going_down = dbFetchCell('SELECT going_down FROM device_outages WHERE device_id=? AND up_again IS NULL', array($device['device_id']));
|
||||
if (!empty($going_down)) {
|
||||
$up_again = time() - $uptime;
|
||||
if ($up_again <= $going_down) {
|
||||
# network connection loss, not device down
|
||||
$up_again = time();
|
||||
}
|
||||
dbUpdate(
|
||||
array('device_id' => $device['device_id'], 'up_again' => $up_again),
|
||||
'device_outages',
|
||||
'device_id=? and up_again is NULL',
|
||||
array($device['device_id'])
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$type = 'down';
|
||||
$reason = $response['status_reason'];
|
||||
if ($device['uptime']) {
|
||||
$data = ['device_id' => $device['device_id'],
|
||||
'uptime' => $device['uptime'],
|
||||
'going_down' => strtotime($device['last_polled'])];
|
||||
dbInsert($data, 'device_outages');
|
||||
}
|
||||
|
||||
$data = ['device_id' => $device['device_id'],
|
||||
'going_down' => strtotime($device['last_polled'])];
|
||||
dbInsert($data, 'device_outages');
|
||||
}
|
||||
|
||||
log_event('Device status changed to ' . ucfirst($type) . " from $reason check.", $device, $type);
|
||||
|
@@ -3,44 +3,42 @@
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\RRD\RrdDefinition;
|
||||
|
||||
if (isset($device['uptime']) && ($device['uptime'] > 0 )) {
|
||||
$os->enableGraph('availability');
|
||||
$os->enableGraph('availability');
|
||||
|
||||
$col = dbFetchColumn('SELECT duration FROM availability WHERE device_id = ?', array($device['device_id']));
|
||||
foreach (Config::get('graphing.availability') as $duration) {
|
||||
if (!in_array($duration, $col)) {
|
||||
$data = ['device_id' => $device['device_id'],
|
||||
'duration' => $duration];
|
||||
dbInsert($data, 'availability');
|
||||
}
|
||||
$col = dbFetchColumn('SELECT duration FROM availability WHERE device_id = ?', array($device['device_id']));
|
||||
foreach (Config::get('graphing.availability') as $duration) {
|
||||
if (!in_array($duration, $col)) {
|
||||
$data = ['device_id' => $device['device_id'],
|
||||
'duration' => $duration];
|
||||
dbInsert($data, 'availability');
|
||||
}
|
||||
|
||||
echo 'Availability: ' . PHP_EOL;
|
||||
|
||||
foreach (dbFetchRows('SELECT * FROM availability WHERE device_id = ?', array($device['device_id'])) as $row) {
|
||||
//delete not more interested availabilities
|
||||
if (!in_array($row['duration'], Config::get('graphing.availability'))) {
|
||||
dbDelete('availability', 'availability_id=?', array($row['availability_id']));
|
||||
continue;
|
||||
}
|
||||
|
||||
$avail = \LibreNMS\Device\Availability::availability($device, $row['duration']);
|
||||
$human_time = \LibreNMS\Util\Time::humanTime($row['duration']);
|
||||
|
||||
$rrd_name = array('availability', $row['duration']);
|
||||
$rrd_def = RrdDefinition::make()
|
||||
->addDataset('availability', 'GAUGE', 0);
|
||||
|
||||
$fields = array(
|
||||
'availability' => $avail,
|
||||
);
|
||||
|
||||
$tags = array('name' => $row['duration'], 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'availability', $tags, $fields);
|
||||
|
||||
dbUpdate(array('availability_perc' => $avail), 'availability', '`availability_id` = ?', array($row['availability_id']));
|
||||
|
||||
echo $human_time . ' : ' . $avail . '%'. PHP_EOL;
|
||||
}
|
||||
unset($duration);
|
||||
}
|
||||
|
||||
echo 'Availability: ' . PHP_EOL;
|
||||
|
||||
foreach (dbFetchRows('SELECT * FROM availability WHERE device_id = ?', array($device['device_id'])) as $row) {
|
||||
//delete not more interested availabilities
|
||||
if (!in_array($row['duration'], Config::get('graphing.availability'))) {
|
||||
dbDelete('availability', 'availability_id=?', array($row['availability_id']));
|
||||
continue;
|
||||
}
|
||||
|
||||
$avail = \LibreNMS\Device\Availability::availability($device, $row['duration']);
|
||||
$human_time = \LibreNMS\Util\Time::humanTime($row['duration']);
|
||||
|
||||
$rrd_name = array('availability', $row['duration']);
|
||||
$rrd_def = RrdDefinition::make()
|
||||
->addDataset('availability', 'GAUGE', 0);
|
||||
|
||||
$fields = array(
|
||||
'availability' => $avail,
|
||||
);
|
||||
|
||||
$tags = array('name' => $row['duration'], 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'availability', $tags, $fields);
|
||||
|
||||
dbUpdate(array('availability_perc' => $avail), 'availability', '`availability_id` = ?', array($row['availability_id']));
|
||||
|
||||
echo $human_time . ' : ' . $avail . '%'. PHP_EOL;
|
||||
}
|
||||
unset($duration);
|
||||
|
@@ -291,10 +291,10 @@ function poll_device($device, $force_module = false)
|
||||
|
||||
if ($response['status'] == '1') {
|
||||
if ($device['snmp_disable']) {
|
||||
Config::set('poller_modules', []);
|
||||
Config::set('poller_modules', ['availability' => true]);
|
||||
} else {
|
||||
// we always want the core module to be included, prepend it
|
||||
Config::set('poller_modules', ['core' => true] + Config::get('poller_modules'));
|
||||
Config::set('poller_modules', ['core' => true, 'availability' => true] + Config::get('poller_modules'));
|
||||
}
|
||||
|
||||
printChangedStats(true); // don't count previous stats
|
||||
|
@@ -4091,13 +4091,6 @@
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
},
|
||||
"poller_modules.availability": {
|
||||
"order": 25,
|
||||
"group": "poller",
|
||||
"section": "poller_modules",
|
||||
"default": true,
|
||||
"type": "boolean"
|
||||
},
|
||||
"poller_modules.os": {
|
||||
"order": 320,
|
||||
"group": "poller",
|
||||
|
@@ -575,7 +575,6 @@ device_outages:
|
||||
- { Field: device_id, Type: 'int unsigned', 'Null': false, Extra: '' }
|
||||
- { Field: going_down, Type: bigint, 'Null': false, Extra: '' }
|
||||
- { Field: up_again, Type: bigint, 'Null': true, Extra: '' }
|
||||
- { Field: uptime, Type: bigint, 'Null': true, Extra: '' }
|
||||
Indexes:
|
||||
device_outages_device_id_index: { Name: device_outages_device_id_index, Columns: [device_id], Unique: false, Type: BTREE }
|
||||
device_outages_device_id_going_down_unique: { Name: device_outages_device_id_going_down_unique, Columns: [device_id, going_down], Unique: true, Type: BTREE }
|
||||
|
Reference in New Issue
Block a user