How to log memory errors
Sometimes a server’s regular memory usage is fine. But there are those times when the server will run out of memory (OOM). And when that happens you may lose trace of what caused the server to run out of memory. Today, we will show you how to log possible memorry errors and see what can cause a problem for your VPS or Dedicated Server.
You can set up a script that will regularly log your server’s memory usage. And if there is a problem you can check the logs to see what was running. This additional log can be used in combination with the defaul tserver logs.
Type in the following, to create the needed file:
cat << EOF > /root/memmon.sh
When the file is ready, use your favorite text editor – vi, nano – to enter the following content
#!/bin/bash
date;
uptime
free -m
vmstat 1 5
ps auxf –width=200
if which iptables 2>&1 > /dev/null; then
iptables -L | diff iptables_default – | awk ‘{print “IPTABLES: ” $0}’
iptables -L > iptables_default
else
echo “IPTABLES MISSING”
fi
dmesg | diff -u dmesg_default – | grep ‘^+’ | awk ‘{print “DMESG:” $0}’
dmesg > dmesg_default
EOF
Now, make this file executable with the following command:
chmod +x /root/memmon.sh
It’s time to set up a cron job, which will execute this file every few minutes to check for the memory usage.
echo ‘0-59/10 * * * * root /root/memmon.sh >> /root/memmon.txt’ > /etc/cron.d/memmon
Then, restart the cron service:
/etc/init.d/cron* restart
The last thing to do is to create a logrotate entry for the new script, to avoid the file getting too large and taking too much disk space:
echo ‘/root/memmon.txt {}’ > /etc/logrotate.d/memmon
Tags: dedicated servers, OOM, VPS




March 19th, 2010 at 12:57 pm
[...] very large amount of memory, which can slow down the overall server performance or lead to possible Out Of Memory (OOM) errors [...]