diff options
author | Ermal Luçi <eri@pfsense.org> | 2008-02-23 02:22:30 +0000 |
---|---|---|
committer | Ermal Luçi <eri@pfsense.org> | 2008-02-23 02:22:30 +0000 |
commit | 21a0464c1a66792acd91e852c47d7838c49df303 (patch) | |
tree | d8d106d0dab053c921ab41a2a142faff0202648e | |
parent | 8e2a7e8a28d893c287afc69538e7fdb30002ba86 (diff) | |
download | pfsense-21a0464c1a66792acd91e852c47d7838c49df303.zip pfsense-21a0464c1a66792acd91e852c47d7838c49df303.tar.gz |
* Unbreak rrd graphs for queues and make them multiinterface aware
* Add a new tab for queuedrops with multiinterface there is no way to have them in the same tab
* Remove $GLOBAL where used and use proper accessor functions
* Remove Manuel from copyright this file has been rewritten
* Some bugs fixes in general
-rw-r--r-- | etc/inc/pfsense-utils.inc | 53 | ||||
-rw-r--r-- | etc/inc/shaper.inc | 42 | ||||
-rwxr-xr-x | usr/local/www/firewall_rules_edit.php | 8 | ||||
-rwxr-xr-x | usr/local/www/firewall_shaper_queues.php | 20 | ||||
-rwxr-xr-x | usr/local/www/status_rrd_graph.php | 9 | ||||
-rw-r--r-- | usr/local/www/status_rrd_graph_img.php | 26 |
6 files changed, 89 insertions, 69 deletions
diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc index 0db625d..31c2c1b 100644 --- a/etc/inc/pfsense-utils.inc +++ b/etc/inc/pfsense-utils.inc @@ -3016,7 +3016,7 @@ function convert_real_interface_to_friendly_descr($interface) { } function enable_rrd_graphing() { - global $config, $g; + global $config, $g, $altq_list_queues; if($g['booting']) echo "Generating RRD graphs..."; @@ -3030,7 +3030,7 @@ function enable_rrd_graphing() { $quality = "-quality.rrd"; $wireless = "-wireless.rrd"; $queues = "-queues.rrd"; - $queuesdrop = "-queuesdrop.rrd"; + $queuesdrop = "-queuedrops.rrd"; $spamd = "-spamd.rrd"; $proc = "-processor.rrd"; @@ -3070,6 +3070,9 @@ function enable_rrd_graphing() { $downstream = 125000000; $upstream = 125000000; + /* read the shaper config */ + read_altq_config(); + $rrdrestore = ""; $rrdreturn = ""; @@ -3282,22 +3285,35 @@ function enable_rrd_graphing() { $rrdupdatesh .= "`$ifconfig {$realif} list ap| $awk 'gsub(\"M\", \"\") {getline 2;print substr(\$5, 0, length(\$5)-2) \":\" $4 \":\" $3}'`\n"; } - /* WAN interface only statistics */ - if ("$ifname" == "wan") { - /* QUEUES, set up the queues databases */ - if (!is_array($GLOBALS['allqueue_list'])) - read_altq_config(); - - if (is_array($config['shaper']['queue'])) { + if ($altq_list_queues[$ifname]) { + $altq =& $altq_list_queues[$ifname]; + /* NOTE: Is it worth as its own function?! */ + switch ($altq->GetBwscale()) { + case "Gb": + $factor = 1000 * 1000 * 1000; + break; + case "Mb": + $factor = 1000 * 1000; + break; + case "Kb": + $factor = 1000; + break; + case "b": + default: + $factor = 1; + break; + } + $qlist =& $altq->get_queue_list($notused); if (!file_exists("$rrddbpath$ifname$queues")) { /* create rrd file if it does not exist */ log_error("Create RRD database $rrddbpath$ifname$queues"); $rrdcreate = "$rrdtool create $rrddbpath$ifname$queues --step $rrdqueuesinterval "; /* loop list of shaper queues */ $q = 0; - foreach ($GLOBALS['allqueue_list'] as $qname) { - $rrdcreate .= "DS:$qname:COUNTER:$queuesvalid:0:$downstream "; + foreach ($qlist as $qname => $q) { + $qbandwidth = $altq->GetBandwidth() * $factor; + $rrdcreate .= "DS:$qname:COUNTER:$queuesvalid:0:$qbandwidth "; } $rrdcreate .= "RRA:AVERAGE:0.5:1:1000 "; @@ -3319,8 +3335,9 @@ function enable_rrd_graphing() { $rrdcreate = "$rrdtool create $rrddbpath$ifname$queuesdrop --step $rrdqueuesdropinterval "; /* loop list of shaper queues */ $q = 0; - foreach ($GLOBALS['allqueue_list'] as $queue) { - $rrdcreate .= "DS:$queue:COUNTER:$queuesdropvalid:0:$downstream "; + foreach ($qlist as $qname => $q) { + $qbandwidth = $altq->GetBandwidth() * $factor; + $rrdcreate .= "DS:$qname:COUNTER:$queuesdropvalid:0:$qbandwidth "; } $rrdcreate .= "RRA:AVERAGE:0.5:1:1000 "; @@ -3339,7 +3356,8 @@ function enable_rrd_graphing() { $rrdqcommand = "-t "; $rrducommand = "N"; $q = 0; - foreach ($GLOBALS['allqueue_list'] as $queue) { + foreach ($qlist as $q) { + $queue = $q->GetQname(); if($q == 0) { $rrdqcommand .= "{$queue}"; } else { @@ -3354,7 +3372,7 @@ function enable_rrd_graphing() { /* awk function to gather shaper data */ /* yes, it's special */ - $rrdupdatesh .= "` pfctl -vsq | awk 'BEGIN {printf \"$rrdtool update $rrddbpath$ifname$queues \" } "; + $rrdupdatesh .= "` pfctl -vsq -i {$realif} | awk 'BEGIN {printf \"$rrdtool update $rrddbpath$ifname$queues \" } "; $rrdupdatesh .= "{ "; $rrdupdatesh .= "if ((\$1 == \"queue\") && ( \$2 ~ /^q/ )) { "; $rrdupdatesh .= "dsname = dsname \":\" \$2 ; "; @@ -3370,7 +3388,7 @@ function enable_rrd_graphing() { $rrdupdatesh .= "printf \"-t \" dsname \" N:\" dsdata }' "; $rrdupdatesh .= "dsname=\"\" dsdata=\"\"`\n\n"; - $rrdupdatesh .= "` pfctl -vsq | awk 'BEGIN {printf \"$rrdtool update $rrddbpath$ifname$queuesdrop \" } "; + $rrdupdatesh .= "` pfctl -vsq -i {$realif} | awk 'BEGIN {printf \"$rrdtool update $rrddbpath$ifname$queuesdrop \" } "; $rrdupdatesh .= "{ "; $rrdupdatesh .= "if ((\$1 == \"queue\") && ( \$2 ~ /^q/ )) { "; $rrdupdatesh .= "dsname = dsname \":\" \$2 ; "; @@ -3386,7 +3404,6 @@ function enable_rrd_graphing() { $rrdupdatesh .= "printf \"-t \" dsname \" N:\" dsdata }' "; $rrdupdatesh .= "dsname=\"\" dsdata=\"\"`\n\n"; } - } } $i++; @@ -3992,4 +4009,4 @@ function lookup_gateway_interface_by_name($name) { } } -?>
\ No newline at end of file +?> diff --git a/etc/inc/shaper.inc b/etc/inc/shaper.inc index bc01ba8..9a26c14 100644 --- a/etc/inc/shaper.inc +++ b/etc/inc/shaper.inc @@ -348,6 +348,7 @@ class altq_root_queue { foreach ($this->queues as $queue) $queue->get_queue_list(&$qlist); } + return $qlist; } function &add_queue($interface, &$queue, &$path, &$input_errors) { @@ -393,8 +394,6 @@ class altq_root_queue { $q->SetAvailableBandwidth($myBw); $this->SetAvailableBandwidth($this->GetAvailableBandwidth() - $myBw); $this->queues[$q->GetQname()] = &$q; - $GLOBALS['allqueue_list'][] = $q->GetQname(); - $GLOBALS['unique_qlist'][$q->GetQname()] = $q->GetQname(); ref_on_altq_queue_list($this->GetQname(), $q->GetQname()); if (is_array($queue['queue'])) { foreach ($queue['queue'] as $key1 => $que) { @@ -838,7 +837,7 @@ function GetEcn() { $qlist[$this->GetQname()] = & $this; if (is_array($this->subqueues)) { foreach ($this->subqueues as $queue) - $queue->get_queue_list(&$qlist); + $queue->get_queue_list($qlist); } } @@ -1239,8 +1238,6 @@ class hfsc_queue extends priq_queue { $this->SetAvailableBandwidth($this->GetAvailableBandwidth() - $myBw); $this->subqueues[$q->GetQname()] =& $q; //new hfsc_queue() - $GLOBALS['allqueue_list'][] = $q->GetQname(); - $GLOBALS['unique_qlist'][$q->GetQname()] = $q->GetQname(); ref_on_altq_queue_list($this->GetQname(), $q->GetQname()); if (is_array($qname['queue'])) { foreach ($qname['queue'] as $key1 => $que) { @@ -1765,8 +1762,6 @@ class cbq_queue extends priq_queue { $q->SetEnabled("on"); $q->SetLink($path); $this->subqueues[$q->GetQName()] = &$q; - $GLOBALS['allqueue_list'][] = $q->GetQname(); - $GLOBALS['unique_qlist'][$q->GetQname()] = $q->GetQname(); ref_on_altq_queue_list($this->GetQname(), $q->GetQname()); if (is_array($qname['queue'])) { foreach ($qname['queue'] as $key1 => $que) { @@ -2037,6 +2032,35 @@ function altq_get_default_queue($interface) { return $altq_tmp->GetDefaultQueuePresent(); } +function altq_check_default_queues() { + global $altq_list_queues; + + $count = 0; + if (is_array($altq_list_queues)) { + foreach($altq_list_queues as $altq) { + if ($altq->GetDefaultQueuePresent()) + $count++; + } + } + else $count++;; + + return 0; +} + +function &get_unique_queue_list() { + global $altq_list_queues; + + $qlist = array(); + if (is_array($altq_list_queues)) { + foreach ($altq_list_queues as $altq) { + $tmplist =& $altq->get_queue_list(); + foreach ($tmplist as $qname => $link) + $qlist[$qname] = $link; + } + } + return $qlist; +} + function get_is_ftp_queue($interface, $qname) { global $config; @@ -2077,9 +2101,6 @@ function read_altq_config() { $altq_list_queues = array(); - $GLOBALS['allqueue_list'] = array(); - $GLOBALS['unique_qlist'] = array(); - if (!is_array($config['shaper']['queue'])) return; @@ -2091,7 +2112,6 @@ function read_altq_config() { $root->ReadConfig($conf); array_push($path, $key); $root->SetLink($path); - $GLOBALS['allqueue_list'][] = $root->GetQname(); if (is_array($conf['queue'])) { foreach ($conf['queue'] as $key1 => $q) { array_push($path, $key1); diff --git a/usr/local/www/firewall_rules_edit.php b/usr/local/www/firewall_rules_edit.php index 033d7ff..bc509d8 100755 --- a/usr/local/www/firewall_rules_edit.php +++ b/usr/local/www/firewall_rules_edit.php @@ -993,9 +993,11 @@ on another rule.")?> <td width="78%" class="vtable"> <select name="ackqueue"> <?php - if (!is_array($altq_list_queues)) read_altq_config(); /* XXX: */ - foreach ($GLOBALS['unique_qlist'] as $q) { + $qlist =& get_unique_queue_list(); + if (!is_array($qlist)) + $qlist = array(); + foreach ($qlist as $q => $qkey) { echo "<option value=\"$q\""; if ($q == $pconfig['ackqueue']) { $qselected = 1; @@ -1011,7 +1013,7 @@ on another rule.")?> <select name="defaultqueue"> <?php $qselected = 0; - foreach ($GLOBALS['unique_qlist'] as $q) { + foreach ($qlist as $q => $qkey) { echo "<option value=\"$q\""; if ($q == $pconfig['defaultqueue']) { $qselected = 1; diff --git a/usr/local/www/firewall_shaper_queues.php b/usr/local/www/firewall_shaper_queues.php index f65e61b..7b67df3 100755 --- a/usr/local/www/firewall_shaper_queues.php +++ b/usr/local/www/firewall_shaper_queues.php @@ -6,10 +6,6 @@ Copyright (C) 2008 Ermal Luçi 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: @@ -39,20 +35,14 @@ if($_GET['reset'] <> "") { exit; } -if (!is_array($config['shaper']['queue'])) { - $config['shaper']['queue'] = array(); -} - -/* on HEAD it has to use vc_* api on variable_cache.inc */ -if (!is_array($GLOBALS['allqueue_list'])) { - $GLOBALS['allqueue_list'] = array(); -} - -/* XXX: NOTE: When dummynet is implemented these will be moved from here */ read_altq_config(); +$qlist =& get_unique_queue_list(); + +if (!is_array($qlist)) + $qlist = array(); $tree = "<ul class=\"tree\" >"; -foreach ($GLOBALS['allqueue_list'] as $queue) { +foreach ($qlist as $queue => $qkey) { $tree .= "<li><a href=\"firewall_shaper_queues.php?queue={$queue}&action=show\" >{$queue}</a></li>"; } $tree .= "</ul>"; diff --git a/usr/local/www/status_rrd_graph.php b/usr/local/www/status_rrd_graph.php index c318421..aeb03d6 100755 --- a/usr/local/www/status_rrd_graph.php +++ b/usr/local/www/status_rrd_graph.php @@ -47,6 +47,8 @@ if ($_GET['option']) { $curoption = "processor"; } else if($curcat == "queues") { $curoption = "queues"; + } else if($curcat == "queuedrops") { + $curoption = "queuedrops"; } else { $curoption = "wan"; } @@ -111,6 +113,8 @@ include("head.inc"); $tab_array[] = array("Quality", $tabactive, "status_rrd_graph.php?cat=quality"); if($curcat == "queues") { $tabactive = True; } else { $tabactive = False; } $tab_array[] = array("Queues", $tabactive, "status_rrd_graph.php?cat=queues"); + if($curcat == "queuesdrop") { $tabactive = True; } else { $tabactive = False; } + $tab_array[] = array("QueueDrops", $tabactive, "status_rrd_graph.php?cat=queuedrops"); if($curcat == "wireless") { $tabactive = True; } else { $tabactive = False; } $tab_array[] = array("Wireless", $tabactive, "status_rrd_graph.php?cat=wireless"); if($curcat == "settings") { $tabactive = True; } else { $tabactive = False; } @@ -145,11 +149,6 @@ include("head.inc"); echo "<option value=\"$optionc\""; $prettyprint = ucwords(str_replace($search, $replace, $optionc)); break; - case "queues": - $optionc = str_replace($search, $replace, $optionc[1]); - echo "<option value=\"$optionc\""; - $prettyprint = ucwords(str_replace($search, $replace, $optionc)); - break; default: /* Deduce a interface if possible and use the description */ $optionc = "$optionc[0]"; diff --git a/usr/local/www/status_rrd_graph_img.php b/usr/local/www/status_rrd_graph_img.php index 71c9a1d..77b9c1c 100644 --- a/usr/local/www/status_rrd_graph_img.php +++ b/usr/local/www/status_rrd_graph_img.php @@ -106,7 +106,7 @@ rsort($databases); /* compare bytes/sec counters, divide bps by 8 */ read_altq_config(); -if (is_array($altq_list_queues[$curif])) { +if ($altq_list_queues[$curif]) { $altq =& $altq_list_queues[$curif]; switch ($altq->GetBwscale()) { case "Gb": @@ -128,7 +128,7 @@ if (is_array($altq_list_queues[$curif])) { $upif = $curif; $downif = "lan"; /* XXX should this be set to something else?! */ } else { - $altq = array(); + $altq = null; $downstream = 12500000; $upstream = 12500000; $upif = "wan"; @@ -503,17 +503,13 @@ elseif((strstr($curdatabase, "-queues.rrd")) && (file_exists("$rrddbpath$curdata --color SHADEA#eeeeee --color SHADEB#eeeeee \\ --title \"`hostname` - $prettydb - $hperiod - $havg average\" \\ --height 200 --width 620 -x \"$scale\" \\"; - if (!is_array($config['shaper']['queue'])) { - $config['shaper']['queue'] = array(); - } - if (count($altq) > 0) - $a_queue =& $altq->get_queue_list($notused); + if ($altq) + $a_queues =& $altq->get_queue_list(); else $a_queues = array(); $i = 0; $t = 0; - foreach ($a_queues as $queue) { - $name = $queue->GetQname(); + foreach ($a_queues as $name => $q) { $color = "$colorqueuesup[$t]"; if($t > 0) { $stack = ":STACK"; } $graphcmd .= "DEF:$name=$rrddbpath$curdatabase:$name:AVERAGE \\ @@ -527,7 +523,7 @@ elseif((strstr($curdatabase, "-queues.rrd")) && (file_exists("$rrddbpath$curdata $graphcmd .= "COMMENT:\"\\n\" \\"; $graphcmd .= "COMMENT:\"\t\t\t\t\t\t\t\t\t\t\t\t\t`date +\"%b %d %H\:%M\:%S %Y\"`\""; } -elseif((strstr($curdatabase, "-queuesdrop.rrd")) && (file_exists("$rrddbpath$curdatabase"))) { +elseif((strstr($curdatabase, "-queuedrops.rrd")) && (file_exists("$rrddbpath$curdatabase"))) { /* define graphcmd for queuedrop stats */ $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$interval.png \\ --start -$seconds -e -$average \\ @@ -535,17 +531,13 @@ elseif((strstr($curdatabase, "-queuesdrop.rrd")) && (file_exists("$rrddbpath$cur --color SHADEA#eeeeee --color SHADEB#eeeeee \\ --title \"`hostname` - $prettydb - $hperiod - $havg average\" \\ --height 200 --width 620 -x \"$scale\" \\"; - if (!is_array($config['shaper']['queue'])) { - $config['shaper']['queue'] = array(); - } - if (count($altq) > 0) - $a_queue =& $altq->get_queue_list($notused); + if ($altq) + $a_queues =& $altq->get_queue_list(); else $a_queues = array(); $i = 0; $t = 0; - foreach ($a_queues as $queue) { - $name = $queue->GetQname(); + foreach ($a_queues as $name => $q) { $color = "$colorqueuesdropup[$t]"; if($t > 0) { $stack = ":STACK"; } $graphcmd .= "DEF:$name=$rrddbpath$curdatabase:$name:AVERAGE \\ |