2009-10-27 13:04:16 +00:00
|
|
|
<?php
|
2017-12-02 22:28:03 +02:00
|
|
|
/*
|
|
|
|
* 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. Please see LICENSE.txt at the top level of
|
|
|
|
* the source code distribution for details.
|
|
|
|
*
|
|
|
|
* @package LibreNMS
|
|
|
|
* @subpackage graphs
|
2021-02-09 00:29:04 +01:00
|
|
|
* @link https://www.librenms.org
|
2017-12-02 22:28:03 +02:00
|
|
|
* @copyright 2017 LibreNMS
|
|
|
|
* @author LibreNMS Contributors
|
|
|
|
*/
|
2009-10-27 13:04:16 +00:00
|
|
|
|
2019-04-11 23:26:42 -05:00
|
|
|
require 'includes/html/graphs/common.inc.php';
|
2011-03-17 10:57:51 +00:00
|
|
|
|
2017-12-02 22:28:03 +02:00
|
|
|
$stacked = generate_stacked_graphs();
|
|
|
|
|
2011-03-17 10:57:51 +00:00
|
|
|
$i = 0;
|
2020-07-10 04:45:01 -04:00
|
|
|
if ($width > '1500') {
|
|
|
|
$descr_len = 40;
|
|
|
|
} elseif ($width >= '500') {
|
|
|
|
$descr_len = 8;
|
|
|
|
$descr_len += min(40, round(($width - 320) / 15));
|
2016-08-18 20:28:22 -05:00
|
|
|
} else {
|
2017-12-02 22:28:03 +02:00
|
|
|
$descr_len = 8;
|
2020-07-10 04:45:01 -04:00
|
|
|
$descr_len += min(20, round(($width - 260) / 9.5));
|
2011-09-21 11:59:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$unit_text = 'Bits/sec';
|
|
|
|
|
2015-05-10 18:44:49 +02:00
|
|
|
if (! $noagg || ! $nodetails) {
|
|
|
|
if ($width > '500') {
|
2023-03-13 22:32:22 +01:00
|
|
|
$rrd_options .= sprintf(" COMMENT:'%s'", substr(str_pad($unit_text, $descr_len + 5), 0, $descr_len + 5));
|
2020-07-10 04:45:01 -04:00
|
|
|
$rrd_options .= sprintf(" COMMENT:'%12s'", 'Current');
|
|
|
|
$rrd_options .= sprintf(" COMMENT:'%10s'", 'Average');
|
|
|
|
$rrd_options .= sprintf(" COMMENT:'%10s'", 'Maximum');
|
2015-05-10 18:44:49 +02:00
|
|
|
if (! $nototal) {
|
2020-07-10 04:45:01 -04:00
|
|
|
$rrd_options .= sprintf(" COMMENT:'%8s'", 'Total');
|
2011-09-21 11:59:59 +00:00
|
|
|
}
|
2021-05-13 13:13:10 -05:00
|
|
|
$rrd_options .= " COMMENT:'\l'";
|
2016-08-18 20:28:22 -05:00
|
|
|
} else {
|
2017-12-02 22:28:03 +02:00
|
|
|
$nototal = true;
|
2023-03-13 22:32:22 +01:00
|
|
|
$rrd_options .= sprintf(" COMMENT:'%s'", substr(str_pad($unit_text, $descr_len + 5), 0, $descr_len + 5));
|
2020-07-10 04:45:01 -04:00
|
|
|
$rrd_options .= sprintf(" COMMENT:'%12s'", 'Now');
|
|
|
|
$rrd_options .= sprintf(" COMMENT:'%10s'", 'Avg');
|
2021-05-13 13:13:10 -05:00
|
|
|
$rrd_options .= sprintf(" COMMENT:'%10s\l'", 'Max');
|
2015-07-13 20:10:26 +02:00
|
|
|
}
|
|
|
|
}
|
2011-03-17 10:57:51 +00:00
|
|
|
|
|
|
|
if (! isset($multiplier)) {
|
|
|
|
$multiplier = '8';
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($rrd_list as $rrd) {
|
2019-06-23 00:29:12 -05:00
|
|
|
if (! \LibreNMS\Config::get("graph_colours.$colours_in.$iter") || ! \LibreNMS\Config::get("graph_colours.$colours_out.$iter")) {
|
2011-03-17 10:57:51 +00:00
|
|
|
$iter = 0;
|
2015-07-13 20:10:26 +02:00
|
|
|
}
|
2011-03-17 10:57:51 +00:00
|
|
|
|
2019-06-23 00:29:12 -05:00
|
|
|
$colour_in = \LibreNMS\Config::get("graph_colours.$colours_in.$iter");
|
|
|
|
$colour_out = \LibreNMS\Config::get("graph_colours.$colours_out.$iter");
|
2015-07-13 20:10:26 +02:00
|
|
|
|
2015-05-10 17:52:46 +02:00
|
|
|
if (! $nodetails) {
|
|
|
|
if (isset($rrd['descr_in'])) {
|
2021-03-28 17:25:30 -05:00
|
|
|
$descr = \LibreNMS\Data\Store\Rrd::fixedSafeDescr($rrd['descr_in'], $descr_len) . ' In';
|
2016-08-18 20:28:22 -05:00
|
|
|
} else {
|
2021-03-28 17:25:30 -05:00
|
|
|
$descr = \LibreNMS\Data\Store\Rrd::fixedSafeDescr($rrd['descr'], $descr_len) . ' In';
|
2015-07-13 20:10:26 +02:00
|
|
|
}
|
2021-03-28 17:25:30 -05:00
|
|
|
$descr_out = \LibreNMS\Data\Store\Rrd::fixedSafeDescr($rrd['descr_out'], $descr_len) . ' Out';
|
2015-05-10 17:52:46 +02:00
|
|
|
}
|
2015-07-13 20:10:26 +02:00
|
|
|
|
2017-12-02 22:28:03 +02:00
|
|
|
$rrd_options .= ' DEF:' . $in . $i . '=' . $rrd['filename'] . ':' . $ds_in . ':AVERAGE ';
|
|
|
|
$rrd_options .= ' DEF:' . $out . $i . '=' . $rrd['filename'] . ':' . $ds_out . ':AVERAGE ';
|
|
|
|
$rrd_options .= ' CDEF:inB' . $i . '=in' . $i . ",$multiplier,* ";
|
|
|
|
$rrd_options .= ' CDEF:outB' . $i . '=out' . $i . ",$multiplier,*";
|
|
|
|
$rrd_options .= ' CDEF:outB' . $i . '_neg=outB' . $i . ',' . $stacked['stacked'] . ',*';
|
|
|
|
$rrd_options .= ' CDEF:octets' . $i . '=inB' . $i . ',outB' . $i . ',+';
|
2015-07-13 20:10:26 +02:00
|
|
|
|
2015-05-10 17:52:46 +02:00
|
|
|
if (! $nototal) {
|
2017-12-02 22:28:03 +02:00
|
|
|
$rrd_options .= ' VDEF:totin' . $i . '=inB' . $i . ',TOTAL';
|
|
|
|
$rrd_options .= ' VDEF:totout' . $i . '=outB' . $i . ',TOTAL';
|
|
|
|
$rrd_options .= ' VDEF:tot' . $i . '=octets' . $i . ',TOTAL';
|
2015-07-13 20:10:26 +02:00
|
|
|
}
|
|
|
|
|
2011-03-17 10:57:51 +00:00
|
|
|
if ($i) {
|
2015-11-15 11:48:39 +10:00
|
|
|
$stack = ':STACK';
|
2015-07-13 20:10:26 +02:00
|
|
|
}
|
|
|
|
|
2017-12-02 22:28:03 +02:00
|
|
|
$rrd_options .= ' AREA:inB' . $i . '#' . $colour_in . $stacked['transparency'] . ":'" . $descr . "'$stack";
|
2015-05-10 17:52:46 +02:00
|
|
|
if (! $nodetails) {
|
2020-06-25 21:51:55 +02:00
|
|
|
$rrd_options .= ' GPRINT:inB' . $i . ':LAST:%6.' . $float_precision . "lf%s$units";
|
|
|
|
$rrd_options .= ' GPRINT:inB' . $i . ':AVERAGE:%6.' . $float_precision . "lf%s$units";
|
|
|
|
$rrd_options .= ' GPRINT:inB' . $i . ':MAX:%6.' . $float_precision . "lf%s$units";
|
2015-05-10 17:52:46 +02:00
|
|
|
if (! $nototal) {
|
2020-06-25 21:51:55 +02:00
|
|
|
$rrd_options .= ' GPRINT:totin' . $i . ':%6.' . $float_precision . "lf%s$total_units";
|
2015-07-13 20:10:26 +02:00
|
|
|
}
|
|
|
|
|
2021-05-13 13:13:10 -05:00
|
|
|
$rrd_options .= '\l';
|
2015-07-13 20:10:26 +02:00
|
|
|
}
|
|
|
|
|
2017-12-02 22:28:03 +02:00
|
|
|
$rrd_options .= " 'HRULE:0#" . $colour_out . ':' . $descr_out . "'";
|
|
|
|
$rrd_optionsb .= " 'AREA:outB" . $i . '_neg#' . $colour_out . $stacked['transparency'] . ":$stack'";
|
2015-07-13 20:10:26 +02:00
|
|
|
|
2015-05-10 17:52:46 +02:00
|
|
|
if (! $nodetails) {
|
2020-06-25 21:51:55 +02:00
|
|
|
$rrd_options .= ' GPRINT:outB' . $i . ':LAST:%6.' . $float_precision . "lf%s$units";
|
|
|
|
$rrd_options .= ' GPRINT:outB' . $i . ':AVERAGE:%6.' . $float_precision . "lf%s$units";
|
|
|
|
$rrd_options .= ' GPRINT:outB' . $i . ':MAX:%6.' . $float_precision . "lf%s$units";
|
2015-05-10 17:52:46 +02:00
|
|
|
if (! $nototal) {
|
2020-07-10 04:45:01 -04:00
|
|
|
$rrd_options .= ' GPRINT:totout' . $i . ':%6.' . $float_precision . "lf%s$total_units";
|
2015-07-13 20:10:26 +02:00
|
|
|
}
|
|
|
|
|
2021-05-13 13:13:10 -05:00
|
|
|
$rrd_options .= '\l';
|
2015-07-13 20:10:26 +02:00
|
|
|
}
|
|
|
|
|
2021-05-13 13:13:10 -05:00
|
|
|
$rrd_options .= " 'COMMENT:\l'";
|
2015-07-13 20:10:26 +02:00
|
|
|
|
2015-05-10 17:52:46 +02:00
|
|
|
if ($i >= 1) {
|
2017-12-02 22:28:03 +02:00
|
|
|
$aggr_in .= ',';
|
2015-05-10 17:52:46 +02:00
|
|
|
$aggr_out .= ',';
|
|
|
|
}
|
2015-07-13 20:10:26 +02:00
|
|
|
|
2015-05-10 17:52:46 +02:00
|
|
|
if ($i > 1) {
|
2017-12-02 22:28:03 +02:00
|
|
|
$aggr_in .= 'ADDNAN,';
|
2011-09-21 13:22:27 +00:00
|
|
|
$aggr_out .= 'ADDNAN,';
|
2015-05-10 17:52:46 +02:00
|
|
|
}
|
2015-07-13 20:10:26 +02:00
|
|
|
|
2017-12-02 22:28:03 +02:00
|
|
|
$aggr_in .= $in . $i;
|
|
|
|
$aggr_out .= $out . $i;
|
2015-07-13 20:10:26 +02:00
|
|
|
|
2011-03-17 10:57:51 +00:00
|
|
|
$i++;
|
|
|
|
$iter++;
|
|
|
|
}
|
|
|
|
|
2015-05-10 18:36:15 +02:00
|
|
|
if (! $noagg) {
|
2017-12-02 22:28:03 +02:00
|
|
|
$rrd_options .= ' CDEF:aggr' . $in . 'bytes=' . $aggr_in . ',ADDNAN';
|
|
|
|
$rrd_options .= ' CDEF:aggr' . $out . 'bytes=' . $aggr_out . ',ADDNAN';
|
|
|
|
$rrd_options .= ' CDEF:aggrinbits=aggrinbytes,' . $multiplier . ',*';
|
|
|
|
$rrd_options .= ' CDEF:aggroutbits=aggroutbytes,' . $multiplier . ',*';
|
2015-05-10 18:36:15 +02:00
|
|
|
$rrd_options .= ' VDEF:totalin=aggrinbytes,TOTAL';
|
|
|
|
$rrd_options .= ' VDEF:totalout=aggroutbytes,TOTAL';
|
2020-07-10 04:45:01 -04:00
|
|
|
$rrd_options .= " COMMENT:' \\n'";
|
2023-03-13 22:32:22 +01:00
|
|
|
$rrd_options .= " COMMENT:'" . substr(str_pad('Aggregate', $descr_len + 5), 0, $descr_len + 5) . 'In' . "'";
|
2020-06-25 21:51:55 +02:00
|
|
|
$rrd_options .= ' GPRINT:aggrinbits:LAST:%6.' . $float_precision . "lf%s$units";
|
|
|
|
$rrd_options .= ' GPRINT:aggrinbits:AVERAGE:%6.' . $float_precision . "lf%s$units";
|
|
|
|
$rrd_options .= ' GPRINT:aggrinbits:MAX:%6.' . $float_precision . "lf%s$units";
|
2015-05-10 18:36:15 +02:00
|
|
|
if (! $nototal) {
|
2020-06-25 21:51:55 +02:00
|
|
|
$rrd_options .= ' GPRINT:totalin:%6.' . $float_precision . "lf%s$total_units";
|
2015-05-10 18:36:15 +02:00
|
|
|
}
|
2015-07-13 20:10:26 +02:00
|
|
|
|
2021-05-13 13:13:10 -05:00
|
|
|
$rrd_options .= '\\n';
|
2023-03-13 22:32:22 +01:00
|
|
|
$rrd_options .= " COMMENT:'" . substr(str_pad('Aggregate', $descr_len + 4), 0, $descr_len + 4) . 'Out' . "'";
|
2020-06-25 21:51:55 +02:00
|
|
|
$rrd_options .= ' GPRINT:aggroutbits:LAST:%6.' . $float_precision . "lf%s$units";
|
|
|
|
$rrd_options .= ' GPRINT:aggroutbits:AVERAGE:%6.' . $float_precision . "lf%s$units";
|
|
|
|
$rrd_options .= ' GPRINT:aggroutbits:MAX:%6.' . $float_precision . "lf%s$units";
|
2015-05-10 18:36:15 +02:00
|
|
|
if (! $nototal) {
|
2020-06-25 21:51:55 +02:00
|
|
|
$rrd_options .= ' GPRINT:totalout:%6.' . $float_precision . "lf%s$total_units";
|
2015-05-10 18:36:15 +02:00
|
|
|
}
|
2015-07-13 20:10:26 +02:00
|
|
|
|
2021-05-13 13:13:10 -05:00
|
|
|
$rrd_options .= '\\n';
|
2015-05-10 17:52:46 +02:00
|
|
|
}
|
|
|
|
|
2011-03-23 10:25:42 +00:00
|
|
|
if ($custom_graph) {
|
|
|
|
$rrd_options .= $custom_graph;
|
|
|
|
}
|
|
|
|
|
2011-03-17 10:57:51 +00:00
|
|
|
$rrd_options .= $rrd_optionsb;
|
|
|
|
$rrd_options .= ' HRULE:0#999999';
|
2017-12-02 22:28:03 +02:00
|
|
|
|
|
|
|
unset($stacked);
|