summaryrefslogtreecommitdiffstats
path: root/usr/local/www/status_rrd_graph_img.php
diff options
context:
space:
mode:
authorScott Ullrich <sullrich@pfsense.org>2006-04-24 18:36:54 +0000
committerScott Ullrich <sullrich@pfsense.org>2006-04-24 18:36:54 +0000
commitcbe30115c582ccb392148288a936100093ca772e (patch)
tree8b11249f25f702cbfddc0865711041b46aa031d4 /usr/local/www/status_rrd_graph_img.php
parent98b5b72baf60b50e0817c7523692e610196f8c1f (diff)
downloadpfsense-cbe30115c582ccb392148288a936100093ca772e.zip
pfsense-cbe30115c582ccb392148288a936100093ca772e.tar.gz
MFC from -HEAD
Diffstat (limited to 'usr/local/www/status_rrd_graph_img.php')
-rw-r--r--usr/local/www/status_rrd_graph_img.php368
1 files changed, 368 insertions, 0 deletions
diff --git a/usr/local/www/status_rrd_graph_img.php b/usr/local/www/status_rrd_graph_img.php
new file mode 100644
index 0000000..55477c0
--- /dev/null
+++ b/usr/local/www/status_rrd_graph_img.php
@@ -0,0 +1,368 @@
+<?php
+/* $Id$ */
+/*
+ status_rrd_graph_img.php
+ Part of pfSense
+ Copyright (C) 2004 Scott Ullrich
+ All rights reserved.
+
+ Originally part of m0n0wall (http://m0n0.ch/wall)
+ Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
+ 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";
+}
+
+if ($_GET['graph']) {
+ $curgraph = $_GET['graph'];
+} else {
+ $curgraph = "traffic";
+}
+
+if ($_GET['interval']) {
+ $interval = $_GET['interval'];
+} else {
+ $interval = "2h";
+}
+
+$ifdescrs = array('wan' => 'WAN', 'lan' => 'LAN');
+$graphs = array('traffic' => 'Traffic', 'quality' => 'Quality', 'queues' => 'Queues', 'packets' => 'Packets', 'spamd' => 'Spamd');
+
+for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) {
+ $ifdescrs['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
+}
+
+$periods = array("2h", "6h", "48h", "14d", "2m", "18m");
+/*
+if(! array_key_exists($interval, $periods)) {
+ PRINT "Graph interval $interval is not valid <br>\n";
+ die();
+}
+*/
+
+$graphs['2h']['seconds'] = 7200;
+$graphs['2h']['average'] = 60;
+$graphs['2h']['scale'] = "MINUTE:5:MINUTE:10:MINUTE:30:0:%H%:%M";
+$graphs['6h']['seconds'] = 21600;
+$graphs['6h']['average'] = 300;
+$graphs['6h']['scale'] = "MINUTE:10:MINUTE:30:MINUTE:30:0:%H%:%M";
+$graphs['48h']['seconds'] = 108000;
+$graphs['48h']['average'] = 300;
+$graphs['48h']['scale'] = "HOUR:1:HOUR:6:HOUR:2:0:%H";
+$graphs['14d']['seconds'] = 1209600;
+$graphs['14d']['average'] = 600;
+$graphs['14d']['scale'] = "HOUR:6:DAY:1:DAY:1:0:%a";
+$graphs['2m']['seconds'] = 5184000;
+$graphs['2m']['average'] = 3600;
+$graphs['2m']['scale'] = "DAY:1:WEEK:1:WEEK:1:0:Week %W";
+$graphs['18m']['seconds'] = 46656000;
+$graphs['18m']['average'] = 86400;
+$graphs['18m']['scale'] = "MONTH:1:MONTH:1:MONTH:1:0:%b";
+
+$rrddbpath = "/var/db/rrd/";
+$traffic = "-traffic.rrd";
+$quality = "-quality.rrd";
+$queues = "-queues.rrd";
+$packets = "-packets.rrd";
+$spamd = "spamd.rrd";
+$rrdtool = "/usr/local/bin/rrdtool";
+$uptime = "/usr/bin/uptime";
+$sed = "/usr/bin/sed";
+
+/* FIXME: We need real shaper speeds here, yes i have a 22/2Mbps
+internet connection */
+/* compare bytes/sec counters, divide bps by 8 */
+$downstream = (22000000/8);
+$upstream = (2000000/8);
+
+/* FIXME: determine down and up interface, note: case insensitive */
+$upif = "wan";
+$downif = "lan";
+
+/* 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-bits_io=$curif-in_bits,$curif-out_bits,+\" \\
+ \"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-bits_io:MAX:'%7.2lf %sb/s'\\
+ GPRINT:$curif-bits_io:AVERAGE:'%7.2lf %sb/s'\\
+ GPRINT:$curif-bits_io:LAST:'%7.2lf %sb/s'\\
+ 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 == "packets") && (file_exists("$rrddbpath$curif$packets"))) {
+ /* define graphcmd for packets stats */
+ $graphcmd = "$rrdtool graph $rrddbpath$curif-$interval-$curgraph.png \\
+ --start -$seconds -e -$average \\
+ --vertical-label \"packets/sec\" \\
+ --title \"`hostname` - $curgraph - $interval\" \\
+ --height 100 --width 650 -x \"$scale\" \\
+ DEF:$curif-in_pps=$rrddbpath$curif$packets:in:AVERAGE \\
+ DEF:$curif-out_pps=$rrddbpath$curif$packets:out:AVERAGE \\
+ \"CDEF:$curif-out_pps_neg=$curif-out_pps,-1,*\" \\
+ \"CDEF:$curif-pps_in=$curif-in_pps,0,12500000,LIMIT,UN,0,$curif-in_pps,IF,$average,*\" \\
+ \"CDEF:$curif-pps_out=$curif-out_pps,0,12500000,LIMIT,UN,0,$curif-out_pps,IF,$average,*\" \\
+ \"CDEF:$curif-pps_io=$curif-in_pps,$curif-out_pps,+\" \\
+ \"CDEF:$curif-pps=$curif-pps_in,$curif-pps_out,+\" \\
+ \"CDEF:$curif-pps_in_t=$curif-in_pps,0,12500000,LIMIT,UN,0,$curif-in_pps,IF,$seconds,*\" \\
+ \"CDEF:$curif-pps_out_t=$curif-out_pps,0,12500000,LIMIT,UN,0,$curif-out_pps,IF,$seconds,*\" \\
+ \"CDEF:$curif-pps_t=$curif-pps_in_t,$curif-pps_out_t,+\" \\
+ AREA:$curif-in_pps#990000:$curif-in \\
+ AREA:$curif-out_pps_neg#666666:$curif-out \\
+ COMMENT:\"\\n\"\\
+ COMMENT:\"\t\t maximum average current period\\n\"\\
+ COMMENT:\"in\t\"\\
+ GPRINT:$curif-in_pps:MAX:'%7.2lf %s pps'\\
+ GPRINT:$curif-in_pps:AVERAGE:'%7.2lf %S pps'\\
+ GPRINT:$curif-in_pps:LAST:'%7.2lf %S pps'\\
+ GPRINT:$curif-pps_in_t:AVERAGE:'%7.2lf %s pkts'\\
+ COMMENT:\"\\n\"\\
+ COMMENT:\"out\t\"\\
+ GPRINT:$curif-out_pps:MAX:'%7.2lf %s pps'\\
+ GPRINT:$curif-out_pps:AVERAGE:'%7.2lf %S pps'\\
+ GPRINT:$curif-out_pps:LAST:'%7.2lf %S pps'\\
+ GPRINT:$curif-pps_out_t:AVERAGE:'%7.2lf %s pkts'\\
+ COMMENT:\"\\n\"\\
+ COMMENT:\"totals\"\\
+ GPRINT:$curif-pps_io:MAX:'%7.2lf %s pps'\\
+ GPRINT:$curif-pps_io:AVERAGE:'%7.2lf %s pps'\\
+ GPRINT:$curif-pps_io:LAST:'%7.2lf %s pps'\\
+ GPRINT:$curif-pps_t:AVERAGE:'%7.2lf %s pkts'\\
+ 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 == "queues") && (file_exists("$rrddbpath$curif$queues"))) {
+ /* define graphcmd for queue stats */
+ $graphcmd = "$rrdtool graph $rrddbpath$curif-$interval-$curgraph.png \\
+ --start -$seconds -e -$average \\
+ --vertical-label \"bits/sec\" \\
+ --title \"`hostname` - $curgraph - $interval\" \\
+ --height 200 --width 650 -x \"$scale\" \\";
+ if (!is_array($config['shaper']['queue'])) {
+ $config['shaper']['queue'] = array();
+ }
+ $a_queues = &$config['shaper']['queue'];
+ /* determine in and out interface at a later time. Asume wan for now.*/
+ $i = 0;
+ $t = 0;
+ $colors = array('000000','7B0000','990000','BB0000','CC0000','D90000','EE0000','FF0000','CC0000');
+ foreach ($a_queues as $queue) {
+ $name = $queue['name'];
+ if((stristr($name, "$upif")) || (stristr($name, "up"))) {
+ $color = "$colors[$t]";
+ if($t > 0) { $stack = ":STACK"; }
+ $graphcmd .= "DEF:$name=$rrddbpath$curif$queues:$name:AVERAGE \\
+ \"CDEF:$name-bytes_out=$name,0,$upstream,LIMIT,UN,0,$name,IF\" \\
+ \"CDEF:$name-bits_out=$name-bytes_out,8,*\" \\
+ \"CDEF:$name-bits_out_neg=$name-bits_out,-1,*\" \\
+ AREA:$name-bits_out_neg#${color}:$name$stack \\";
+ $t++;
+ if($t > 7) { $t = 0; }
+ }
+ }
+ $graphcmd .= "COMMENT:\"\\n\" \\";
+ $colors = array('000000','7B7B7B','999999','BBBBBB','CCCCCC','D9D9D9','EEEEEE','FFFFFF','CCCCCC');
+ $stack = "";
+ foreach ($a_queues as $queue) {
+ $name = $queue['name'];
+ if((stristr($name, "$downif")) || (stristr($name, "down"))) {
+ $color = "$colors[$i]";
+ if($i > 0) { $stack = ":STACK"; }
+ $graphcmd .= "DEF:$name=$rrddbpath$curif$queues:$name:AVERAGE \\
+ \"CDEF:$name-bytes_in=$name,0,$downstream,LIMIT,UN,0,$name,IF\" \\
+ \"CDEF:$name-bits_in=$name-bytes_in,8,*\" \\
+ AREA:$name-bits_in#${color}:$name$stack \\";
+ $i++;
+ if($i > 7) { $i = 0; }
+ }
+ }
+ $graphcmd .= "COMMENT:\"\\n\" \\";
+ $graphcmd .= "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\"`\"";
+ }
+elseif(($curgraph == "spamd") && (file_exists("$rrddbpath$spamd"))) {
+ /* graph a spamd statistics graph */
+ $graphcmd = "$rrdtool graph $rrddbpath$curif-$interval-$curgraph.png \\
+ --start -$seconds -e -$average \\
+ --title=\"Spamd statistics for last $interval\" \\
+ --vertical-label=\"Conn / Time, sec.\" \\
+ --height 150 --width 650 --no-gridfit \\
+ -x \"$scale\" --lower-limit 0 \\
+ DEF:consmin=$rrddbpath$spamd:conn:MIN \\
+ DEF:consavg=$rrddbpath$spamd:conn:AVERAGE \\
+ DEF:consmax=$rrddbpath$spamd:conn:MAX \\
+ DEF:timemin=$rrddbpath$spamd:time:MIN \\
+ DEF:timeavg=$rrddbpath$spamd:time:AVERAGE \\
+ DEF:timemax=$rrddbpath$spamd:time:MAX \\
+ \"CDEF:timeminadj=timemin,0,86400,LIMIT,UN,0,timemin,IF\" \\
+ \"CDEF:timeavgadj=timeavg,0,86400,LIMIT,UN,0,timeavg,IF\" \\
+ \"CDEF:timemaxadj=timemax,0,86400,LIMIT,UN,0,timemax,IF\" \\
+ \"CDEF:t1=timeminadj,timeavgadj,+,2,/,timeminadj,-\" \\
+ \"CDEF:t2=timeavgadj,timemaxadj,+,2,/,timeminadj,-,t1,-\" \\
+ \"CDEF:t3=timemaxadj,timeminadj,-,t1,-,t2,-\" \\
+ AREA:timeminadj \\
+ AREA:t1#DDDDFF::STACK \\
+ AREA:t2#AAAAFF::STACK \\
+ AREA:t3#DDDDFF::STACK \\
+ LINE2:timeavgadj#000066:\"Time \" \\
+ GPRINT:timeminadj:MIN:\"Min\\:%6.2lf\\t\" \\
+ GPRINT:timeavgadj:AVERAGE:\"Avg\\:%6.2lf\\t\" \\
+ GPRINT:timemaxadj:MAX:\"Max\\:%6.2lf\\n\" \\
+ AREA:consmax#00AA00BB \\
+ AREA:consmin#FFFFFFFF \\
+ LINE1:consmin#00660088 \\
+ LINE1:consmax#FFFFFF88 \\
+ LINE1:consavg#006600:\"Cons \" \\
+ GPRINT:consmin:MIN:\"Min\\:%6.2lf\\t\" \\
+ GPRINT:consavg:AVERAGE:\"Avg\\:%6.2lf\\t\" \\
+ GPRINT:consmax:MAX:\"Max\\:%6.2lf\\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 "<b>Sorry we do not have data to graph $curgraph for $curif with.</b><br>";
+ }
+
+ /* 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 ) {
+ exec("$graphcmd 2>&1", $graphcmdoutput, $graphcmdreturn);
+ usleep(500);
+ }
+ } else {
+ exec("$graphcmd 2>&1", $graphcmdoutput, $graphcmdreturn);
+ usleep(500);
+ }
+ if($graphcmdreturn != 0) {
+ PRINT "Failed to create graph with error code
+$graphcmdreturn, the error is: $graphcmdoutput[0]";
+ }
+
+ if(file_exists("$rrddbpath/$curif-$interval-$curgraph.png")) {
+ header("Content-type: image/png");
+ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+ header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
+ header("Cache-Control: no-store, no-cache, must-revalidate");
+ header("Cache-Control: post-check=0, pre-check=0", false);
+ header("Pragma: no-cache");
+ $file= "$rrddbpath/$curif-$interval-$curgraph.png";
+ $size= filesize($file);
+ header("Content-Length: $size bytes");
+ readfile($file);
+ }
+
+
+?>
OpenPOWER on IntegriCloud