Tak jak w temacie nowe nnd i brak statystyk czemu ??
stat.pl
#! /usr/bin/perl
#--------Ustawienie sta³ych u¿ytkownika-------------------
my $path = '/tmp/stats'; # katalog ze statystyk±
my $ipt = '/usr/local/sbin/iptables'; # lokalizacja iptables
my $hosts_names = 1; # nazwy zamiast IP (domy¶lnie: wy³±czone
stat.php
<?php
$path = "/tmp/stats"; //¶cie¿ka do plików ze statystyk±
$hosts_names = 1; //u¿ywaæ nazw hostów zamiast IP
$default_sorting = 'download'; //domy¶lne sortowanie ('download' 'upload', 'hos
$skip_zeroes = 1; //pomija komputery z zerowymi danymi
$time_limit = 300; //czas (w sekundach), po którym komputery zostan
//uznane za nieaktywne
/*******************************************************************/
/etc/rc.d/bałwan jestem
iptables -t mangle -D FORWARD -i eth0 -j STAT >/dev/null 2>&1
iptables -t mangle -D FORWARD -o eth0 -j STAT >/dev/null 2>&1
iptables -t mangle -F STAT >/dev/null 2>&1
iptables -t mangle -X STAT >/dev/null 2>&1
iptables -t mangle -N STAT
iptables -t mangle -I FORWARD -o eth0 -j STAT
iptables -t mangle -I FORWARD -i eth0 -j STAT
# i dla kazdego komputera po dwie reguly
iptables -t mangle -A STAT -d 192.168.0.2
iptables -t mangle -A STAT -s 192.168.0.2
iptables -t mangle -A STAT -d 192.168.0.5
iptables -t mangle -A STAT -s 192.168.0.5
iptables -t mangle -A STAT -d 192.168.0.6
iptables -t mangle -A STAT -s 192.168.0.6
iptables -t mangle -A STAT -d 192.168.0.9
iptables -t mangle -A STAT -s 192.168.0.9
iptables -t mangle -A STAT -d 192.168.0.11
iptables -t mangle -A STAT -s 192.168.0.11
iptables -t mangle -A STAT -d 192.168.0.40
iptables -t mangle -A STAT -s 192.168.0.40
zrobilem katalog w tmp ---> stats i tam sie zrobil nowy plik 20062 ale jest pusty nie wiem czemu
po wpisaniu w przegladarke
http://192.168.0.1/stats/stat.php wyswietla mi sie
<?php
$path = "/tmp/stats"; //ścieżka do plików ze statystyką
$hosts_names = 1; //używać nazw hostów zamiast IP
$default_sorting = 'download'; //domyślne sortowanie ('download' 'upload', 'host')
$skip_zeroes = 1; //pomija komputery z zerowymi danymi
$time_limit = 300; //czas (w sekundach), po którym komputery zostaną
//uznane za nieaktywne
/*******************************************************************/
$title = 'Statystyka wykorzystania łącza v.0.9.5';
$footer = 'Copyright © 2003-2005 A.L.E.C (<a href="http://alec.pl">www.alec.pl</a>)';
$months = array ('styczeń','luty','marzec','kwiecień','maj','czerwiec','lipiec','sierpień','wrzesień','październik','listopad','grudzień');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<TITLE><? echo $title; ?></TITLE>
<LINK rel="stylesheet" href="images/style.css" type="text/css">
</HEAD>
<BODY>
<?
function setunits($data)
{
if ( !($data < (1024*1024*1000)) ) {
$number = $data / (1024*1024*1024);
$unit = "GB";
} elseif ( !($data < (1024*1000) ) ) {
$number = $data / (1024*1024);
$unit = "MB";
} else {
$number = $data / 1024;
$unit = "KB";
}
return array($number, $unit);
}
$now = time();
$date = getdate();
$month = ( $_POST['month'] ? $_POST['month'] : $date['mon'] );
$year = ( $_POST['year'] ? $_POST['year'] : $date['year'] );
$sort = ( $_POST['sort'] ? $_POST['sort'] : $default_sorting );
/****************************************************************/
print '<P class="header">'.$title.'</P>';
print '<P><FORM class="form" name="traffic" method="post" action="stat.php">';
print 'miesiąc:<SELECT class="select" name="month" OnChange="javascript:document.traffic.submit();">';
for ( $i=1; $i<=12; $i++ )
{
print '<OPTION value="'.$i.'"';
if ( $i==$month )
print 'SELECTED';
print '>'.$months[$i-1].'</OPTION>';
};
print '</SELECT> ';
print 'rok:<SELECT class="select" name="year" OnChange="javascript:document.traffic.submit();">';
for ( $i=0; $i<=10; $i++ )
{
print '<OPTION value="'.($i+2000).'"';
if ( $i==$year-2000 )
print 'SELECTED';
print '>'.($i+2000).'</OPTION>';
};
print '</SELECT> ';
print 'sortowanie:<SELECT class="select" name="sort" OnChange="javascript:document.traffic.submit();">';
print '<OPTION value="download"'.($sort=='download' ? 'SELECTED' : '').'>download</OPTION>';
print '<OPTION value="upload"'.($sort=='upload' ? 'SELECTED' : '').'>upload</OPTION>';
print '<OPTION value="host"'.($sort=='host' ? 'SELECTED' : '').'>host</OPTION>';
print '</SELECT>';
print '</FORM>';
//otwieramy plik ************************
if( !($file = @fopen($path.'/'.$year.$month,'r')) )
{
print '<P class="error"><BR><BR>Brak statystyk z wybranego okresu!</P>';
die;
}
//czytamy dane
while (!feof($file))
$lines[] = fgets($file,100);
fclose($file);
foreach ($lines as $line)
{
$tab = preg_split('/[ \t]+/', $line);
$host = trim($tab[0]);
$up = trim($tab[1]);
$down = trim($tab[2]);
$atime = trim($tab[3]);
if(!$host || ($skip_zeroes && !($up || $down)) )
{
continue;
}
$hosts[] = ($hosts_names ? $host : ip2long($host));
$upload[] = $up;
$download[] = $down;
$active[] = $atime>$now-$time_limit ? 1 : 0;
}
//skalowanie wykresów ********************
$maks_up = max($upload);
$maks_down = max($download);
$maks = ( $maks_up > $maks_down ? $maks_up : $maks_down );
if ($maks == 0)
$maks = 1; //co by nie było dzielenia przez zero
//sortowanie *****************************
switch($sort)
{
case 'download':
array_multisort($download, SORT_DESC, $download, $upload, $hosts, $active);
break;
case 'upload':
array_multisort($upload, SORT_DESC, $upload, $download, $hosts, $active);
break;
case 'host':
array_multisort($hosts, SORT_ASC, $hosts, $download, $upload, $active);
break;
}
print '<P><TABLE cellpadding="3" align="center"><TR><TD>';
//upload *********************************
$sum_upload = array_sum($upload);
print '<TABLE cellpadding="0" class="tables" ALIGN="right">';
print '<TR><TD colspan="2" align="center"><B>Upload</B></TD></TR>';
foreach ($upload as $idx => $data)
{
list($number, $unit) = setunits($upload[$idx]);
$d = round($upload[$idx]*200/$maks);
print '<TR>';
print '<TD align="right" nowrap> '.($active[$idx] ? '<B>' : '').($hosts_names ? $hosts[$idx] : long2ip($hosts[$idx])).($active[$idx] ? '</B>' : '').' </TD>';
print '<TD><IMG src="images/bluepx.gif" height="12" width="'.($d ? $d : '1').'" align="absmiddle" alt="" border="1"> ';
printf('%0.2f %s (%0.1f%%)</TD>', $number, $unit, ($upload[$idx]*100/$sum_upload));
print '</TR>';
}
$sum = setunits($sum_upload);
print '<TR><TD colspan="2" align="center"><B>RAZEM: '.sprintf('%0.2f',$sum[0]).' '.$sum[1].'</B></TD></TR>';
print '</TABLE>';
print '</TD><TD>';
//download *******************************
$sum_download = array_sum($download);
print '<TABLE cellpadding="0" class="tables" align="center">';
print '<TR><TD colspan="2" align="center"><B>Download</B></TD></TR>';
foreach ($download as $idx => $data)
{
list($number, $unit) = setunits($download[$idx]);
$d = round($download[$idx]*200/$maks);
print '<TR>';
print '<TD align="right" nowrap> '.($active[$idx] ? '<B>' : '').($hosts_names ? $hosts[$idx] : long2ip($hosts[$idx])).($active[$idx] ? '</B>' : '').' </TD>';
print '<TD><IMG src="images/redpx.gif" height="12" width="'.($d ? $d : '1').'" alt="" align="absmiddle" border="1"> ';
printf('%0.2f %s (%0.1f%%)</TD>', $number, $unit, ($download[$idx]*100/$sum_download));
print '</TR>';
}
$sum = setunits($sum_download);
print '<TR><TD colspan="2" align="center"><B>RAZEM: '.sprintf('%0.2f',$sum[0]).' '.$sum[1].'</B></TD></TR>';
print '</TABLE>';
print '</TD></TR><TR><TD colspan="2" align="center" class="footer"><P>'.$footer.'</P></TD></TR></TABLE>';
?>
co z tym jest nie tak na starym NND mi dzialaly a na nowym nie jest to najnowsze NND z 2006 r.
mam zainstalowane apache i php statystyki mam w katacogu /var/www/stats