Monitoring Linux system performance every day is a daunting task for every system/network administrator. After 5 years of Linux system administrators in the IT industry, I found it's not easy to monitor and keep the system up and running, so I've summed up 8 very useful command-line tools for Linux/unix system administrators. These commands support all Linux systems and can be used not only to monitor the system, but also to identify the cause of performance problems. The 8 commands provided below are sufficient for you to select one of them for your scene.
1.top--linux Process Monitoring
The top command of Linux is a performance Monitor that many Linux system administrators often use to monitor system performance, and the top command displays all running real-time processes in a list and updates periodically. It shows CPU usage, memory usage, swap memory, cache size, buffer size, process PID, user, command, and so on. It also shows the high memory processes and CPU utilization that are running. It is useful for system administrators to use top for monitoring and to help administrators take the right steps if necessary. Let's take a look at the actual use of the top command!
- # Top
Top command More examples of use, you can read: Top command on Linux 12 use cases
2.vmstat--Virtual Memory Statistics
The Linux vmstat command is used to display virtual memory statistics, Kernerl threads, disks, system processes, I/O modules, interrupts, CPU activity, and so on. By default, you need to install a Sysstat package on a Linux system to use the Vmstat command. The command is used in the following format:
- # 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
For more examples of using the Vmstat command, read: Vmstat 6 use cases in Linux
3.lsof--to list open files
The lsof command, like many Linux/unix system commands, is used to display all open files and processes. These open files include disk files, network sockets, pipelines, devices, and processes. The main reason for using it is that when you unmount the file system, if there are any open files in the file system, the operation will usually fail, then through Lsof can find out which processes are in use, the most common format for this command is as follows:
- # 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
For more lsof instructions please read: The lsof command in Linux 10 use cases
4.tcpdump--Network Packet Analyzer
Tcpdump is the most widely used command line-the network packet Analyzer or packet sniffer program-to capture or filter TCP/IP packets received or transferred from a specific interface on the network. It also saves the captured package to a folder. Tcpdump can be used on 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 bytes
- 22:08:59.617628 IP tecmint.com.ssh > 115.113.134.3.static-mumbai.vsnl.net.in.28472:p 2,532,133,365:2,532,133,481 ( ) Ack 3561562349 win 9648
- 22:09:07.653466 IP tecmint.com.ssh > 115.113.134.3.static-mumbai.vsnl.net.in.28472:p 116:232 ($) Ack 1 win 9648
- 22:08:59.617916 IP 115.113.134.3.static-mumbai.vsnl.net.in.28472 > Tecmint.com.ssh:. Ack, Win 64347
For more tcpdump use cases, please read: The tcpdump command 12 use cases in Linux systems
5.netstat--Network Statistics
Netstat is a command-line tool for monitoring incoming and outgoing network packet information and interface information statistics. It is useful for system administrators to use it to monitor network performance and troubleshoot network-related issues.
- # 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
For more netstat use cases, please read: Netstat 20 use cases on Linux
6.htop--linux Process Monitoring
Htop is a more advanced interactive and real-time Linux process monitoring tool. This command is very similar to the top command, but it is more versatile, such as friendly user interface process management, shortcut keys, vertical and horizontal view processes, and more. Htop is a third-party plug-in tool that you need to install on a Linux system using the Yum Package management tool.
Htop Installation Instructions: Installing Htop in Linux (Linux process monitoring)
7.lotop--Monitoring Linux disk I/O
Lotop is similar to the top command and the Htop program, but it has statistical capabilities to monitor and display disk I/O in real time. This tool is useful for precise processes and for discovering high-usage read/write processes.
Loptop Installation Instructions: Installing Loptop in Linux
8.iostat--Input/Output statistics
Iostat is a very simple tool for collecting and displaying system input and output storage device statistics. This tool is typically used to track performance issues with storage devices, including devices, local disks, remote disks such as NFS.
- # Iostat
- Linux 2.6.18-238.9.1.el5 (tecmint.com) 09/13/2012
- 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
For more iostat use examples and instructions, read: The Iostat command on Linux 6 use cases
Ultra-Practical 8 Linux command line performance monitoring tools