pfsense/pfsense — pull request #865 by phildd (2013-12-22 11:59:47+00:00)
Title: Avoid dashboard divide by zero errors

Today I was having trouble with a 256MB Alix 2.1-RELEASE system that had too many OpenVPN servers defined, and some trouble with RRD data and bandwidthd... It was running out of memory badly during boot (another story).
Anyway, one of the side-effects was getting this on the dashboard System Information widget, where %ages should be displayed:
Warning: Division by zero in /usr/local/www/includes/functions.inc.php on line 155
The console had showed some errors about "sysctl" - and it seems the system didn't have enough spare memory to fork the various underlying "sysctl" etc commands that gather the amount of system memory etc. So these were zero, resulting in divide by zero errors when trying to calculate percentages.
Some other people have reported this in the forum in the past, but I guess it only happens when there is other bigger trouble on a system! I thought it was worth handling the "zero divisor" cases, because that saves someone from chasing this little code issue when they really need to be looking elsewhere to fix their system.
I have made the version for this pull request against master, but the code easily applies to 2.1 branch also.