mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Simple linear port graph prediction (#10520)
* Simple linear port graph prediction Simple linear prediction line for in and out if graph "to" value is in the future Improve graph date handling * thinner line * Make test specify timezone
This commit is contained in:
@@ -1526,6 +1526,34 @@ function generate_stacked_graphs($transparency = '88')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse AT time spec, does not handle the entire spec.
|
||||
* @param string $time
|
||||
* @return int
|
||||
*/
|
||||
function parse_at_time($time)
|
||||
{
|
||||
if (is_numeric($time)) {
|
||||
return $time < 0 ? time() + $time : intval($time);
|
||||
}
|
||||
|
||||
if (preg_match('/^[+-]\d+[hdmy]$/', $time)) {
|
||||
$units = [
|
||||
'm' => 60,
|
||||
'h' => 3600,
|
||||
'd' => 86400,
|
||||
'y' => 31557600,
|
||||
];
|
||||
$value = substr($time, 1, -1);
|
||||
$unit = substr($time, -1);
|
||||
|
||||
$offset = ($time[0] == '-' ? -1 : 1) * $units[$unit] * $value;
|
||||
return time() + $offset;
|
||||
}
|
||||
|
||||
return (int)strtotime($time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ZFS pools for a device... just requires the device ID
|
||||
* an empty return means ZFS is not in use or there are currently no pools
|
||||
|
@@ -2,13 +2,8 @@
|
||||
|
||||
use LibreNMS\Util\Clean;
|
||||
|
||||
if ($_GET['from']) {
|
||||
$from = preg_match('/(-\d+[hdm]|now)/', $_GET['from']) ? $_GET['from'] : (int)$_GET['from'];
|
||||
}
|
||||
|
||||
if ($_GET['to']) {
|
||||
$to = preg_match('/(-?\d+[hdm]|now)/', $_GET['to']) ? $_GET['to'] : (int)$_GET['to'];
|
||||
}
|
||||
$from = parse_at_time($_GET['from']);
|
||||
$to = parse_at_time($_GET['to']);
|
||||
|
||||
if ($_GET['width']) {
|
||||
$width = (int)$_GET['width'];
|
||||
|
@@ -137,8 +137,21 @@ $rrd_options .= " GPRINT:totout:'Out %6.2lf%sB)\\l'";
|
||||
$rrd_options .= ' LINE1:percentile_in#aa0000';
|
||||
$rrd_options .= ' LINE1:dpercentile_out#aa0000';
|
||||
|
||||
// Linear prediction of trend
|
||||
if ($to > time()) {
|
||||
$rrd_options .= ' VDEF:islope=inbits_max,LSLSLOPE';
|
||||
$rrd_options .= ' VDEF:icons=inbits_max,LSLINT';
|
||||
$rrd_options .= ' CDEF:ilsl=inbits_max,POP,islope,COUNT,*,icons,+ ';
|
||||
$rrd_options .= " LINE2:ilsl#44aa55:'In Linear Prediction\\n':dashes=8";
|
||||
|
||||
$rrd_options .= ' VDEF:oslope=doutbits_max,LSLSLOPE';
|
||||
$rrd_options .= ' VDEF:ocons=doutbits_max,LSLINT';
|
||||
$rrd_options .= ' CDEF:olsl=doutbits_max,POP,oslope,COUNT,*,ocons,+ ';
|
||||
$rrd_options .= " LINE2:olsl#4400dd:'Out Linear Prediction\\n':dashes=8";
|
||||
}
|
||||
|
||||
if ($_GET['previous'] == 'yes') {
|
||||
$rrd_options .= ' LINE1.25:in' . $format . "X#009900:'Prev In \\\\n'";
|
||||
$rrd_options .= ' LINE1.25:in' . $format . "X#009900:'Prev In \\n'";
|
||||
$rrd_options .= ' LINE1.25:dout' . $format . "X#000099:'Prev Out'";
|
||||
}
|
||||
|
||||
|
@@ -22,14 +22,10 @@ $title = $vars['title'];
|
||||
$vertical = $vars['vertical'];
|
||||
$legend = $vars['legend'];
|
||||
$output = (!empty($vars['output']) ? $vars['output'] : 'default');
|
||||
$from = (isset($vars['from']) ? $vars['from'] : time() - 60 * 60 * 24);
|
||||
$to = (isset($vars['to']) ? $vars['to'] : time());
|
||||
$from = parse_at_time($_GET['from']) ?: Config::get('time.day');
|
||||
$to = parse_at_time($_GET['to']) ?: Config::get('time.now');
|
||||
$graph_type = (isset($vars['graph_type']) ? $vars['graph_type'] : Config::get('webui.graph_type'));
|
||||
|
||||
if ($from < 0) {
|
||||
$from = ($to + $from);
|
||||
}
|
||||
|
||||
$period = ($to - $from);
|
||||
$base64_output = '';
|
||||
$prev_from = ($from - $period);
|
||||
|
@@ -14,12 +14,8 @@ if (session('widescreen')) {
|
||||
$thumb_width=113;
|
||||
}
|
||||
|
||||
if (!is_numeric($vars['from'])) {
|
||||
$vars['from'] = strtotime($vars['from']) ?: Config::get('time.day');
|
||||
}
|
||||
if (!is_numeric($vars['to'])) {
|
||||
$vars['to'] = strtotime($vars['to']) ?: Config::get('time.now');
|
||||
}
|
||||
$vars['from'] = parse_at_time($vars['from']) ?: Config::get('time.day');
|
||||
$vars['to'] = parse_at_time($vars['to']) ?: Config::get('time.now');
|
||||
|
||||
preg_match('/^(?P<type>[A-Za-z0-9]+)_(?P<subtype>.+)/', $vars['type'], $graphtype);
|
||||
|
||||
|
Reference in New Issue
Block a user