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
|
* 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
|
* an empty return means ZFS is not in use or there are currently no pools
|
||||||
|
@@ -2,13 +2,8 @@
|
|||||||
|
|
||||||
use LibreNMS\Util\Clean;
|
use LibreNMS\Util\Clean;
|
||||||
|
|
||||||
if ($_GET['from']) {
|
$from = parse_at_time($_GET['from']);
|
||||||
$from = preg_match('/(-\d+[hdm]|now)/', $_GET['from']) ? $_GET['from'] : (int)$_GET['from'];
|
$to = parse_at_time($_GET['to']);
|
||||||
}
|
|
||||||
|
|
||||||
if ($_GET['to']) {
|
|
||||||
$to = preg_match('/(-?\d+[hdm]|now)/', $_GET['to']) ? $_GET['to'] : (int)$_GET['to'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($_GET['width']) {
|
if ($_GET['width']) {
|
||||||
$width = (int)$_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:percentile_in#aa0000';
|
||||||
$rrd_options .= ' LINE1:dpercentile_out#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') {
|
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'";
|
$rrd_options .= ' LINE1.25:dout' . $format . "X#000099:'Prev Out'";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,14 +22,10 @@ $title = $vars['title'];
|
|||||||
$vertical = $vars['vertical'];
|
$vertical = $vars['vertical'];
|
||||||
$legend = $vars['legend'];
|
$legend = $vars['legend'];
|
||||||
$output = (!empty($vars['output']) ? $vars['output'] : 'default');
|
$output = (!empty($vars['output']) ? $vars['output'] : 'default');
|
||||||
$from = (isset($vars['from']) ? $vars['from'] : time() - 60 * 60 * 24);
|
$from = parse_at_time($_GET['from']) ?: Config::get('time.day');
|
||||||
$to = (isset($vars['to']) ? $vars['to'] : time());
|
$to = parse_at_time($_GET['to']) ?: Config::get('time.now');
|
||||||
$graph_type = (isset($vars['graph_type']) ? $vars['graph_type'] : Config::get('webui.graph_type'));
|
$graph_type = (isset($vars['graph_type']) ? $vars['graph_type'] : Config::get('webui.graph_type'));
|
||||||
|
|
||||||
if ($from < 0) {
|
|
||||||
$from = ($to + $from);
|
|
||||||
}
|
|
||||||
|
|
||||||
$period = ($to - $from);
|
$period = ($to - $from);
|
||||||
$base64_output = '';
|
$base64_output = '';
|
||||||
$prev_from = ($from - $period);
|
$prev_from = ($from - $period);
|
||||||
|
@@ -14,12 +14,8 @@ if (session('widescreen')) {
|
|||||||
$thumb_width=113;
|
$thumb_width=113;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_numeric($vars['from'])) {
|
$vars['from'] = parse_at_time($vars['from']) ?: Config::get('time.day');
|
||||||
$vars['from'] = strtotime($vars['from']) ?: Config::get('time.day');
|
$vars['to'] = parse_at_time($vars['to']) ?: Config::get('time.now');
|
||||||
}
|
|
||||||
if (!is_numeric($vars['to'])) {
|
|
||||||
$vars['to'] = strtotime($vars['to']) ?: Config::get('time.now');
|
|
||||||
}
|
|
||||||
|
|
||||||
preg_match('/^(?P<type>[A-Za-z0-9]+)_(?P<subtype>.+)/', $vars['type'], $graphtype);
|
preg_match('/^(?P<type>[A-Za-z0-9]+)_(?P<subtype>.+)/', $vars['type'], $graphtype);
|
||||||
|
|
||||||
|
@@ -113,4 +113,23 @@ sdfsd <a href="ftp://192.168.1.1/help/me/now.php">ftp://192.168.1.1/help/me/now.
|
|||||||
$this->assertSame('Pickle', dynamic_discovery_get_value('singletable', 11, $data, $pre_cache));
|
$this->assertSame('Pickle', dynamic_discovery_get_value('singletable', 11, $data, $pre_cache));
|
||||||
$this->assertSame('BBQ', dynamic_discovery_get_value('doubletable', 13, $data, $pre_cache));
|
$this->assertSame('BBQ', dynamic_discovery_get_value('doubletable', 13, $data, $pre_cache));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testParseAtTime()
|
||||||
|
{
|
||||||
|
$this->assertEquals(time(), parse_at_time('now'), 'now did not match');
|
||||||
|
$this->assertEquals(time()+180, parse_at_time('+3m'), '+3m did not match');
|
||||||
|
$this->assertEquals(time()+7200, parse_at_time('+2h'), '+2h did not match');
|
||||||
|
$this->assertEquals(time()+172800, parse_at_time('+2d'), '+2d did not match');
|
||||||
|
$this->assertEquals(time()+63115200, parse_at_time('+2y'), '+2y did not match');
|
||||||
|
$this->assertEquals(time()-180, parse_at_time('-3m'), '-3m did not match');
|
||||||
|
$this->assertEquals(time()-7200, parse_at_time('-2h'), '-2h did not match');
|
||||||
|
$this->assertEquals(time()-172800, parse_at_time('-2d'), '-2d did not match');
|
||||||
|
$this->assertEquals(time()-63115200, parse_at_time('-2y'), '-2y did not match');
|
||||||
|
$this->assertEquals(429929439, parse_at_time('429929439'));
|
||||||
|
$this->assertEquals(212334234, parse_at_time(212334234));
|
||||||
|
$this->assertEquals(time()-43, parse_at_time('-43'), '-43 did not match');
|
||||||
|
$this->assertEquals(0, parse_at_time('invalid'));
|
||||||
|
$this->assertEquals(606614400, parse_at_time('March 23 1989 UTC'));
|
||||||
|
$this->assertEquals(time()+86400, parse_at_time('+1 day'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user