Using the top command to display information
The top command and the program htop can help you view the currently running processes on your server. It’s useful for finding scripts or programs that might be running on your server and also useful if your server is experiencing issues like slow webpage loading or other resource issues. Top is installed by default but htop is a separate program which needs to be installed. We will detail how to install htop later on.
Top has a range of shortcuts that display the information in different orders. Consult the table below for the different shortcuts available.
The most common shortcut is top -c and nine times out of ten if you are having trouble with a server by using this shortcut you can determine what the problems is and then decide on the best way forward.
There is a lot of information listed on the top screen and we are going to point out the basics when using the top -c shortcut. Below is a screenshot from one of our KVM NVMe hosts. It’s powering a range of VPS servers for our customers from Windows servers and desktops to Ubuntu and CentOS servers.
From the information we can see;
- The Uptime of the host. This one has been online for 163 days.
- The server load in 1 minute, 5 minute and 15-minute intervals.
- This is how much of your CPU power is currently not being used.
- The wait time. This is how long a process has to wait before being finished.
- CPU Usage. The percentage of the total CPU you are using.
- Memory usage, how much physical memory, swap and cache you are using and have free. You can use free -m for memory usage.
Below this information, you can see the currently running processes and containers on the server. As this is KVM we do not see what individual processes are being run. We simply see the container mounted and resource usage. For a more detailed explanation on top and the full range of commands you can check the manual under man top.
Installing And Using Htop
Htop is much the same as top but the information is displayed in a more graphical way. if you want to use htop then first you will need to install htop;
Install htop on CentOS 7 or CentOS 8
CentOS 8 yum install epel-release dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm yum install htop CentOS 7 yum install epel-release yum install htop
To install htop on Ubuntu or debian
apt-get install htop
Once installed issue the htop command and you will be presented with the htop screen.
How was this article?