---
title: "[zz]Troubleshooting Memory Usage"
author: "iunknown"
date: "2010-01-13T21:05:34Z"
tags: []
categories: ["编程语言"]
slug: "zz-troubleshooting-memory-usage"
draft: false
lastmod: "2010-01-13T21:05:34Z"
id: 569595
url: "https://iunknown.iteye.com/blog/569595"
---

<http://rimuhosting.com/howto/memory.jsp>


```

# create a memmon.sh script that tracks the current date, memory usage and running processes
cat << EOF > /root/memmon.sh
#!/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

chmod +x /root/memmon.sh

# create a cronjob that runs every few minutes to log the memory usage
echo '0-59/10 * * * * root /root/memmon.sh >> /root/memmon.txt' > /etc/cron.d/memmon
/etc/init.d/cron* restart 

# create a logrotate entry so the log file does not get too large
echo '/root/memmon.txt {}' > /etc/logrotate.d/memmon


```