Revert "Change mempools summary graph to show values (#12349)" (#12354)

This reverts commit 7a027f8467.
This commit is contained in:
Tony Murray 2020-11-25 10:10:01 -06:00 committed by GitHub
parent 7a027f8467
commit 23e8544913
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 61 additions and 135 deletions

View File

@ -26,7 +26,6 @@
namespace LibreNMS\Modules;
use App\Models\Mempool;
use App\Observers\MempoolObserver;
use Illuminate\Support\Collection;
use LibreNMS\DB\SyncsModels;
use LibreNMS\Interfaces\Discovery\MempoolsDiscovery;
@ -34,6 +33,7 @@ use LibreNMS\Interfaces\Module;
use LibreNMS\Interfaces\Polling\MempoolsPolling;
use LibreNMS\OS;
use LibreNMS\RRD\RrdDefinition;
use LibreNMS\Util\ModuleModelObserver;
use Log;
class Mempools implements Module
@ -53,7 +53,7 @@ class Mempools implements Module
});
$this->calculateAvailable($mempools);
MempoolObserver::observe('\App\Models\Mempool');
ModuleModelObserver::observe('\App\Models\Mempool');
$this->syncModels($os->getDevice(), 'mempools', $mempools);
echo PHP_EOL;
@ -80,9 +80,8 @@ class Mempools implements Module
if (empty($mempool->mempool_class)) {
Log::debug('Mempool skipped. Does not include class.');
return;
}
$mempool->save();
$rrd_name = ['mempool', $mempool->mempool_type, $mempool->mempool_class, $mempool->mempool_index];

View File

@ -26,12 +26,12 @@
namespace LibreNMS\Modules;
use App\Observers\ModuleModelObserver;
use LibreNMS\DB\SyncsModels;
use LibreNMS\Interfaces\Discovery\MplsDiscovery;
use LibreNMS\Interfaces\Module;
use LibreNMS\Interfaces\Polling\MplsPolling;
use LibreNMS\OS;
use LibreNMS\Util\ModuleModelObserver;
class Mpls implements Module
{

View File

@ -25,10 +25,10 @@
namespace LibreNMS\Modules;
use App\Models\PortsNac;
use App\Observers\ModuleModelObserver;
use LibreNMS\Interfaces\Module;
use LibreNMS\Interfaces\Polling\NacPolling;
use LibreNMS\OS;
use LibreNMS\Util\ModuleModelObserver;
class Nac implements Module
{

View File

@ -26,8 +26,8 @@
namespace LibreNMS\OS;
use App\Models\TnmsneInfo;
use App\Observers\ModuleModelObserver;
use LibreNMS\Interfaces\Polling\OSPolling;
use LibreNMS\Util\ModuleModelObserver;
use Log;
class Coriant extends \LibreNMS\OS implements OSPolling

View File

@ -169,7 +169,7 @@ trait HostResources
'mempool_perc_warn' => $this->memoryDescrWarn[$storage['hrStorageDescr']] ?? 90,
'mempool_used_oid' => ".1.3.6.1.2.1.25.2.3.1.6.$index",
'mempool_total_oid' => null,
]))->setClass(null, $storage['hrStorageType'] == 'hrStorageVirtualMemory' ? 'virtual' : 'system')
]))->setClass($storage['hrStorageType'] == 'hrStorageVirtualMemory' ? 'virtual' : null)
->fillUsage($storage['hrStorageUsed'], $total);
});
}

View File

