.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require("guiconfig.inc");
if ($_GET['if']) {
$curif = $_GET['if'];
$ifnum = $config['interfaces'][$curif]['if'];
} else {
$curif = "wan";
$ifnum = get_real_wan_interface();
}
if ($_GET['graph']) {
$curgraph = $_GET['graph'];
} else {
$curgraph = "traffic";
}
$pgtitle = "Status: RRD Graphs";
include("head.inc");
?>
$interval) {
/* generate the graphs when we request the page. */
$seconds = $graphs[$interval]['seconds'];
$average = $graphs[$interval]['average'];
$scale = $graphs[$interval]['scale'];
if(($curgraph == "traffic") && (file_exists("$rrddbpath$curif$traffic"))) {
/* define graphcmd for traffic stats */
$graphcmd = "$rrdtool graph $rrddbpath$curif-$interval-$curgraph.png \\
--start -$seconds -e -$average \\
--vertical-label \"bits/sec\" \\
--title \"`hostname` - $curgraph - $interval\" \\
--height 100 --width 650 -x \"$scale\" \\
DEF:$curif-in_bytes=$rrddbpath$curif$traffic:in:AVERAGE \\
DEF:$curif-out_bytes=$rrddbpath$curif$traffic:out:AVERAGE \\
\"CDEF:$curif-in_bits=$curif-in_bytes,8,*\" \\
\"CDEF:$curif-out_bits=$curif-out_bytes,8,*\" \\
\"CDEF:$curif-out_bits_neg=$curif-out_bits,-1,*\" \\
\"CDEF:$curif-bytes_in=$curif-in_bytes,0,12500000,LIMIT,UN,0,$curif-in_bytes,IF,$average,*\" \\
\"CDEF:$curif-bytes_out=$curif-out_bytes,0,12500000,LIMIT,UN,0,$curif-out_bytes,IF,$average,*\" \\
\"CDEF:$curif-bytes=$curif-bytes_in,$curif-bytes_out,+\" \\
\"CDEF:$curif-bytes_in_t=$curif-in_bytes,0,12500000,LIMIT,UN,0,$curif-in_bytes,IF,$seconds,*\" \\
\"CDEF:$curif-bytes_out_t=$curif-out_bytes,0,12500000,LIMIT,UN,0,$curif-out_bytes,IF,$seconds,*\" \\
\"CDEF:$curif-bytes_t=$curif-bytes_in_t,$curif-bytes_out_t,+\" \\
AREA:$curif-in_bits#990000:$curif-in \\
AREA:$curif-out_bits_neg#666666:$curif-out \\
COMMENT:\"\\n\"\\
COMMENT:\"\t\t maximum average current period\\n\"\\
COMMENT:\"in\t\"\\
GPRINT:$curif-in_bits:MAX:'%7.2lf %sb/s'\\
GPRINT:$curif-in_bits:AVERAGE:'%7.2lf %Sb/s'\\
GPRINT:$curif-in_bits:LAST:'%7.2lf %Sb/s'\\
GPRINT:$curif-bytes_in_t:AVERAGE:'%7.2lf %sB i'\\
COMMENT:\"\\n\"\\
COMMENT:\"out\t\"\\
GPRINT:$curif-out_bits:MAX:'%7.2lf %sb/s'\\
GPRINT:$curif-out_bits:AVERAGE:'%7.2lf %Sb/s'\\
GPRINT:$curif-out_bits:LAST:'%7.2lf %Sb/s'\\
GPRINT:$curif-bytes_out_t:AVERAGE:'%7.2lf %sB o'\\
COMMENT:\"\\n\"\\
COMMENT:\"totals\"\\
GPRINT:$curif-bytes_in:AVERAGE:'%7.2lf %sB i'\\
GPRINT:$curif-bytes_out:AVERAGE:'%7.2lf %sB o'\\
GPRINT:$curif-bytes:AVERAGE:'%7.2lf %sB t'\\
GPRINT:$curif-bytes_t:AVERAGE:'%7.2lf %sB t'\\
COMMENT:\"\\n\"\\
COMMENT:\"\t\t\t\t\t\t\t\t\t\t\t\t\t\t`date +\"%b %d %H\:%M\:%S %Y\"`\"";
}
elseif(($curgraph == "quality") && (file_exists("$rrddbpath$curif$quality"))) {
/* make a link quality graphcmd, we only have WAN for now, others too follow */
$graphcmd = "$rrdtool graph $rrddbpath$curif-$interval-$curgraph.png \\
--start -$seconds -e -$average \\
--title=\"Link quality last $interval for $curif\" \\
--vertical-label \"ms / %\" \\
--height 100 --width 650 \\
-x \"$scale\" --lower-limit 0 \\
DEF:roundtrip=$rrddbpath$curif$quality:roundtrip:AVERAGE \\
DEF:loss=$rrddbpath$curif$quality:loss:AVERAGE \\
\"CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/\" \\
\"CDEF:loss10=loss,10,*\" \\
\"CDEF:r0=roundtrip,20,MIN\" \\
\"CDEF:r1=roundtrip,60,MIN\" \\
\"CDEF:r2=roundtrip,180,MIN\" \\
\"CDEF:r3=roundtrip,420,MIN\" \\
COMMENT:\" * Roundtrip * * Packet loss *\\n\" \\
COMMENT:\"\\n\" \\
COMMENT:\" \" \\
AREA:roundtrip#990000:\"> 420 ms\" \\
GPRINT:roundtrip:MIN:\" Min\\: %7.2lf ms\" \\
COMMENT:\" \" \\
GPRINT:loss:MIN:\"Min\\: %3.1lf %%\\n\" \\
COMMENT:\" \" \\
AREA:r3#a83c3c:\"180-420 ms\" \\
GPRINT:roundtrip:AVERAGE:\" Avg\\: %7.2lf ms\" \\
COMMENT:\" \" \\
GPRINT:loss:AVERAGE:\"Avg\\: %3.1lf %%\" \\
COMMENT:\" Packet loss multiplied\\n\" \\
COMMENT:\" \" \\
AREA:r2#b36666:\"60-180 ms\" \\
GPRINT:roundtrip:MAX:\" Max\\: %7.2lf ms\" \\
COMMENT:\" \" \\
GPRINT:loss:MAX:\"Max\\: %3.1lf %%\" \\
COMMENT:\" by 10 in graph.\\n\" \\
COMMENT:\" \" \\
AREA:r1#bd9090:\"20-60 ms\" \\
COMMENT:\"\\n\" \\
COMMENT:\" \" \\
AREA:r0#cccccc:\"< 20 ms\" \\
GPRINT:roundtrip:LAST:\" Last\\: %7.2lf ms\" \\
COMMENT:\" \" \\
GPRINT:loss:LAST:\"Last\: %3.1lf %%\" \\
COMMENT:\" \" \\
AREA:loss10#ee0000:\"Packet loss\\n\" \\
COMMENT:\" \" \\
LINE1:roundtrip#000000:\"roundtrip average\\n\" \\
COMMENT:\"\t\t\t\t\t\t\t\t\t\t\t\t\t\t`date +\"%b %d %H\:%M\:%S %Y\"`\"";
}
else
{
PRINT "
Sorry we do not have data to graph $curgraph for $curif with.";
break;
}
/* check modification time to see if we need to generate image */
if (file_exists("$rrddbpath$curif-$interval-$curgraph.png")) {
if((time() - filemtime("$rrddbpath$curif-$interval-$curgraph.png")) >= 280 ) {
system("$graphcmd >/dev/null");
usleep(500);
}
} else {
system("$graphcmd >/dev/null");
usleep(500);
}
PRINT "
Analysis for $curif -- $interval $curgraph";
PRINT "
";
}
?>