diff options
Diffstat (limited to 'config/rrd-summary')
-rw-r--r-- | config/rrd-summary/rrd-summary.xml | 70 | ||||
-rw-r--r-- | config/rrd-summary/status_rrd_summary.php | 90 |
2 files changed, 160 insertions, 0 deletions
diff --git a/config/rrd-summary/rrd-summary.xml b/config/rrd-summary/rrd-summary.xml new file mode 100644 index 00000000..db410502 --- /dev/null +++ b/config/rrd-summary/rrd-summary.xml @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE packagegui SYSTEM "../schema/packages.dtd"> +<?xml-stylesheet type="text/xsl" href="../xsl/package.xsl"?> +<packagegui> + <copyright> + <![CDATA[ +/* $Id$ */ +/* ========================================================================== */ +/* + rrd-summary.xml + part of pfSense (http://www.pfSense.com) + Copyright (C) 2010 to whom it may belong + All rights reserved. + + Based on m0n0wall (http://m0n0.ch/wall) + Copyright (C) 2003-2006 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. + */ +/* ========================================================================== */ + ]]> + </copyright> + <description>RRD Summary Page</description> + <requirements>None</requirements> + <faq>Currently there are no FAQ items provided.</faq> + <name>RRD Summary</name> + <version>1.0</version> + <title>Status: RRD Summary</title> + <menu> + <name>RRD Summary</name> + <tooltiptext></tooltiptext> + <section>Status</section> + <url>/status_rrd_summary.php</url> + </menu> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>077</chmod> + <item>http://www.pfsense.com/packages/config/rrd-summary/status_rrd_summary.php</item> + </additional_files_needed> + <custom_php_deinstall_command> + <![CDATA[ + $version = file_get_contents("/etc/version"); + if ($version[0] < 2) { + unlink_if_exists("/usr/local/www/status_rrd_summary.php"); + } + ]]> + </custom_php_deinstall_command> +</packagegui>
\ No newline at end of file diff --git a/config/rrd-summary/status_rrd_summary.php b/config/rrd-summary/status_rrd_summary.php new file mode 100644 index 00000000..8906ee55 --- /dev/null +++ b/config/rrd-summary/status_rrd_summary.php @@ -0,0 +1,90 @@ +<?php +/* + rrd_summary.php + Copyright (C) 2010 Jim Pingle + + 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_once("guiconfig.inc"); + +$startday = isset($_POST['startday']) ? $_POST['startday'] : "01"; +$rrd = isset($_POST['rrd']) ? $_POST['rrd'] : "wan-traffic.rrd"; + +$start = "00 " . date("m/{$startday}/Y"); +$lastmonth = "00 " . date("m/{$startday}/Y", strtotime("-1 month", strtotime(date("m/{$startday}/Y")))); + +$thismonth = fetch_rrd_summary($rrd, $start, "now"); +$lastmonth = fetch_rrd_summary($rrd, $lastmonth, $start, "86400"); + +function fetch_rrd_summary($rrd, $start, $end, $resolution="3600") { + $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); sum2 += $3/(1024*1024) } END { printf \"%u|%u\", sum1*{$resolution}, sum2*{$resolution}; }'", $traffic); + return explode('|', trim($traffic[0])); +} + +function print_rrd_summary_table($data) { ?> +<table> + <tr><th> </th><th>Bandwidth</th></tr> + <tr><td>In</td><td><?php echo $data[0]; ?> MBytes</td></tr> + <tr><td>Out</td><td><?php echo $data[1]; ?> MBytes</td></tr> + <tr><td>Total</td><td><?php echo $data[0] + $data[1]; ?> MBytes</td></tr> +</table> +<?php +} + +$pgtitle = "Status: RRD Summary"; +include("head.inc"); +include("fbegin.inc"); + +$rrds = glob("/var/db/rrd/*-traffic.rrd"); + +?> +<form name="form1" action="status_rrd_summary.php" method="POST"> + RRD Database: + <select name="rrd" class="formselect" onchange="document.form1.submit()"> + <?php + foreach ($rrds as $r) { + $r = basename($r); + $selected = ($r == $rrd) ? " selected" : ""; + print "<option value=\"{$r}\"{$selected}>{$r}</option>"; + } ?> + </select> + Start Day: + <select name="startday" class="formselect" onchange="document.form1.submit()"> + <?php + for ($day=1; $day < 29; $day++) { + $selected = ($day == $startday) ? " selected" : ""; + print "<option value=\"{$day}\"{$selected}>{$day}</option>"; + } ?> + </select> +</form> +<br/> +This Month (to date, does not include this hour, starting at day <?php echo $startday; ?>): +<?php print_rrd_summary_table($thismonth); ?> +<br/><br/> +Last Month: +<?php print_rrd_summary_table($lastmonth); ?> + +<?php include("fend.inc"); ?> |