Change mempools summary graph to show values v2 (#12355)

* Change mempools summary graph to show values
put swap on the negative axis
fix swap classification

* fix whitespace

* fix incorrect class
fix rrd rename logic

* Style

* missed one

* observe with the correct class
This commit is contained in:
Tony Murray
2020-11-25 10:31:24 -06:00
committed by GitHub
parent 23e8544913
commit 5d3e06ee69
37 changed files with 136 additions and 62 deletions

View File

@@ -4,8 +4,7 @@ use App\Models\Mempool;
require 'includes/html/graphs/common.inc.php';
$rrd_options .= ' -u 100 -l 0 -E -b 1024 ';
$rrd_options .= " COMMENT:' Min Cur Max Used\\n'";
$rrd_options .= ' -E -b 1024 ';
// order mempools properly
$mempool_classes = [
@@ -29,18 +28,25 @@ $mempools = DeviceCache::get($device['device_id'])->mempools->sort(function (Mem
// find available
$available = null;
$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);
$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
}
$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) {
@@ -52,24 +58,37 @@ 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,mempoolused$index,mempoolfree$index,+,/,100,* ";
$rrd_options .= " CDEF:mempooltotal$index=mempoolused$index,mempoolfree$index,+ ";
$rrd_options .= " CDEF:mempoolpercent$index=mempoolused$index,mempooltotal$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:mempooltotal$index#{$color}70:$stack";
$rrd_options .= " AREA:mempoolused$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] .= " 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 ";
$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 ";
}
}
@@ -77,13 +96,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,mempooltotal' . implode(',mempooltotal', $free_indexes) . str_repeat(',-', count($free_indexes));
$rrd_options .= ' CDEF:mempoolfree=100,mempoolpercent' . implode(',mempoolpercent', $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%sB\l';
$legend_sections[1] .= ' GPRINT:mempoolfreebytes:LAST:%6.2lf%siB\l';
if ($available === null) {
$rrd_options .= " CDEF:mempoolavailablebytes=mempoolfree{$free_indexes[0]}";
@@ -92,12 +111,12 @@ if (! empty($free_indexes)) {
$rrd_options .= " DEF:mempoolavailablebytes=$available_filename:free:AVERAGE";
}
$rrd_options .= " CDEF:mempoolavailable=100,mempooltotal{$free_indexes[0]},-";
$rrd_options .= " CDEF:mempoolavailable=100,mempoolpercent{$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%sB\l';
$legend_sections[1] .= ' GPRINT:mempoolavailablebytes:LAST:%6.2lf%siB\l';
}
}