How to Use Top for Debugging Your Linux Server

How to Use Top for Debugging Your Linux Server

What Do I Need?

  • A Dedicated or VPS Linux Server
  • CentOS

What is Debugging?

Every now and again you’re going to need to do some troubleshooting and that will sometimes mean some debugging is needed too. Any server can suffer from hardware, software, and connectivity problems.

  1. Check the Hardware
  1. If you have access to the physical hardware you should have all of the cable connections, internally and externally checked.
  2. Check your ethernet hardware connection:
sudo ethtool eth0

  1. Check your bios/uefi hardware, including memory:
sudo dmidecode --type memory

  1. If the information summary looks correct, but you still suspect a memory problem, it’s time to deploy an additional tool, Memtest86. If you’re running into numerous memory problems, you should check the edac_core module:
sudo modprobe edac_core

  1. After a moment you should then check the following:
sudo grep “[0-9]”
/sys/devices/system/edac/mc/mc*/csrow*/ch*_ce_count

  1. Define your Problem
  1. Your web server has gone rogue; however, you can’t work out what’s happening. Before you attempt to deal with the end result, you need to lock down exactly what the problem is. For example, if your users are complaining about a problem with a server application, first make sure it’s not actually failing on the client’s side. Is the problem with the server or the application?
  2. To check if an application is running try the two following commands:
sudo ps -ef | grep apache2
sudo netstat -plunt | grep apache2

  1. If it’s shown that, for example, the Apache web server isn’t running, you can start it with the following command:
sudo service apache2 start

  1. Using Top
  1. Another super useful tool for systems debugging is Top. Use it to check load average, swap and which processes are using resources. Top shows all of a Linux server’s currently running processes.
  2. You’ll receive a wealth of useful troubleshooting information. To find the process consuming the most memory, sort the process list by pressing the ‘M’ key. To see which applications are using the CPU cycles, press ‘P’; and to sort by running time, press ‘T’. To see more easily which column you’re using for sorting, press the ‘B’ key. You can also interactively filter top’s results by pressing ‘O’, which displays the following prompt:
add filter #1 (ignoring case) as: [!]FLD?VAL

  1. You can then enter a search for a particular process, for example:
COMMAND=apache

  1. Check Hard Disk Space
  1. Running out of space on an active web server is remarkably easy nowadays considering the size of media uploads and various sharable content. To track down these kinds of issues use the following commands:
sudo df -h

This command presents data about your hard disk drives in a human-readable format; for example, it displays storage as gigabytes rather than the exact number of bytes.

sudo df -i

This command displays the number of used inodes and their percentage for the file system.

  1. You can use other useful optional flags, like ‘T’. This displays your storages file system types:
sudo df -hT

  1. For deeper analysis, you should use the iostat command. This command is part of the sysstat advanced system performance monitoring tools collection. It reports granular CPU and i/o statistics for block storage devices, partitions, and network file systems.
  1. The most useful version of this command displays the reads, writes, read kb and write kb per second to the device. It also shows you the average i/o in milliseconds in terms of wait times. The command is used in this way:
iostat -xz 1

Next Steps

Last but definitely not by any means least you should check the server logs. These can usually be found in /var/log in a subdirectory specific to the service itself. For the noob, log files can be indeed quite scary. But despite their innate cryptic nature, you can still learn your way around them. Time, patience, frequent Google searches and, of course, checking back here regularly for more awesome how-to guides is your recommended approach.

Conclusion

Maybe your servers will never attain all time longevity records. Perhaps they’ll never need to be restarted. However, fixing problems and ensuring that your servers are as stable as possible are worthwhile goals. With the concepts described above, you’re well on your way to being able to get started confidently debugging your systems.

How To Set up a VSFTPD Server on a CentOS 7 VPS or Dedicated Server

Brief Description FTP is usually insecure exposing clear-text passwords, userna
2 min read
Avi Ilinsky
Avi Ilinsky
Hosting Expert

How To Set up a VSFTPD Server on an Ubuntu 16.04 VPS or Dedicated Server

Brief Description FTP data is usually insecure since information (usernames, pa
2 min read
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

How to use phpMyAdmin to develop a website (without MySQL experience)

Brief description A web developer who is not well versed into coding websites f
2 min read
Idan Cohen
Idan Cohen
Marketing Expert

How to Install MySQL on a Windows Web Server Running Apache

This tutorial will show you how to install the MySQL database on a Windows serve
3 min read
Michael Levanduski
Michael Levanduski
Expert Hosting Writer & Tester
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top