Top 5 System Monitoring Tools on Linux

System Monitoring is a routine task for a system administrator. As a system administrator, you’ll need the ability to find out what is happening on your system at any time. Whether it is the percent of CPU uses, Percent of Memory uses. What process consuming more or less memory or CPU, how many users and who logged in your system etc. System monitoring play very important role when a program malfunction.

When a performance issue arises, there are 4 main areas to consider: CPU, Memory, Disk I/O, and Network. The ability to determine where the bottleneck is can save you a lot of time. In the case of shared hosting, there are lots of users uses lots of services i.e Webservice(Apache), Nginx, PHP, Mysql, mail etc. And individual users uses the system resources. It will help you to know and determine whether your system needs any upgrades. Or if some services need to be moved to another machine.

For each Linux distribution, there are various open source system monitoring program that can help you. Here I describe top 5 System monitoring tools for you these are:

  1. The top command.
  2. The iostat Command
  3. The ps command
  4. The vmstat command
  5. The lsof command

Top 5 System Monitoring Tools

 1) The top command.

The most common of these commands is top. The top will display a continually updating report of system resource usage.

# top

 

System Monitoring

The top portion of the report lists information such as the system time, server uptime, CPU usage, physical and swap memory usage and the number of processes. Below that is a list of the processes sorted by CPU utilisation.

You can modify the output of top while is running. If you hit an i, top will no longer display idle processes. Hit i again to see them again. Hitting M will sort by memory usage, S will sort by how long they processes have been running, and P will sort by CPU usage again.

In addition to viewing options, you can also modify processes from within the top command. You can use u to view processes owned by a specific user, k to kill processes, and r to renice them.

2) The iostat Command:

The iostat will display the current CPU load average and disk I/O information. This is a great command to monitor your disk I/O usage. The iostat create reports that can be used to change system configuration to better balance the input/output between physical disks. By default, iostat command is not installed on your Linux distributions. you need to install it before use.

Installing iostat 

Note: iostat command is included in sysstat package

To install iostat on RHEL ( RedHat / CentOS / Fedora )

# yum install sysstat

To install iostat on Debian ( Debian / Ubuntu / Lunux Mint )

$ sudo apt-get install sysstat

How to use iostat command

# iostat

iostat-command

To see extend view of iostat use iostat -x

# iostat -x

iostat-x-command

By default iostat display report in bytes unit. If you want to see the report as kilobyte and megabyte, you can use -k and -m respectively.

# iostat -k

iostat-k-command

# iostat -m

iostat-m-command

Field Description :

The first section contains CPU report

  • %user : show the percentage of CPU utilisation that occurred while executing at the user (application) level
  • %nice : show the percentage of CPU utilisation that occurred while executing at the user level with nice priority
  • %system : show the percentage of CPU utilisation that occurred while executing at the system (kernel) level
  • %iowait : show the percentage of the time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request
  • %steal : show the percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual processor
  • %idle : show the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request

The second section contains device utilisation report

  • Device : device / partition name as listed in /dev directory
  • tps : show the number of transfers per second that were issued to the device. Higher tps means the processor is busier
  • Blk_read/s : show the amount of data read from the device expressed in a number of blocks (kilobytes, megabytes) per second
  • Blk_wrtn/s : show the amount of data written to the device expressed in a number of blocks (kilobytes, megabytes) per second
  • Blk_read : show the total number of blocks read
  • Blk_wrtn : show the total number of blocks written

3)The ps command

The ps will provide you report with a list of processes currently running. There is a wide variety of options that this command gives you. A common use would be to list all processes currently running. To do this you would use the ps −ef command. (Screen output from this command is too large to include, the following is only a partial output.)

# ps -ef

ps-ef-command

 The first column shows who owns the process. The second column is the process ID. The Third column is the parent process ID. This is the process that generated, or started the process. The fourth column is the CPU usage (in percent). The fifth column is the start time, of date if the process has been running long enough. The sixth column is the tty associated with the process, if applicable. The seventh column is the cumulative CPU usage (total amount of CPU time is has used while running). The eighth column is the command itself.

4)The vmstat command

The vmstat command will provide a report showing statistics for system processes, memory, swap, I/O, and the CPU. These statistics are generated using data from the last time the command was run to the present. In the case of the command never being run, the data will be from the last reboot until the present.

# vmstat

vmstat-command

FIELD DESCRIPTIONS

  • Procs
    r: The number of processes waiting for run time.
    b: The number of processes in uninterruptible sleep.
    w: The number of processes swapped out but otherwise runnable. This
    field is calculated, but Linux never desperation swaps.
  • Memory
    swpd: the amount of virtual memory used (kB).
    free: the amount of idle memory (kB).
    buff: the amount of memory used as buffers (kB).
  • Swap
    si: Amount of memory swapped in from disk (kB/s).
    so: Amount of memory swapped to disk (kB/s).
  • IO
    bi: Blocks sent to a block device (blocks/s).
    bo: Blocks received from a block device (blocks/s).
  • System
    in: The number of interrupts per second, including the clock.
    cs: The number of context switches per second.
  • CPU
    These are percentages of total CPU time.
    us: user time
    sy: system time
    id: idle time

5)The lsof command

The lsof command will print out a list of every file that is in use. Since Linux considers everything a file, this list can be very long. However, this command can be useful in diagnosing problems. An example of this is if you wish to unmount a filesystem, but you are being told that it is in use. You could use this command and grep for the name of the filesystem to see who is using it.

# lsof

lsof-command

Conclusion

With top command, we can view real-time process details. And iostat to monitor CPU usage and I/O system. Vmstat tells us memory uses in details. And ps to monitor each process information. And lsof tells all information to file. All together gives you empower to monitor every detail happens on your server and make right decision to handle any situation.

The following two tabs change content below.

Subroto Mondal

Chief Coordinator HR&CR
I like Programming and New Technologies. And work with Linux.

Latest posts by Subroto Mondal (see all)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.