@ -1,6 +1,6 @@
<?php
/*
* ModuleModelObserver.php
/**
* DiscoveryModelObserver.php
*
* Displays +,-,U,. while running discovery and adding,deleting,updating, and doing nothing.
*
@ -18,11 +18,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @link http://librenms.org
* @copyright 2020 Tony Murray
* @copyright 2018 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace App\Observers;
namespace LibreNMS\Util;
use Illuminate\Database\Eloquent\Model as Eloquent;

View File

@ -95,11 +95,10 @@ class Mempool extends DeviceRelatedModel implements Keyable
/**
* Set the mempool class. If no class is given, try to detect it from available data.
*
* @param string $class
* @param string $default
* @param null $class
* @return \App\Models\Mempool
*/
public function setClass($class = null, $default = 'system')
public function setClass($class = null)
{
if ($class) {
$this->mempool_class = $class;
@ -125,14 +124,7 @@ class Mempool extends DeviceRelatedModel implements Keyable
return $this;
}
}
if ($default == 'virtual' && Str::contains($this->mempool_descr, ['/dev/'])) {
$this->mempool_class = 'swap';
return $this;
}
$this->mempool_class = $default;
$this->mempool_class = 'system'; // just call everything else system
return $this;
}

View File

@ -1,46 +0,0 @@
<?php
/*
* MempoolObserver.php
*
* Observe Mempool changes during discovery
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2020 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace App\Observers;
use Illuminate\Database\Eloquent\Model as Eloquent;
use Log;
class MempoolObserver extends ModuleModelObserver
{
public function updated(Eloquent $model)
{
parent::updated($model);
if ($model->isDirty('mempool_class')) {
Log::debug("Mempool class changed $model->mempool_descr ($model->mempool_id)");
rrd_file_rename(
$model->device->toArray(),
['mempool', $model->mempool_type, $model->getOriginal('mempool_class'), $model->mempool_index],
['mempool', $model->mempool_type, $model->mempool_class, $model->mempool_index]
);
}
}
}

View File

@ -4,7 +4,8 @@ use App\Models\Mempool;
require 'includes/html/graphs/common.inc.php';
$rrd_options .= ' -E -b 1024 ';
$rrd_options .= ' -u 100 -l 0 -E -b 1024 ';
$rrd_options .= " COMMENT:' Min Cur Max Used\\n'";
// order mempools properly
$mempool_classes = [
@ -28,25 +29,18 @@ $mempools = DeviceCache::get($device['device_id'])->mempools->sort(function (Mem
// find available
$available = null;
$swap_present = false;
foreach ($mempools as $index => $mempool) {
if ($mempool->mempool_class == 'available') {
$available = $mempool;
$mempools->forget($index);
} elseif ($mempool->mempool_class == 'swap') {
$swap_present = true;
}
}
if (! $swap_present) {
$rrd_options .= '-l 0 '; // swap is negative axis
$available_key = $mempools->search(function (Mempool $mempool) {
return $mempool->mempool_class == 'available';
});
if ($available_key !== false) {
$available = $mempools->get($available_key);
$mempools->forget($available_key);
}
$colors = \LibreNMS\Config::get('graph_colours.varied');
$legend_sections = [0 => '', 1 => ''];
$section = 0;
$free_indexes = [];
$rrd_options .= " COMMENT:' Min Max Cur \\n'";
/** @var \App\Models\Mempool $mempool */
foreach ($mempools as $index => $mempool) {
@ -58,37 +52,24 @@ foreach ($mempools as $index => $mempool) {
if (rrdtool_check_rrd_exists($rrd_filename)) {
$rrd_options .= " DEF:mempoolfree$index=$rrd_filename:free:AVERAGE ";
$rrd_options .= " DEF:mempoolused$index=$rrd_filename:used:AVERAGE ";
$rrd_options .= " CDEF:mempooltotal$index=mempoolused$index,mempoolfree$index,+ ";
$rrd_options .= " CDEF:mempoolpercent$index=mempoolused$index,mempooltotal$index,/,100,* ";
$rrd_options .= " CDEF:mempooltotal$index=mempoolused$index,mempoolused$index,mempoolfree$index,+,/,100,* ";
$system_pools = in_array($mempool->mempool_class, ['system', 'cached', 'buffers']);
$stack = $system_pools && $index > 0 ? ':STACK' : '';
if ($system_pools) {
$free_indexes[] = $index;
$rrd_options .= " AREA:mempoolused$index#{$color}70:$stack";
$rrd_options .= " AREA:mempooltotal$index#{$color}70:$stack";
}
if ($mempool->mempool_class == 'system') {
// add system
$legend_sections[1] .= " LINE1:mempooltotal$index#AAAAAA:'Total '";
$legend_sections[1] .= " GPRINT:mempooltotal$index:LAST:%6.2lf%siB\\l ";
}
if ($mempool->mempool_class == 'swap') {
$section = 2;
$rrd_options .= " CDEF:mempoolswap$index=mempoolused$index,-1,* ";
$rrd_options .= " AREA:mempoolswap$index#{$color}70:$stack";
$legend_sections[$section] .= " LINE1.5:mempoolswap$index#$color:'$descr'$stack";
} elseif ($mempool->mempool_class == 'virtual') {
$section = 2;
$legend_sections[$section] .= " COMMENT:' $descr'";
} else {
$legend_sections[$section] .= " LINE1.5:mempoolused$index#$color:'$descr'$stack";
}
$legend_sections[$section] .= " GPRINT:mempoolpercent$index:MIN:%3.0lf%%";
$legend_sections[$section] .= " GPRINT:mempoolpercent$index:MAX:%3.0lf%%";
$legend_sections[$section] .= " GPRINT:mempoolpercent$index:LAST:%3.0lf%%";
$legend_sections[$section] .= " GPRINT:mempoolused$index:LAST:%6.2lf%siB\\l ";
$legend_sections[$section] .= " LINE1.5:mempooltotal$index#$color:'$descr'$stack";
$legend_sections[$section] .= " GPRINT:mempooltotal$index:MIN:%3.0lf%%";
$legend_sections[$section] .= " GPRINT:mempooltotal$index:LAST:%3.0lf%%";
$legend_sections[$section] .= " GPRINT:mempooltotal$index:MAX:%3.0lf%%";
$legend_sections[$section] .= " GPRINT:mempoolused$index:LAST:%6.2lf%sB\\l ";
}
}
@ -96,13 +77,13 @@ foreach ($mempools as $index => $mempool) {
if (! empty($free_indexes)) {
$mempool_classes = $mempools->pluck('mempool_class');
if ($mempool_classes->contains('buffers') || $mempool_classes->contains('cached')) {
$rrd_options .= ' CDEF:mempoolfree=100,mempoolpercent' . implode(',mempoolpercent', $free_indexes) . str_repeat(',-', count($free_indexes));
$rrd_options .= ' CDEF:mempoolfree=100,mempooltotal' . implode(',mempooltotal', $free_indexes) . str_repeat(',-', count($free_indexes));
$rrd_options .= " CDEF:mempoolfreebytes=mempoolfree{$free_indexes[0]},mempoolused{$free_indexes[0]},+,mempoolfree,100,/,*";
$legend_sections[1] .= " COMMENT:' Free memory '";
$legend_sections[1] .= ' GPRINT:mempoolfree:MIN:%3.0lf%%';
$legend_sections[1] .= ' GPRINT:mempoolfree:LAST:%3.0lf%%';
$legend_sections[1] .= ' GPRINT:mempoolfree:MAX:%3.0lf%%';
$legend_sections[1] .= ' GPRINT:mempoolfreebytes:LAST:%6.2lf%siB\l';
$legend_sections[1] .= ' GPRINT:mempoolfreebytes:LAST:%6.2lf%sB\l';
if ($available === null) {
$rrd_options .= " CDEF:mempoolavailablebytes=mempoolfree{$free_indexes[0]}";
@ -111,12 +92,12 @@ if (! empty($free_indexes)) {
$rrd_options .= " DEF:mempoolavailablebytes=$available_filename:free:AVERAGE";
}
$rrd_options .= " CDEF:mempoolavailable=100,mempoolpercent{$free_indexes[0]},-";
$rrd_options .= " CDEF:mempoolavailable=100,mempooltotal{$free_indexes[0]},-";
$legend_sections[1] .= " COMMENT:' Available memory '";
$legend_sections[1] .= ' GPRINT:mempoolavailable:MIN:%3.0lf%%';
$legend_sections[1] .= ' GPRINT:mempoolavailable:LAST:%3.0lf%%';
$legend_sections[1] .= ' GPRINT:mempoolavailable:MAX:%3.0lf%%';
$legend_sections[1] .= ' GPRINT:mempoolavailablebytes:LAST:%6.2lf%siB\l';
$legend_sections[1] .= ' GPRINT:mempoolavailablebytes:LAST:%6.2lf%sB\l';
}
}

View File

@ -533,7 +533,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 4096,
"mempool_descr": "/dev/hd6",
"mempool_perc": 4,

View File

@ -155,7 +155,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 4096,
"mempool_descr": "Swap space",
"mempool_perc": 0,

View File

@ -961,7 +961,7 @@
"mempool_index": "21",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 4096,
"mempool_descr": "/dev/hd6",
"mempool_perc": 0,

View File

@ -86,7 +86,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 1024,
"mempool_descr": "Swap space",
"mempool_perc": 0,

View File

@ -4035,7 +4035,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 1024,
"mempool_descr": "Swap space",
"mempool_perc": 1,

View File

@ -1028,7 +1028,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 1024,
"mempool_descr": "Swap space",
"mempool_perc": 0,

View File

@ -2351,7 +2351,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 1024,
"mempool_descr": "Swap space",
"mempool_perc": 1,

View File

@ -124,7 +124,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 1024,
"mempool_descr": "Swap space",
"mempool_perc": 0,

View File

@ -7887,7 +7887,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 1024,
"mempool_descr": "Swap space",
"mempool_perc": 0,

View File

@ -1061,7 +1061,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 1024,
"mempool_descr": "Swap space",
"mempool_perc": 1,

View File

@ -2781,7 +2781,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 1024,
"mempool_descr": "Swap space",
"mempool_perc": 13,

View File

@ -814,7 +814,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 1024,
"mempool_descr": "Swap space",
"mempool_perc": 0,

View File

@ -1985,7 +1985,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 1024,
"mempool_descr": "Swap space",
"mempool_perc": 0,

View File

@ -2398,7 +2398,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 1024,
"mempool_descr": "Swap space",
"mempool_perc": 0,

View File

@ -2691,7 +2691,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 1024,
"mempool_descr": "Swap space",
"mempool_perc": 0,

View File

@ -1039,7 +1039,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 1024,
"mempool_descr": "Swap space",
"mempool_perc": 0,

View File

@ -1019,7 +1019,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 1024,
"mempool_descr": "Swap space",
"mempool_perc": 0,

View File

@ -2131,7 +2131,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 1024,
"mempool_descr": "Swap space",
"mempool_perc": 0,

View File

@ -580,7 +580,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 1024,
"mempool_descr": "Swap space",
"mempool_perc": 0,

View File

@ -13799,7 +13799,7 @@
"mempool_index": "30",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 1024,
"mempool_descr": "Slot-0 Management Swap",
"mempool_perc": 21,

View File

@ -1917,7 +1917,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 1024,
"mempool_descr": "Swap space",
"mempool_perc": 65,

View File

@ -1880,7 +1880,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 1024,
"mempool_descr": "Swap space",
"mempool_perc": 6,

View File

@ -1495,7 +1495,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 1024,
"mempool_descr": "Swap space",
"mempool_perc": 0,

View File

@ -825,7 +825,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 1024,
"mempool_descr": "Swap space",
"mempool_perc": 0,

View File

@ -1777,7 +1777,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 1024,
"mempool_descr": "Swap space",
"mempool_perc": 0,

View File

@ -1233,7 +1233,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 4096,
"mempool_descr": "Swap space (total)",
"mempool_perc": 1,

View File

@ -5533,7 +5533,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 1024,
"mempool_descr": "Swap space",
"mempool_perc": 0,

View File

@ -2351,7 +2351,7 @@
"mempool_index": "10",
"entPhysicalIndex": null,
"mempool_type": "hrstorage",
"mempool_class": "swap",
"mempool_class": "virtual",
"mempool_precision": 4096,
"mempool_descr": "Swap space",
"mempool_perc": 0,