Files
librenms-librenms/html/includes/graphs/generic_multi_line.inc.php
T

102 lines
3.4 KiB
PHP
Raw Normal View History

2009-10-27 13:04:16 +00:00
<?php
2016-07-22 14:29:29 -05:00
/*
* Outputs a graph with multiple overlaid lines
*
* Variables:
* $rrd_list array required - array of data sets to graph. Each item is an array that contains the following
* ds string required - data set name as defined in rrd
* filename string required - path to the rrd file as generated by rrd_name()
* descr string required - the label for this data set
* colour string optional - Defines the colour for this data set (overrides the overall colour set)
* area boolean optional - Colors in the area of the data set with 20% opacity (unless areacolor is set)
* areacolor string optional - Sets the area color manually
* invert boolean optional - multiplies values in this data set by -1
* $colours string required - colour set as defined in $config['graph_colours']
* $print_total boolean optional - Sum all the values and output the last, min, max, and avg in the legend
* $simplerrd boolean optional - All data sets reside in the same rrd file
*/
require 'includes/graphs/common.inc.php';
if ($width > '500') {
$descr_len = 24;
2016-08-18 20:28:22 -05:00
} else {
$descr_len = 12;
$descr_len += round(($width - 250) / 8);
2011-09-30 19:15:58 +00:00
}
2009-10-27 13:04:16 +00:00
if ($nototal) {
$descr_len += '2';
$unitlen += '2';
}
2011-09-30 19:15:58 +00:00
if ($width > '500') {
$rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))."Now Min Max Avg\l'";
if (!$nototal) {
$rrd_options .= " COMMENT:'Total '";
}
2011-09-30 19:15:58 +00:00
$rrd_options .= " COMMENT:'\l'";
2016-08-18 20:28:22 -05:00
} else {
$rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))."Now Min Max Avg\l'";
2011-09-30 19:15:58 +00:00
}
2009-10-27 13:04:16 +00:00
$i = 0;
2011-09-30 19:15:58 +00:00
$iter = 0;
2009-10-27 13:04:16 +00:00
foreach ($rrd_list as $rrd) {
2016-07-22 14:29:29 -05:00
// get the color for this data set
2016-08-18 20:28:22 -05:00
if (isset($rrd['colour'])) {
2016-07-22 14:29:29 -05:00
$colour = $rrd['colour'];
} else {
if (!$config['graph_colours'][$colours][$iter]) {
$iter = 0;
}
$colour = $config['graph_colours'][$colours][$iter];
$iter++;
}
2009-10-27 13:04:16 +00:00
2015-07-01 08:08:06 +10:00
if (!empty($rrd['area']) && empty($rrd['areacolour'])) {
$rrd['areacolour'] = $colour."20";
}
2009-10-27 13:04:16 +00:00
$ds = $rrd['ds'];
$filename = $rrd['filename'];
2011-09-30 19:15:58 +00:00
$descr = rrdtool_escape($rrd['descr'], $descr_len);
2009-10-27 13:04:16 +00:00
$id = 'ds'.$i;
$rrd_options .= ' DEF:'.$id."=$filename:$ds:AVERAGE";
2009-10-27 13:04:16 +00:00
if ($simple_rrd) {
$rrd_options .= ' CDEF:'.$id.'min='.$id.' ';
$rrd_options .= ' CDEF:'.$id.'max='.$id.' ';
2016-08-18 20:28:22 -05:00
} else {
$rrd_options .= ' DEF:'.$id."min=$filename:$ds:MIN";
$rrd_options .= ' DEF:'.$id."max=$filename:$ds:MAX";
}
2011-09-18 22:55:29 +00:00
if ($rrd['invert']) {
$rrd_options .= ' CDEF:'.$id.'i='.$id.',-1,*';
$rrd_optionsb .= ' LINE1.25:'.$id.'i#'.$colour.":'$descr'";
if (!empty($rrd['areacolour'])) {
$rrd_optionsb .= ' AREA:'.$id.'i#'.$rrd['areacolour'];
}
2016-08-18 20:28:22 -05:00
} else {
$rrd_optionsb .= ' LINE1.25:'.$id.'#'.$colour.":'$descr'";
if (!empty($rrd['areacolour'])) {
$rrd_optionsb .= ' AREA:'.$id.'#'.$rrd['areacolour'];
}
}
2009-10-27 13:04:16 +00:00
2015-07-01 08:08:06 +10:00
$rrd_optionsb .= ' GPRINT:'.$id.':LAST:%5.2lf%s'.$units.' GPRINT:'.$id.'min:MIN:%5.2lf%s'.$units;
$rrd_optionsb .= ' GPRINT:'.$id.'max:MAX:%5.2lf%s'.$units.' GPRINT:'.$id.":AVERAGE:'%5.2lf%s$units\\n'";
2011-09-30 13:09:14 +00:00
$i++;
}//end foreach
2011-03-17 10:57:51 +00:00
2011-09-19 08:54:48 +00:00
$rrd_options .= $rrd_optionsb;
$rrd_options .= ' HRULE:0#555555';