I use loadavg to monitor memory, CPU and network usage on my VPS, just so I can get the bigger picture about what’s happening when I’m not about. However, with the introduction of SLM on my VPS I found that loadavg was reporting incorrect memory usage.
Looking through the PHP code for loadavg, I could see the commands that were being issued to get memory usage. I found this one:
cat /proc/user_beancounters
This was the command that outputted the incorrect RAM usage. It was always about 40 - 100 megabytes out. Far too much for my liking!
Later on in the script, there’s a call to /proc/meminfo if the information from the above code can’t be ascertained. This seemed to be giving the correct information. I worked out that a simple switch would be able to tell the scripts if SLM was enabled and if so, go straight to the latter piece of code and get the correct RAM usage.
Here are the changes you need to make in order to get loadavg working on an SLM based VPS.
Open config.php and add this underneath “Size of kilobyte”
// If you're on a virtuozzo VPS, you may have SLM enabled. $slm = TRUE;
Open logger.php and change
$beancounters = @shell_exec("/bin/beanc 2> /dev/null"); if (!$beancounters) { if (file_exists('/proc/user_beancounters')) { $beancounters = `cat /proc/user_beancounters 2> /dev/null`; } else { $ded=TRUE; } }
To
if($slm == TRUE) { $ded = TRUE; } else { $beancounters = @shell_exec("/bin/beanc 2> /dev/null"); if (!$beancounters) { if (file_exists('/proc/user_beancounters')) { $beancounters = `cat /proc/user_beancounters 2> /dev/null`; } else { $ded=TRUE; } } }
That’s you sorted. Re-upload the changed files, delete any existing logs and watch the difference in reported memory usage!