Command Line Tools to Monitor Linux Performance

Command Line Tools to Monitor Linux Performance

Here, we are going to see some of the Command Line Tools to Monitor Linux Performance

1. Top – Linux Process Monitoring

Linux Top command is a performance monitoring program which is used frequently by many system administrators to monitor Linux performance and it is available under many Linux/Unix like operating systems. The top command used to dipslay all the running and active real-time processes in ordered list and updates it regularly. It display CPU usage, Memory usage, Swap Memory, Cache Size, Buffer Size, Process PID, User, Commands and much more. It also shows high memory and cpu utilization of a running processess. The top command is much userful for system administrator to monitor and take correct action when required. Let’s see top command in action.

# top

Top Command Example

 

Tasks: 136 total,   2 running, 133 sleeping,   0 stopped,   1 zombie
%Cpu(s):  7.1 us, 13.6 sy,  0.0 ni, 78.8 id,  0.2 wa,  0.0 hi,  0.2 si,  0.2 st
KiB Mem :  2041268 total,   172476 free,   951712 used,   917080 buff/cache
KiB Swap:  1048572 total,   466584 free,   581988 used.   977344 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 4669 phonics+  20   0  565040  33424  23076 S   6.3  1.6   0:00.19 /opt/cpanel/ea-php56/root/usr/bin/php-cgi
12795 root      20   0  178868  27704   1104 S   5.6  1.4   3:35.72 lfd - sleeping
 4674 root      20   0  179804  28172    856 R   1.7  1.4   0:00.05 lfd - (child) process tracking...
20951 nobody    20   0  216360  15624    580 S   1.7  0.8   1:32.72 /usr/sbin/httpd -k start
  992 cpanelc+  20   0   11900   4952   4228 S   0.7  0.2  10:39.70 /usr/local/cpanel/3rdparty/sbin/p0f -i any -u 
 4648 root      20   0  160096   2324   1632 R   0.7  0.1   0:00.08 top c
   11 root      20   0       0      0      0 S   0.3  0.0   7:07.28 [rcu_sched]
 4658 phonic    20   0  565040  33400  23060 S   0.3  1.6   0:00.19 /opt/cpanel/ea-php56/root/usr/bin/php-cgi
20953 nobody    20   0 1423132  30200   7748 S   0.3  1.5   0:05.53 /usr/sbin/httpd -k start
    1 root      20   0  125540   2640   1428 S   0.0  0.1   1:54.62 /usr/lib/systemd/systemd --switched-root
    2 root      20   0       0      0      0 S   0.0  0.0   0:00.01 [kthreadd]
    3 root      20   0       0      0      0 S   0.0  0.0   0:00.61 [ksoftirqd/0]
    5 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 [kworker/0:0H]
    7 root      rt   0       0      0      0 S   0.0  0.0   0:02.14 [migration/0]

2. VmStat – Virtual Memory Statistics

Linux VmStat command used to display statistics of virtual memory, kernerl threads, disks, system processes, I/O blocks, interrupts, CPU activity and much more. By default vmstat command is not available under Linux systems you need to install a package called sysstat that includes a vmstat program. The common usage of command format is.

# vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
r  b   swpd   free  inact active   si   so    bi    bo   in   cs us sy id wa st
1  0      0 810420  97380  70628    0    0   115     4   89   79  1  6 90  3  0

3. Lsof – List Open Files

Lsof command used in many Linux/Unix like system that is used to display list of all the open files and the processes. The open files included are disk files, network sockets, pipes, devices and processes. One of the main reason for using this command is when a disk cannot be unmounted and displays the error that files are being used or opened. With this commmand you can easily identify which files are in use. The most common format for this command is.

# lsof
COMMAND     PID      USER   FD      TYPE     DEVICE     SIZE       NODE NAME
init          1      root  cwd       DIR      104,2     4096          2 /
init          1      root  rtd       DIR      104,2     4096          2 /
init          1      root  txt       REG      104,2    38652   17710339 /sbin/init
init          1      root  mem       REG      104,2   129900     196453 /lib/ld-2.5.so
init          1      root  mem       REG      104,2  1693812     196454 /lib/libc-2.5.so
init          1      root  mem       REG      104,2    20668     196479 /lib/libdl-2.5.so
init          1      root  mem       REG      104,2   245376     196419 /lib/libsepol.so.1
init          1      root  mem       REG      104,2    93508     196431 /lib/libselinux.so.1
init          1      root   10u     FIFO       0,17                 953 /dev/initctl

 

4. Tcpdump – Network Packet Analyzer

Tcpdump one of the most widely used command-line network packet analyzer or packets sniffer program that is used capture or filter TCP/IP packets that received or transferred on a specific interface over a network. It also provides a option to save captured packages in a file for later analysis. tcpdump is almost available in all major Linux distributions.

