Original address: Liang Guizhao’s blog
Blog address: blog.720ui.com
Welcome to reprint, reprint please indicate the author and source, thank you!
When performance problems occur, you can run Linux commands to obtain performance information. This section describes some common Linux performance monitoring commands.
The top command – Monitors process status
This command can be used to master the overall status of the operating system in real time and reflect the resource usage of each process in the system in real time, similar to the Task manager of Windows. You can run the top command to display process information.
# top
Copy the code
The upper part of the figure displays various information about the operating system, including CPU usage, memory usage, and process execution. The lower half shows the active processes in which you can look for clues to problems. After the suspicious process is identified, you can specify the related process and set the information update time to display the complete command. Let’s take a look at an example where you specify to display the resource usage of process 9836 every 5 seconds.
# top -- d 5 -- p 9836-c
Copy the code
Ps command – View the current process
This command is suitable for viewing the processes and their status at a certain moment. Using the ps command, you can check the status of the current process to find out the cause of the fault. You can run the ps command to display all current processes in the system.
# ps -ef
Copy the code
You can also specify which process to view. Let’s look at an example where all Java processes are viewed.
# ps ef | grep Java
Copy the code
The netstat command – Displays the network connection
This command is used to check the network status of the Linux system and is suitable for viewing network connection information. You can view all current connections.
# netstat -a
Copy the code
In addition, YOU can listen for TCP connections.
# netstat - atl
Copy the code
You can even count the number of current connections on a port. Let’s look at an example where we look at the current number of connections for port 10090.
# netstat -an | grep 10090 | wc -l
Copy the code
This command is used to monitor the I/O load of system devices and monitor disk operation activities. When the iostat command is run for the first time, the statistics of the system are displayed. After the iostat command is run, the statistics of the system are displayed since the last time. Users can obtain desired statistics by specifying the number and time of statistics. Let’s look at an example where the disk IO usage is sampled once per second, five times in a row.
# iostat –k 1 5
Copy the code
SAR command – Performance monitoring
This command is used to monitor CPU usage, idle CPU usage, disk I/O usage, and network adapter traffic usage. To monitor CPU usage, use the -u parameter to display CPU usage statistics. Let’s look at an example where we sample CPU usage once per second, 10 times in a row.
# SAR -- u 1 10
Copy the code
It is worth noting that if %user + %sys exceeds 85%, the process may spend time waiting in the run queue, so response time and throughput suffer. However, 100% utilization does not necessarily mean that the CPU is a performance bottleneck, and you can take a closer look at whether the r value in the vmstat command exceeds the number of cpus on the server. In addition, %system is large, indicating a lot of system administration time. Further analysis of other hardware and software factors is required. To monitor disk I/O status, use the -d parameter to output the activity information of each block device. Let’s look at an example where disk I/O usage is sampled once per second, 10 times in a row. The -p parameter displays the device name of the disk.
# SAR -- pd 1 10
Copy the code
If %util approaches 100%, there may be a disk bottleneck because the I/O system is overloaded due to too many I/O requests. Also, if %await is much larger than % SVCTM, the response time may be slow because the disk I/O queue is too long.
Vmstat command – Virtual memory monitoring
This command is used to monitor CPU usage, memory usage, virtual memory swapping, AND I/O reading and writing. Let’s look at an example where virtual memory usage is sampled once per second, five times in a row.
# vmstat 1 5
Copy the code
The first line shows the average value of the Linux operating system after startup, so you usually look at the value after the second line.
Among them, the values of SWPD, SI and SO are relatively high, which may be due to insufficient memory. If the cache usage is very low and the SI or SO of swap has a high value, be aware of memory performance problems. In addition, note that when the memory is severely insufficient, the system frequently uses paging and swapping, which increases the disk I/O load and further slows down the execution speed of the system’s jobs. That is, the system I/O resource problem affects the allocation of memory resources.
Nmon command – Performance Monitoring
Nmon displays all important performance information on one screen, including CPU information, memory information, network information, disk I/O information, and updates it dynamically. You can download it for free from the IBM website or install it directly through the yum command. Here, use wGET mode for download and installation.
# wget http://sourceforge.net/projects/nmon/files/nmon_linux_14i.tar.gz
# tar zxvf nmon_linux_14i.tar.gz
# chmod 777 nmon_x86_64_sles11
Copy the code
The installation is complete. Run the following command to start the system.
# ./nmon_x86_64_sles11
Copy the code
Enter C to display CPU information, M to display memory information, N to display network information, and D to display disk I/O information.
(End, reprint please indicate the author and source.)
More wonderful articles, all in the “server-side thinking”!