%PDF- %PDF-
Direktori : /home/waritko/ |
Current File : //home/waritko/nfstat.php |
<?php function fsize($size) { $jedn = array("bytes", "Kbytes", "Mbytes", "Gbytes", "Tbytes", "Pbytes"); //$size = filesize($name); $i = 0; while($size > 1023) { $size /= 1024; $i++; } return sprintf("%0.2f %s", $size, $jedn[$i]); } $f = popen("tail /var/log/messages -n 500000 | grep nfcapd | tail -n 150 | tac", "r"); $out = array(); while(!feof($f)) { $line = fgets($f); if(preg_match_all("/(.*?) Ident: '(.*?)' Flows: ([0-9]+), Packets: ([0-9]+), Bytes: ([0-9]+), Sequence Errors: ([0-9]+), Bad Packets: ([0-9]+)/", $line, $matches)) { $ident = $matches[2][0]; $beg = $matches[1][0]; $flows = number_format($matches[3][0], 0, '.', ' '); $packets = number_format($matches[4][0], 0, '.', ' '); $pps = number_format($matches[4][0]/300, 0, '.', ' '); $bytes = fsize($matches[5][0]); $sqerr = number_format($matches[6][0], 0, '.', ' '); $bp = number_format($matches[7][0], 0, '.', ' '); if($ident == "lo") { $pps = number_format($matches[4][0]/3600, 0, '.', ' '); $out[] = "<span style=\"background-color: #6BBAB0;\">$beg Ident: '$ident' Flows: <b>$flows</b>, Packets: <b>$packets</b> (approx <b>$pps</b> pps), Bytes: <b>$bytes</b>, Sequence Errors: <b>$sqerr</b>, Bad Packets: <b>$bp</b></span>"; } elseif($ident == "devbox") { $pps = number_format($matches[4][0]/3600, 0, '.', ' '); $out[] = "<span style=\"background-color: #6699FF;\">$beg Ident: '$ident' Flows: <b>$flows</b>, Packets: <b>$packets</b> (approx <b>$pps</b> pps), Bytes: <b>$bytes</b>, Sequence Errors: <b>$sqerr</b>, Bad Packets: <b>$bp</b></span>"; } elseif($ident == "arjen") { $pps = number_format($matches[4][0]/3600, 0, '.', ' '); $out[] = "<span style=\"background-color: #76f3fc;\">$beg Ident: '$ident' Flows: <b>$flows</b>, Packets: <b>$packets</b> (approx <b>$pps</b> pps), Bytes: <b>$bytes</b>, Sequence Errors: <b>$sqerr</b>, Bad Packets: <b>$bp</b></span>"; } elseif($ident == "ludek") { $pps = number_format($matches[4][0]/3600, 0, '.', ' '); $out[] = "<span style=\"background-color: #f3fc76;\">$beg Ident: '$ident' Flows: <b>$flows</b>, Packets: <b>$packets</b> (approx <b>$pps</b> pps), Bytes: <b>$bytes</b>, Sequence Errors: <b>$sqerr</b>, Bad Packets: <b>$bp</b></span>"; } else { $out[] = "<span style=\"background-color: #AC89D8;\">$beg Ident: '$ident' Flows: <b>$flows</b>, Packets: <b>$packets</b> (approx <b>$pps</b> pps), Bytes: <b>$bytes</b>, Sequence Errors: <b>$sqerr</b>, Bad Packets: <b>$bp</b></span>"; } } /*else { $out[] = trim($line); }*/ } pclose($f); ?> <!DOCTYPE html> <html> <head> <title>NFcapD stats</title> <META HTTP-EQUIV="Refresh" CONTENT="300"> <META HTTP-EQUIV="Cache-Control" content="no-cache"> <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> </head> <body> <?php foreach($out as $o) { echo $o."<br>\n"; } ?> </body> </html>