How to Monitor Your Server’s Memory Usage

One system resource that can quickly get away from you is memory. Every program needs memory, and some may take more than their fair share. Therefore, it is important to monitor memory usage to make sure your applications are behaving and also help you decide when it might be time to reallocate resources or even consider upgrading.

Two tools that can provide you with very useful memory information are “meminfo” and “free”. Meminfo is a file found in the /proc directory that has a number of important general memory values, including total memory used, total free memory, swap totals, active memory, kernel stack, and more. You can access it with the following command:

# cat /proc/meminfo

For a more basic overall summary of memory usage, free is an excellent tool. Simply type “free” from the command line. You can also use a variety of options to make it even more useful. For example, the “-m” option will display the information in megabytes, and the “-h” option will show a generally more human-readable output.

For example, typing “free -h” from the command line might show an output like this:

total used free shared buffers cached

Mem: 7.8G 7.5G 331M 0B 444M 1.6G

-/+ buffers/cache: 1.4G 2.4G

Swap: 8.4G 106M 8.3G

Both meminfo and free are installed by default on many Linux and Unix servers.