Location: PHPKode > projects > Network Traffic Monitor > sampling/calculateMeans.php


#Network Traffic Monitor is an application to monitor the network traffic on all SNMP managable devices.
#Copyright (c) 2004, Daimler Trust nv <hide@address.com> - Jan Van Hees <hide@address.com>
#This file is part of Network Traffic Monitor.
#    Network Traffic Monitor is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#    Network Traffic Monitor is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with Network Traffic Monitor; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
include ('config.php');

$dat = date("Y-m-");
$dater = $dat;
$hour = date("G");
$day = date("d");
if($hour == 00){
	$day -= 1;
	if($day < 10) $day="0".$day;
}//if midnight	
	$hour -= 1;
if($hour < 10) $hour="0".$hour;
$date = $date." $hour:%";
$sql = "SELECT DISTINCT porttraffic.pid";
$temp = $db->query($sql);
$counter = $temp->numrows();
$sql = "SELECT pid from ports";

$port = $db->query($sql) OR die ("SQL error");

$hour .=":00:00";
$dater .= "$day $hour";
#$dater ="2004-03-24 23:00:00";
// Get each row of data on each iteration until
// there are no more rows
echo "date: $date  dater: $dater \n";
while ($p = $port->fetchRow()){
	$sql1 = "SELECT DISTINCT porttraffic.pid, porttraffic.incoming, porttraffic.outgoing, porttraffic.times
         FROM porttraffic
	WHERE porttraffic.times LIKE '$date' AND porttraffic.pid=$p[0]
	ORDER BY porttraffic.times DESC";
	$result = $db->query($sql1) OR die("SQL error");

	while ($row = $result->fetchRow()) {
		$sumIn += $row[1];
		$sumOut +=$row[2];
	$insert = "INSERT INTO hourtraffic (pid, times, incoming, outgoing) VALUES ($p[0], '$dater', $sumIn, $sumOut)";
	$db->query($insert) OR die ("INSERT error");
	$sumIn = 0;
	$sumOut = 0;
echo "sql1: $sql1\n insert: $insert\n";
Return current item: Network Traffic Monitor