Common Linux System monitoring commands
Blog Category:
Record your common Linux system commands, easy to access later, found that memory is getting worse
Find the most CPU-consuming Java Thread PS command
Command: PS-MP pid-o thread,tid,time or PS-LFP pid
Results show:
The purpose of this command is to obtain some information about the thread that corresponds to a process. For example, if you want to analyze some of the running bottlenecks of a Java process, you can use this command to find the CPU time of all current thread, which is the last column here.
For example, a tid:30834 is found here, which takes up the most time.
Through the printf "%x\n" 30,834 first converted to 16 binary, continue to dump the current JVM process through the jstack command stack information. With the grep command, you can find the thread ID information corresponding to the 16-binary, and you'll soon be able to figure out where the most CPU-consuming code is going.
Simply explained below, Jstack this crossed information content:
Java code
- "dboserviceprocessor-4-thread-295" daemon prio= tid= 0x00002aab047a9800 nid= 0x7d9b waiting oncondition [ 0x0000000046f66000]
Nid: The corresponding Linux operating system, the TID, is the front conversion of 16 binary digits
Tid: This should be the only address location in the JVM's JMM memory specification, and if you use it to analyze some of the JVM's memory data in detail, I'm not up to that level, so let's put it down.
Top command
Command: TOP-HP PID
The results show:
And the previous effect, you can track and get the CPU-consuming threads in the specified process in real time. The previous method is used to extract the corresponding thread stack information.
Judging I/O bottlenecks
Mpstat command
Command: Mpstat-p all 1 1000
The results show:
Notice the%iowait in this column, the amount of time that the CPU spends waiting for I/O operations. This consistently high value can often be caused by an I/O bottleneck.
This parameter can be used to visually see if the current I/O operation has a bottleneck.
Iostat command
Command: iostat-m-X 1 1000
Also you can observe the corresponding CPU%iowait data, in addition to Iostat also provides some more detailed I/O state data, such as the more important is:
Avgqu-sz:the average queue Length of the requests that were issued to the device. (Disk queue request length, normal words 2,3 better.) Can be understood as the CPU's load)
Await:the average time (in milliseconds) for I/O requests issued to the device to be served. (Represents the total time of an I/O operation from wait to completion)
Both SVCTM and%util represent the time-to-CPU ratio for processing the I/O request. These two parameters are not the primary when determining whether the bottleneck is
r/s w/s and rmb/s wmb/s are some of the states that represent the I/O processed by the current system, which is what we often call TPS, the latter being throughput. This is also the evaluation of a system performance indicators
PID command
Command: Pidstat-p pid-u-d-t-w-h 1 1000
The results show:
A very practical command, can be based on the process of analyzing the corresponding performance data, including Cpu,i/o,ir, CS, etc., can be convenient for developers to more granular observation of the operating state of the system. But Pidstat appears to be in some newer versions of the 2.6 kernel, and needs to install the Sysstat package.
Under Ubuntu, you can install it via the sudo apt-get install Sysstat.
SAR command
Command: Sar-x PID 1 1000
SAR can also specify the corresponding PID, focus on a fixed number of parameters, not pidstat so powerful. I can't see the corresponding I/O, IR and other information.
The functions of the SAR can be covered by Mpstat, iostat and related functions.
Dstat command
Command: dstat-y--tcp 1 1000
Through the Dstat--tcp can be more convenient to see the current TCP of various states, do not need to see each time Netstat-nat
Other commands
NETSTAT-NATP: Check the corresponding network link, follow Recv-q, send-q, state.
Lsof-p pid: Find the corresponding PID file handle
Lsof-i: 80: Find out which process is consuming the corresponding port
Lsof/tmp/1.txt: Find out which process is consuming the corresponding file
Tcpdump/wireshark: Packet Capture analysis tool
A series of Java monitoring commands such as Jstat/jmap/jstack/jps
At last
If you want to do some performance tuning work, be sure to be good at using some tools to focus on the appropriate state. Through the Linux command you can be more convenient to observe the CPU, I/O, network and other relatively peripheral state, many times it has been able to solve most of the problems. Some operational state monitoring within the JVM requires a few unique tools for fine-grained observation.
Common Linux System monitoring commands