# tcpdump -i eth0
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
22:08:59.617628 IP webhostingchennai.co.in.ssh > 123.15.56.85.static-webhostingchennai.co.in.28472: P 2532133365:2532133481(116) ack 3561562349 win 9648
22:09:07.653466 IP webhostingchennai.co.in.ssh > 123.15.56.85.static-webhostingchennai.co.in.28472: P 116:232(116) ack 1 win 9648

5. Netstat – Network Statistics

Netstat is a command line tool for monitoring incoming and outgoing network packets statistics as well as interface statistics. It is very useful tool for every system administrator to monitor network performance and troubleshoot network related problems.

# netstat -a | more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0 *:mysql                     *:*                         LISTEN
tcp        0      0 *:sunrpc                    *:*                         LISTEN
tcp        0      0 *:realm-rusd                *:*                         LISTEN
tcp        0      0 *:ftp                       *:*                         LISTEN
tcp        0      0 localhost.localdomain:ipp   *:*                         LISTEN
tcp        0      0 localhost.localdomain:smtp  *:*                         LISTEN
tcp        0      0 localhost.localdomain:smtp  localhost.localdomain:42709 TIME_WAIT
tcp        0      0 localhost.localdomain:smtp  localhost.localdomain:42710 TIME_WAIT
tcp        0      0 *:http                      *:*                         LISTEN
tcp        0      0 *:ssh                       *:*                         LISTEN
tcp        0      0 *:https                     *:*                         LISTEN

6. Htop – Linux Process Monitoring

Htop is a much advanced interactive and real time Linux process monitoring tool. This is much similar to Linux top command but it has some rich features like user friendly interface to manage process, shortcut keys, vertical and horizontal view of the processes and much more. Htop is a third party tool and doesn’t included in Linux systems, you need to install it using YUM package manager tool. For more information on installation read our article below.

# htop
Tools to Monitor Linux Performance

7. Iotop – Monitor Linux Disk I/O

Iotop is also much similar to top command and Htop program, but it has accounting function to monitor and display real time Disk I/O and processes. This tool is much useful for finding the exact process and high used disk read/writes of the processes.

# iotop

Tools to Monitor Linux Performance

8. Iostat – Input/Output Statistics

IoStat is simple tool that will collect and show system input and output storage device statistics. This tool is often used to trace storage device performance issues including devices, local disks, remote disks such as NFS.

# iostat
Linux 2.6.18-238.9.1.el5 (webhostingchennai.co.in)         07/16/2018
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
2.60    3.65    1.04    4.29    0.00   88.42
Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
cciss/c0d0       17.79       545.80       256.52  855159769  401914750
cciss/c0d0p1      0.00         0.00         0.00       5459       3518
cciss/c0d0p2     16.45       533.97       245.18  836631746  384153384
cciss/c0d0p3      0.63         5.58         3.97    8737650    6215544
cciss/c0d0p4      0.00         0.00         0.00          8          0
cciss/c0d0p5      0.63         3.79         5.03    5936778    7882528
cciss/c0d0p6      0.08         2.46         2.34    3847771    3659776

9. Psacct or Acct – Monitor User Activity

psacct or acct tools are very useful for monitoring each users activity on the system. Both daemons runs in the background and keeps a close watch on the overall activity of each user on the system and also what resources are being consumed by them.

These tools are very useful for system administrators to track each users activity like what they are doing, what commands they issued, how much resources are used by them, how long they are active on the system etc.

10. Monit – Linux Process and Services Monitoring

Monit is a free open source and web based process supervision utility that automatically monitors and managers system processes, programs, files, directories, permissions, checksums and filesystems.

It monitors services like Apache, MySQL, Mail, FTP, ProFTP, Nginx, SSH and so on. The system status can be viewed from the command line or using it own web interface.

[root@server ~]# monit
 New Monit id: 8dc7a69b24bb98fa5526c9ff92c1592d
 Stored in '/root/.monit.id'
Starting Monit 5.25.1 daemon with http interface at [localhost]:2812
[root@server ~]# monit status
Monit 5.25.1 uptime: 0m

System 'server.webhostingchennai.co.in'
  status                       OK
  monitoring status            Monitored
  monitoring mode              active
  on reboot                    start
  load average                 [0.08] [0.20] [0.19]
  cpu                          0.0%us 0.0%sy 0.0%wa
  memory usage                 109.1 MB [11.0%]
  swap usage                   0 B [0.0%]
  uptime                       18h 14m
  boot time                    Mon, 16 Jul 2018 13:49:47
  data collected               Tue, 17 Jul 2018 08:04:07

[root@server ~]#

Installing Monit:

rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install monit
(1/2): epel/x86_64/updateinfo  | 927 kB  00:00:03
(2/2): epel/x86_64/primary     | 3.5 MB  00:00:08
epel                             12611/12611
Resolving Dependencies
--> Running transaction check
---> Package monit.x86_64 0:5.25.1-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================
 Package            Arch      Version       Repository  Size
===============================================================
Installing:
 monit              x86_64    5.25.1-1.el7  epel       318 k

