From 7505c89586a9b3694de0bfdeec1b4c3168638216 Mon Sep 17 00:00:00 2001 From: "Zane C. Bowers-Hadley" Date: Wed, 2 Aug 2023 08:36:25 -0500 Subject: [PATCH] add generic stats graph munging support and make uptime display as days again (#15097) * add munging to generic stats graph include * add graph_uptime_days config def * make it optionally changable now * style fix * remove the graph_uptime_days option --- includes/html/graphs/device/uptime.inc.php | 6 +++- includes/html/graphs/generic_stats.inc.php | 35 ++++++++++++++++++---- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/includes/html/graphs/device/uptime.inc.php b/includes/html/graphs/device/uptime.inc.php index 822baebb99..ed79368894 100644 --- a/includes/html/graphs/device/uptime.inc.php +++ b/includes/html/graphs/device/uptime.inc.php @@ -9,6 +9,10 @@ $ds = 'uptime'; $colours = 'greens'; $float_precision = 3; -$descr = ''; +$descr = 'Uptime'; + +$munge = true; + +$unit_text = 'Days'; require 'includes/html/graphs/generic_stats.inc.php'; diff --git a/includes/html/graphs/generic_stats.inc.php b/includes/html/graphs/generic_stats.inc.php index c879891e9b..d0738c5082 100644 --- a/includes/html/graphs/generic_stats.inc.php +++ b/includes/html/graphs/generic_stats.inc.php @@ -17,6 +17,10 @@ require 'includes/html/graphs/common.inc.php'; $stacked = generate_stacked_graphs(); +if (! isset($munge)) { + $munge = false; +} + if (! isset($colours)) { $colours = 'rainbow_stats_purple'; } @@ -108,15 +112,30 @@ if ($height > 25) { $descr_1w = \LibreNMS\Data\Store\Rrd::fixedSafeDescr('1 week avg', $descr_len); } -$id = 'ds' . $i; +$id = 'ds0'; +if ($munge) { + $id = 'dsm0'; +} -$rrd_options .= ' DEF:' . $id . "=$filename:$ds:AVERAGE"; +$rrd_options .= ' DEF:ds0' . "=$filename:$ds:AVERAGE"; + +$munge_helper = ''; +if ($munge) { + if (! isset($munge_opts)) { + $munge_opts = '86400,/'; + } + $rrd_options .= ' CDEF:dsm0=ds0,' . $munge_opts; + $munge_helper = 'ds'; +} $rrd_optionsb .= ' AREA:' . $id . '#' . $colourA . $colourAalpha; $rrd_optionsb .= ' LINE1.25:' . $id . '#' . $colour . ":'$descr'"; if ($height > 25) { - $rrd_options .= ' DEF:' . $id . "1h=$filename:$ds:AVERAGE:step=3600"; + $rrd_options .= ' DEF:' . $id . "1h$munge_helper=$filename:$ds:AVERAGE:step=3600"; + if ($munge) { + $rrd_options .= ' CDEF:dsm01h=dsm01hds,' . $munge_opts; + } $rrd_options .= ' VDEF:' . $id . '50th=' . $id . ',50,PERCENTNAN'; $rrd_options .= ' VDEF:' . $id . '25th=' . $id . ',25,PERCENTNAN'; $rrd_options .= ' VDEF:' . $id . '75th=' . $id . ',75,PERCENTNAN'; @@ -130,12 +149,18 @@ if ($height > 25) { } // displays nan if less than 17 hours if ($time_diff >= 61200) { - $rrd_options .= ' DEF:' . $id . "1d=$filename:$ds:AVERAGE:step=86400"; + $rrd_options .= ' DEF:' . $id . "1d$munge_helper=$filename:$ds:AVERAGE:step=86400"; + if ($munge) { + $rrd_options .= ' CDEF:dsm01d=dsm01dds,' . $munge_opts; + } } // weekly breaks and causes issues if it is less than 8 days if ($time_diff >= 691200) { - $rrd_options .= ' DEF:' . $id . "1w=$filename:$ds:AVERAGE:step=604800"; + $rrd_options .= ' DEF:' . $id . "1w$munge_helper=$filename:$ds:AVERAGE:step=604800"; + if ($munge) { + $rrd_options .= ' CDEF:dsm01w=dsm01wds,' . $munge_opts; + } } $rrd_optionsb .= ' GPRINT:' . $id . ':LAST:%5.' . $float_precision . 'lf%s' . $units . ' GPRINT:' . $id . ':MIN:%5.' . $float_precision . 'lf%s' . $units;