Commands to troubleshoot your VPS

There are many ways to keep track of your VPS' Memory and CPU usage. If you start to notice that your VPS went from 60MB of memory usage a day to 250MB of memory usage a day, you should probably take a close look at what is going on behind the scenes.

The following describes various commands that help you pin point high memory usage and high CPU usage.

The following commands must be ran within a shell terminal. View the SSH article for further details.


The ‘top’ command allows you to view system tasks running in real-time. It provides a good summary of your system to quickly check if anything stands out that may be causing issues with your server. View the following man page for further details:

Top has a few shortcut keys that are available which changes how the information is displayed:

# Shortcut KeyDescription
t Displays summary information on and off.
m Displays memory information on and off.
A Sorts the display by top consumers of various system resources. Useful for quick identification of performance-hungry tasks on the system.
f Enters an interactive configuration screen for top. Helpful for setting up top for a specific task.
o Enables you to interactively select the ordering within top.
r Issues renice command.
k Issues kill command.
z Turns color/mono on and off.

Displaying the top ten processes

The following four commands display the top ten (10) processes that are using memory on your VPS:

[server]$ ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10
[server]$ ps -eo pcpu,pid,user,args | sort -r -k1 | less
[server]$ ps -eo pmem,pid,user,args | sort -k 1 -r | head -10
[server]$ ps -eo pmem,pid,user,args | sort -r -k1 | less

The following command shows USERNAME, CPU%, MEMORY%, and the number of processes running. Run this command on a single line:

[server]$ ps aux | awk '{cpu[$1]+=$3; mem[$1]+=$4; procs[$1]+=1} END { for (user in cpu){ print user,"cpu:",cpu[user],"mem:",mem[user],"proc:",procs[user] } }'

Displaying memory usage of a specific process

[server]$ top -b -n 1 | grep -i [EnterProcessName]
or by username:
[server]$ top -U [EnterUsername]

Displaying memory usage with /proc/meminfo

[server]$ ps aux --sort pmem

Use the following command to view memory usage over time (requires you to repeat the command or usage of a cron job):

[server]$ ps ev --pid=[EnterPID]

To display all currently running processes and detailed information, use the following command:

[server]$ ps -ef

and on most systems:

[server]$ ps -aux

You can find a memory leak by running:

[server]$ ps ev --pid=[HighestEnterPID]

iostat to view CPU usage, disk activity, and network filesystems

[server]$ iostat

See also