Transaction Summary
================================================================
Install  1 Package

Total download size: 318 k
Installed size: 818 k
Downloading packages:
monit-5.25.1-1.el7.x86_64.rpm             | 318 kB  00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : monit-5.25.1-1.el7.x86_64                 1/1
  Verifying  : monit-5.25.1-1.el7.x86_64                 1/1

Installed:

Installing web interface of Monit refer here

11. NetHogs – Monitor Per Process Network Bandwidth

NetHogs is an open source nice small program (similar to Linux top command) that keeps a tab on each process network activity on your system. It also keeps a track of real time network traffic bandwidth used by each program or application.

NetHogs version 0.8.5

    PID USER     PROGRAM                                     DEV        SENT      RECEIVED
      ? root     123.147.51.48:36750-208.74.121.35:80                  0.000       3.742 KB/sec
      ? root     123.147.51.48:58117-70.87.220.252:80                  0.000       3.461 KB/sec
      ? root     123.147.51.48:38556-208.74.123.62:80                  0.000       3.461 KB/sec
      ? root     123.147.51.48:34343-185.78.221.90:80                  0.000       3.461 KB/sec
      ? root     123.147.51.48:44420-208.74.121.39:80                  0.000       3.449 KB/sec
      ? root     123.147.51.48:49612-103.252.152.1:80                  0.000       3.449 KB/sec
      ? root     123.147.51.48:45364-122.201.72.171:80                 0.000       3.448 KB/sec
      ? root     123.147.51.48:57572-208.74.123.61:80                  0.000       3.018 KB/sec
      ? root     123.147.51.48:59418-209.85.80.214:80                  0.000       2.738 KB/sec
      ? root     123.147.51.48:38047-67.222.0.10:80                    0.000       1.949 KB/sec
      ? root     123.147.51.48:56937-208.100.0.204:80                  0.000       1.566 KB/sec
      ? root     123.147.51.48:38505-216.14.113.158:80                 0.000       1.018 KB/sec
      ? root     123.147.51.48:37151-72.29.88.74:80                    0.000       0.855 KB/sec

 

Installing NetHogs:

yum -y install nethogs

Resolving Dependencies
--> Running transaction check
---> Package nethogs.x86_64 0:0.8.5-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================
 Package              Arch       Version      Repository    Size
===================================================================
Installing:
 nethogs             x86_64     0.8.5-1.el7   epel          38 k

Transaction Summary
===================================================================
Downloading packages:
nethogs-0.8.5-1.el7.x86_64.rpm              |  38 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : nethogs-0.8.5-1.el7.x86_64    1/1
  Verifying  : nethogs-0.8.5-1.el7.x86_64    1/1

Installed:
  nethogs.x86_64 0:0.8.5-1.el7

12. iftop – Network Bandwidth Monitoring

iftop is another terminal-based free open source system monitoring utility that displays a frequently updated list of network bandwidth utilization (source and destination hosts) that passing through the network interface on your system. iftop is considered for network usage, what ‘top‘ does for CPU usage. iftop is a ‘top‘ family tool that monitor a selected interface and displays a current bandwidth usage between two hosts.

13. Monitorix – System and Network Monitoring

Monitorix is a free lightweight utility that is designed to run and monitor system and network resources as many as possible in Linux/Unix servers. It has a built in HTTP web server that regularly collects system and network information and display them in graphs. It Monitors system load average and usage, memory allocation, disk driver health, system services, network ports, mail statistics (Sendmail, Postfix, Dovecot, etc), MySQL statistics and many more. It designed to monitor overall system performance and helps in detecting failures, bottlenecks, abnormal activities etc.

Tools to Monitor Linux Performance

 

For installing Monitorix refer here

14. Arpwatch – Ethernet Activity Monitor

Arpwatch is a kind of program that is designed to monitor Address Resolution (MAC and IP address changes) of Ethernet network traffic on a Linux network. It continuously keeps watch on Ethernet traffic and produces a log of IP and MAC address pair changes along with a timestamps on a network. It also has a feature to send an email alerts to administrator, when a pairing added or changes. It is very useful in detecting ARP spoofing on a network.

 

15. VnStat PHP – Monitoring Network Bandwidth

VnStat PHP a web based frontend application for most popular networking tool called “vnstat“. VnStat PHP monitors a network traffic usage in nicely graphical mode. It displays a total IN and OUT network traffic usage in hourly, daily, monthly and full summary report.

 

For installing VnStat refer here

16. Nagios – Network/Server Monitoring

Nagios is an leading open source powerful monitoring system that enables network/system administrators to identify and resolve server related problems before they affect major business processes. With the Nagios system, administrators can able to monitor remote Linux, Windows, Switches, Routers and Printers on a single window. It shows critical warnings and indicates if something went wrong in your network/server which indirectly helps you to begin remediation processes before they occur.

For installing Nagios refer here 

 

You may also like...