Learn linux system monitoring tools 1. Learn linux
Make full use of the built-in linux system monitoring tools to quickly and conveniently understand the system performance and other issues, so as to facilitate system analysis and debugging.
Learning articles: Every system administrator needs to know 30 Linux system monitoring tools and learn CPU and process performance monitoring through vmstat.
[1] top-monitoring process commands
Commandtop
Real-time Monitoring Chart
1. Understandingtop
top
(Different systems may have different names, such as IBM aixtopas
) Command to display the system processes and provide a real-time dynamic view (that is, real-time monitoring of Process activities). By default,top
The command displays the processes with the highest CPU usage and updates each 5S.
2. Main Functions
It is mainly used to monitor the Real-Time Load Rate of the system, the resource usage rate of processes, and whether other system status attributes are normal.
3. View Process Monitoring
Terminal input commandtop
Output Recognition
- Line 1: displays system-level load. The average load has three outputs, representing the average load in the past 1, 5, and 15 minutes. The output of this part is consistent with the command uptime.
- Row 2: displays general information about processes, such as the current total number of processes, the number of running or sleep processes. In the process list
S
The column value isR
Representativerunning
, IfS
Issleeping
.
- Row 3: Display
cpu
Some load information, especially%id
And%wa
These two indicators are particularly important.%id
Too low,%wa
Very low.cpu
The usage is very high and there may be somesql
The statement consumes a lotcpu
Resource, if%wa
If it is very high, it is likely that the system IO has a problem.
- Row 4: displays the memory usage. If the memory usage is abnormal, you can find it in the highlighted process information.
%MEM
Processes that consume a relatively high level.
- The fifth line shows the swap area. If the memory is sufficient or the system load is not high, there is no big change in the data in this part.
Notte: Parameter description of CPU status information
% Cpu (s): 9.5 us, 4.2 sy, 0.0 ni, 74.5 id, 11.7 wa, 0.0 hi, 0.1 si, 0.0 st
4. Common shortcut keys
Deepintop
Commandz
Shortcut Key black/white switch mode
Shortcut Key Usage
- T: whether to display summary information
- M: whether to Display memory information
- A: sorting processes based on the utilization of various system resources helps to quickly identify tasks with poor system performance.
- B: enable or disable the bold display of important numbers in the table.
- C: enter directly
top -c
Or (entertop
And then enter the shortcut keyc
The command name of the display process or the input information of the completed command line will be switched.
- F: Enter the top interactive configuration screen to set top Display Based on specific requirements.
- O: If you want to customize the display
top
Command output order.pid
,user
To display process information, if you wantuser
,pid
To display, you can usec
Shortcut Key. Inputtop
And then entero
, An interactive interface is displayed. If you want to display the column USER first, enterE
And then press Enter. The result is rearranged.
- R: renice)
- K: kill A Process)
- Z: Switch the color or black/white Mode
[2] vmstat-Virtual Memory statistics
1. Understandingvmstat
vmstat [options] [delay [count]]
vmstat
Commands are the most common Linux/Unix monitoring tool. They can display the status values of servers at a given interval, including CPU usage, memory usage, virtual memory switching, and IO read/write.
vmstat
Commandman
Page
2. Main Functions
The vmstat Command reports information about processes, memory, paging, block IO, interruptions, and CPU activity.
3. view memory statistics
vmstat
Monitoring
Note: Parameter description
Procs ---- memory -----swap--- io ---system--- cpu --
Procs
R B swpd free buff cache si so bi bo in cs us sy id wa st
1.r
: Number of kernel threads (number of processes) in the running queue. This value can also determine whether to increase the CPU. (Longer than 1)
2.b
: Number of kernel threads placed in the waiting queue (waiting for resources, waiting for input/output); Number of non-interrupted processes in the block queue
Memory
3.swpd
: Available virtual swap memory, ifswpd
The value is not 0,SI
,SO
The long-term value is 0, which does not affect the system performance.
4.free
: Idle physical memory size
5.buff
: Memory size used as a buffer
6.cache
: The cache memory size. Ifcache
Description when the value is largecache
The number of files is large, and files that are frequently accessed can becache
The disk read IO bi will be very small.
Swap
7.si
: Number of swap pages from disk to memory (Unit/S)
8.so
: Number of swap pages (Unit/S) from swap memory to disk)
IO
9.bi
: Number of blocks received by the block device (Block/second)
10.bo
: Number of blocks sent to block devices (Block/second)
System
11.in
: Number of interrupts per second, including clock interruptions
12.cs
: Number of context switches per second
CPU
13.us
: Percentage of CPU consumed by all processes in user mode. When the us value is relatively high, it indicates that the CPU time consumed by the process user State is too large. If the CPU time exceeds 50% for a long time, you need to consider optimizing the application.
14.sy
: Percentage of kernel system process execution time (system time ).sy
When the value is high, it indicates that the CPU time consumed by the process kernel state is too large; ifus+sy
Exceeds80%
CPU resources are insufficient.
15.id
: Percentage of idle CPU time
16.wa
: IO wait time percentage
17.st
: CPU usage percentage of virtual machines. Ifwa
The value exceeds20%
, DescriptionIO
The wait is serious.st
Only in Linuxvmstat
Show
4. options)
Option usage instructions
- A: displays active and inactive pages.
- F: displays the total number of processes created after startup.
- M: Display
slab
Information
- N: The header information is only displayed once.
- S: display the event counters and memory status in a table
- D: Displays disk statistics.
- P: displays statistics of specified disk partitions.
- S: The unit of output information. Parameters include k, K, m, and M, representing 1000, 1024, 1000000, and 1048576 bytes respectively ). The default unit is K (1024 bytes)
- V: Display
vmstat
Version information.
5. Parameters
- Delay: refresh interval. If this parameter is not specified, only one result is displayed.
- Count: Number of refreshes. If you do not specify the number of refreshes, but specify the interval, the number of refreshes is infinite.
6. Use instances
Instance 1: Averagevmstat
Two numeric parameters are used. The first parameter is the number of sampling intervals, in seconds, and the second parameter is the number of samples,
vmstat 2 1
In fact, in the application process, we often get used to monitoring for a period of time and don't want to directly end monitoring.vmstat
Instance 2: Displays active and inactive memory.
vmstat -a 2 3
Use-a
When the option shows active and inactive memory, the displayed content is increased.inact
Andactive
.
Field supplementary description
Memory (Memory ):
Inact: inactive memory size (when used-a
Option)
Active: active memory size (when used-a
Option)
Instance 3: View how many times the system has fork
vmstat -f
View comments