diff --git a/sysutils/pfSense-pkg-RRD_Summary/Makefile b/sysutils/pfSense-pkg-RRD_Summary/Makefile index ee8b16d76121..8a4ea9bfc58e 100644 --- a/sysutils/pfSense-pkg-RRD_Summary/Makefile +++ b/sysutils/pfSense-pkg-RRD_Summary/Makefile @@ -1,8 +1,7 @@ # $FreeBSD$ PORTNAME= pfSense-pkg-RRD_Summary -PORTVERSION= 1.3.2 -PORTREVISION= 2 +PORTVERSION= 2.0 CATEGORIES= sysutils MASTER_SITES= # empty DISTFILES= # empty diff --git a/sysutils/pfSense-pkg-RRD_Summary/files/usr/local/pkg/rrd-summary.xml b/sysutils/pfSense-pkg-RRD_Summary/files/usr/local/pkg/rrd-summary.xml index 33c5744ba6cf..c12cc9927620 100644 --- a/sysutils/pfSense-pkg-RRD_Summary/files/usr/local/pkg/rrd-summary.xml +++ b/sysutils/pfSense-pkg-RRD_Summary/files/usr/local/pkg/rrd-summary.xml @@ -30,7 +30,7 @@ Status: RRD Summary RRD Summary - Display total amount of traffic passed In/Out during this and the previous month. + Estimated month-over-month traffic passed In/Out during the specified period.
Status
/status_rrd_summary.php
diff --git a/sysutils/pfSense-pkg-RRD_Summary/files/usr/local/share/pfSense-pkg-RRD_Summary/info.xml b/sysutils/pfSense-pkg-RRD_Summary/files/usr/local/share/pfSense-pkg-RRD_Summary/info.xml index d96239bf18be..5ed6a0acfd33 100644 --- a/sysutils/pfSense-pkg-RRD_Summary/files/usr/local/share/pfSense-pkg-RRD_Summary/info.xml +++ b/sysutils/pfSense-pkg-RRD_Summary/files/usr/local/share/pfSense-pkg-RRD_Summary/info.xml @@ -3,7 +3,7 @@ RRD Summary RRD_Summary - + %%PKGVERSION%% rrd-summary.xml diff --git a/sysutils/pfSense-pkg-RRD_Summary/files/usr/local/www/status_rrd_summary.php b/sysutils/pfSense-pkg-RRD_Summary/files/usr/local/www/status_rrd_summary.php index 39ad4c86a951..5cb55762a4bd 100644 --- a/sysutils/pfSense-pkg-RRD_Summary/files/usr/local/www/status_rrd_summary.php +++ b/sysutils/pfSense-pkg-RRD_Summary/files/usr/local/www/status_rrd_summary.php @@ -20,40 +20,87 @@ */ require_once("guiconfig.inc"); -$rrds = glob("/var/db/rrd/*-traffic.rrd"); -$startday = isset($_POST['startday']) ? $_POST['startday'] : "01"; -$rrd = isset($_POST['rrd']) ? $_POST['rrd'] : "wan-traffic.rrd"; - -$start = "00 " . date("m/{$startday}/Y"); -$lastmonthstart = "00 " . date("m/d/Y", strtotime("-1 month", strtotime(date("m/{$startday}/Y")))); -$lastmonthend = "00 " . date("m/d/Y", strtotime("-1 second", strtotime(date("m/{$startday}/Y")))); - -$thismonth = fetch_rrd_summary($rrd, $start, "now"); -$lastmonth = fetch_rrd_summary($rrd, $lastmonthstart, $lastmonthend, 24*60*60); - -function fetch_rrd_summary($rrd, $start, $end, $resolution=60*60) { +// Using too small a divisor for traffic sums will likely exceed PHP_MAX_INT +$unitlist = array("MiB" => 2, "GiB" => 3, "TiB" => 4, "PiB" => 5); + +// validate interface +$iflist = get_configured_interface_list(); +$interface = filter_input(INPUT_POST, "interface", FILTER_SANITIZE_STRING); +$interface = in_array($interface, $iflist) ? $interface : "wan"; + +// get rrd bounds for interface +$rrd = "{$interface}-traffic.rrd"; +$data = fetch_rrd_summary($rrd, "-10y", "now"); +$firstyear = date("Y", ($data["first"] > 0) ? $data["first"] : time() ); +$lastyear = date("Y", ($data["last"] > 0) ? $data["last"] : time() ); + +// validate year +$startyear = filter_input(INPUT_POST, "startyear", FILTER_VALIDATE_INT, + array("options" => array("min_range" => 0, "max_range" => $lastyear)) ); +$startyear = ($startyear >= $firstyear || $startyear == "0") ? $startyear : $lastyear; +// validate startday +$startday = filter_input(INPUT_POST, "startday", FILTER_VALIDATE_INT, + array("options" => array("min_range" => 1, "max_range" => 28)) ); +$startday = ($startday > 0) ? $startday : 1; +// validate units +$units = filter_input(INPUT_POST, "units", FILTER_VALIDATE_INT, + array("options" => array("min_range" => min(array_values($unitlist)), "max_range" => max(array_values($unitlist)) )) ); +$units = in_array($units, $unitlist) ? $units : $unitlist["GiB"]; + +// 1:timestamp 2:inpass 3:outpass 4:inblock 5:outblock 6:inpass6 7:outpass6 8:inblock6 9:outblock6 +// total_in = $2 + $4 + $6 + $8; total_out = $3 + $7 (blocked outbound traffic is excluded) +function fetch_rrd_summary($rrd, $start, $end, $units=2, $resolution=24*60*60) { $traffic = array(); $rrd = escapeshellarg("/var/db/rrd/{$rrd}"); $start = escapeshellarg($start); $end = escapeshellarg($end); - exec("/usr/local/bin/rrdtool fetch {$rrd} AVERAGE -r {$resolution} -s {$start} -e {$end} | grep -v nan | awk '{ sum1 += $2/(1024*1024) + $4/(1024*1024) + $6/(1024*1024) + $8/(1024*1024); sum2 += $3/(1024*1024) + $5/(1024*1024) + $7/(1024*1024) + $9/(1024*1024); } END { printf \"%u|%u\", sum1*{$resolution}, sum2*{$resolution}; }'", $traffic); - return explode('|', trim($traffic[0])); + exec("/usr/local/bin/rrdtool fetch {$rrd} AVERAGE -r {$resolution} -s {$start} -e {$end}", $traffic); + $divisor = 1024 ** $units; + $t_keys = preg_split("/\s+/", $traffic[0]); // grab keys + //print "time=$t_first st=$start end=$end div=$divisor res=$resolution"; + $traffic = preg_grep("/^[0-9]+:/", $traffic); // select data rows + $traffic = preg_grep("/nan/", $traffic, PREG_GREP_INVERT); // filter nan rows + $data = array( "first" => time() ); + foreach ( $traffic as $t ) { + $t = preg_split("/[\s:]+/", $t); + if (count($t) != count($t_keys)) continue; // error: field mismatch + $data["first"] = min($t[0], $data["first"]); + $data["last"] = max($t[0], $data["last"]); + foreach ($t_keys as $i => $k) { $data[$k] += ($t[$i] / $divisor) * $resolution; } + } + // Adjust for resolution + foreach ($t_keys as $k) { + if (preg_match("/^outblock/", $k)) continue; + $data["total_in"] += preg_match("/^in/", $k) ? $data[$k] : 0; + $data["total_out"] += preg_match("/^out/", $k) ? $data[$k] : 0; + } + return $data; } -function print_rrd_summary_table($data) { ?> -
- - - - - - - - - -
DirectionBandwidth
In MBytes
Out MBytes
Total MBytes
-
- 0 && $startyear != $year) continue; + foreach (range(12, 1, -1) as $month) { + $start = strtotime(date("{$month}/{$startday}/{$year}")); + $end = strtotime("-1 second", strtotime("+1 month", $start)); + if ($start > $last || $end < $first) continue; + if ($start < $first) $start = $first; + if ($end > $last) $end = $last; + $data = fetch_rrd_summary($rrd, "epoch+{$start}s", "epoch+{$end}s", $units, 24*60*60); + ?> + + to + + + + + $section = new Form_Section('Select RRD Parameters'); -$rrd_options = array(); -foreach ($rrds as $r) { - $r = basename($r); - $rrd_options[$r] = $r; +$if_options = array(); +foreach ($iflist as $i) { + $if_options[$i] = $i; } $section->addInput(new Form_Select( - 'rrd', - 'RRD File', - $rrd, - $rrd_options + 'interface', + 'Interface', + $interface, + $if_options +)); + +$section->addInput(new Form_Select( + 'units', + 'Units', + $units, + array_flip($unitlist) +)); + +$section->addInput(new Form_Select( + 'startyear', + 'Year', + $startyear, + array("0" => "All") + array_combine(range($lastyear, $firstyear, -1), range($lastyear, $firstyear, -1)) )); $section->addInput(new Form_Select( @@ -93,18 +153,29 @@ function print_rrd_summary_table($data) { ?>

- This Month (to date, does not include this hour, starting at day ): - -
- Last Month: - +
+ Estimated monthly traffic for given time period beginning on day of each month + + + + + + + + + + + + +
+