How to use top to monitor server performance
What is Top
top shows load, CPU, memory and per-process usage in real time, and can signal a process from the same screen. The top command syntax is as noted below for your reference.
usage: top -hv | -abcHimMsS -d delay -n iterations [-u user | -U user] -p pid [,pid ...]
#1 Row One
Four fields of information are available in the first row output, which are current system time, system up-time, logged in users and the server load average.
#2 Row Two
This row will give you an idea on the process information from server, which are total number of processes and number of processes based on the process states such as Running processes, Sleeping processes, Stopped processes and Zombie processes.
Running : Running or runnable processes, or the processes waiting for the CPU to process it.
Sleeping : Interruptible sleep, processes waiting for an event to complete like an input or output from another process.
Stopped : Process that has been suspended/stopped
Zombie : Processes which are already dead but it has a an entry in the process table of the parent process. This can happen when the parent process die before clearing the process tables and the child process turnout to be orphan.
#3 Row Three
This row contains the information about the CPU usage in system, which provide you % CPU utilization for User processes (us), System processes (sy), Processes with Nice value (ni), Idle processes (id), Waiting for I/O (wa), Hardware Interrupts (hi), Software Interrupts (si), Steal Time (st)
#4 Row Four and Five
The fourth and fifth row describe memory information on RAM and SWAP respectively. Total assigned, used, free and buffer usage from RAM share and total, used, free and cached from assigned SWAP.
#5 Row Six
The next block of information describes more on the running processes and their individual details like the PID, ownership (USER), running priority (PR), nice value (NI), virtual (VIRT), reserver (RES), shared (SHR) memory used by the process, process status (s), CPU used by the process, RAM (MEM) used by the process, the running time of the process (TIME) and the command line expansion of the process (COMMAND).
Top Command Tips
We are going to discuss some of the flags that can be used with top command which can help you work and manipulate the output more efficiently.
#1 Sort options
You can use the key combination Shift+o or Shift+f to reach the sort option of top command.
Press the key corresponding to the criteria which you would like to get the top output sorted and press Enter.
#2 Decreasing output frequency (-d)
top is programmed to output the details in an interval of every 3 seconds, however using top in such a frequency for a system affected with high CPU load can again increase the server load. Similarly, if you are monitoring a system for a process which exist for a very short duration, the 3 seconds frequency will be high and possibly the process will not be shown in top output. The -d flag can be used with top to specify the refresh frequency of outputs such as,
top -d1 ,for one second iteration of results
top -d5 ,for five second iteration of results etc.
You can press the d key on a running top screen to adjust the delay.
#3 Color Marking Running Processes
The z key can be used in an opened top screen to get the running process for easy identification.
#4 Listing processes owned by a specific user (-u)
Trigger top command using the -u flag to get the listing only for that specific user.
Top -u <username>
You can press the u key on a running top screen to get listing for a specific user.
#5 Killing specific PIDs (k)
You can press the k key on a running top screen which will ask you to enter the process ID of specific process that you want to terminate and then it will ask you the signal that you want to use for process termination, by default it will be 15 SIGTERM, you can use 9 SIGKILL
From the EuroVPS FAQ.
More in how toYour next infrastructure partner
Still have
a question?
Tell us what you are trying to do. An engineer will read it and reply.
+357 222 32280
who will look after your infrastructure.
Let’s start with your setup.
A little context helps us start the right conversation.
