Web Hosting Talk







View Full Version : phpsysinfo script problem


Eiv
09-07-2001, 03:53 AM
I have recently upload this script onto my server : http://phpsysinfo.sourceforge.net/phpsysinfo/.

It is a great script. However for some reason the "Network Usage"(bandwidth monitor) reset very often and I keep losing track on how much incoming & outgoing on my box. Anyone has a solution??

Thanks in advance.

eva2000
09-07-2001, 05:58 AM
same happens with mine.. don't know why though

RutRow
09-07-2001, 08:29 AM
Here is the function they use to grab network device information:


function sys_netdevs ()
{
$results = array();

if ($fd = fopen('/proc/net/dev', 'r')) {
while ($buf = fgets($fd, 4096)) {
if (preg_match('/:/', $buf)) {
list($dev_name, $stats_list) = preg_split('/:/', $buf, 2);
$stats = preg_split('/\s+/', trim($stats_list));
$results[$dev_name] = array();

$results[$dev_name]['rx_bytes'] = $stats[0];
$results[$dev_name]['rx_packets'] = $stats[1];
$results[$dev_name]['rx_errs'] = $stats[2];
$results[$dev_name]['rx_drop'] = $stats[3];

$results[$dev_name]['tx_bytes'] = $stats[8];
$results[$dev_name]['tx_packets'] = $stats[9];
$results[$dev_name]['tx_errs'] = $stats[10];
$results[$dev_name]['tx_drop'] = $stats[11];

$results[$dev_name]['errs'] = $stats[2] + $stats[10];
$results[$dev_name]['drop'] = $stats[3] + $stats[11];
}
}
}
return $results;
}


I believe the problem is that the counters in /proc/net/dev roll over at a certain point. I am not sure what that point is, though. I would suggest using MRTG for accurate bandwidth monitoring.