CPU, Disk, Network Monitoring Commands in Linux

1.top command
It is commonly used to monitor the system status of linux, and is a commonly used performance analysis tool, which can display the resource usage of each process in the system in real time.

You can use the top command to find out the threads that take up too much CPU in the JVM, find the corresponding thread code calls through jstack, and troubleshoot the problem code.
jstack is the abbreviation of java stack (java stack)

How to use top:
top [-d number] | top [-bnp]
Parameter explanation:
-d: number represents the number of seconds, which represents the interval at which the page displayed by the top command is updated once. The default is 5 seconds. -b: Execute top in batches.
-n: Used in conjunction with -b, it means that the output result of the top command needs to be performed several times. -p: Specify a specific pid process number to observe.
top -Hp 23344 H View thread information P stands for pid

The picture after use is as follows:

System information (first five lines):

Line 1: Top task queue information(System operating status and average load),and uptime The command results are the same. 
    Paragraph 1: The current time of the system, for example: 16:07:37
    Section 2: The system running time, the time it has not been restarted, the longer the time, the more stable the system. 
    Format: up xx days, HH:MM
    Example: 241 days, 20:11, Indicates that it has run continuously for 241 days, 20 hours and 11 minutes
    Paragraph 3: The number of currently logged in users, for example: 1 user,Indicates that only 1 user is currently logged in
    Section 4: System load, that is, the average length of the task queue, three values ​​​​respectively count the system average load in the last 1, 5, and 15 minutes 
    System Load Average: Single Core CPU case, 0.00 means no load, 1.00 It means just full load, more than 1 side means overload, the ideal value is 0.7;
    multicore CPU load: CPU Number of cores * ideal value 0.7 = Ideal load, eg: 4 cores CPU load no more than 2.8 Ho said there was no high load.
Line 2: Tasks Process related information 
    Paragraph 1: Total number of processes, for example: Tasks: 231 total, Indicates a total of 231 processes running
    Paragraph 2: Number of running processes, for example: 1 running,
    Paragraph 3: The number of sleeping processes, for example: 230 sleeping,
    Paragraph 4: Number of stopped processes, eg: 0 stopped,
    Paragraph 5: The number of zombie processes, for example: 0 zombie
 Line 3: Cpus CPU Relevant information, if multi-core CPU,Press the number 1 to display each core CPU information, at this point 1 line will be converted to Cpu In the nuclear count line, the number 1 can be switched back and forth. 
    Paragraph 1: us user space usage CPU percentage, for example: Cpu(s): 12.7%us,
    Paragraph 2: sy Kernel space usage CPU percentage, for example: 8.4%sy,
    Paragraph 3: ni Processes that have changed priorities in user process space occupy CPU percentage, for example: 0.0%ni,
    Paragraph 4: id idle CPU percentage, for example: 77.1%id,
    Paragraph 5: wa waiting for input CPU time percentage, for example: 0.0%wa,
    Paragraph 6: hi CPU The total amount of time spent servicing hardware interrupts, for example: 0.0%hi,
    Paragraph 7: si CPU The total amount of time spent servicing the soft interrupt, for example: 1.8%si,
    Paragraph 8: st Steal time virtual machine hypervisor stolen CPU time (if currently in a hypervisor down vm,Actually hypervisor also consume some CPU processing time)
Line 4: Mem Memory related information ( Mem: 12196436k total, 12056552k used, 139884k free, 64564k buffers) 
    Paragraph 1: Total amount of physical memory, for example: Mem: 12196436k total,
    Paragraph 2: The total amount of physical memory used, for example: 12056552 k used,
    Paragraph 3: Total amount of free memory, for example: Mem: 139884k free,
    Paragraph 4: Amount of memory to use as kernel cache, eg: 64564 k buffers
 Line 5: Swap Swap partition related information ( Swap: 2097144k total, 151016k used, 1946128k free, 3120236k cached) 
    Paragraph 1: Total amount of swap area, for example: Swap: 2097144k total,
    Paragraph 2: The total amount of swap area used, for example: 151016 k used,
    Section 3: The total amount of free swap area, for example: 1946128 k free,
    Paragraph 4: Total buffered swap area, 3120236 k cached

exist top press the command f Press to view the displayed column information, press the corresponding letter to open/Close the column, uppercase letters mean on, lowercase letters mean off. bring*No. is the default column.
(Data is by default CPU Sort by total)

A: PID = (Process Id) process Id;  (focus)
E: USER = (User Name) the username of the process owner;
H: PR = (Priority) priority
I: NI = (Nice value) nice value. Negative values ​​indicate high priority, positive values ​​indicate low priority
O: VIRT = (Virtual Image (kb)) The total amount of virtual memory used by the process, in units kb. VIRT=SWAP+RES  (focus)
Q: RES = (Resident size (kb)) The size of the physical memory used by the process but not swapped out, in units kb. RES=CODE+DATA
T: SHR = (Shared Mem size (kb)) Shared memory size, unit kb
W: S = (Process Status) Process status. D=uninterruptible sleep state,R=run,S=sleep,T=track/stop,Z=zombie process
K: %CPU = (CPU usage) last update to now CPU percentage of time (focus)
N: %MEM = (Memory usage (RES)) The percentage of physical memory used by the process  (focus)
M: TIME+ = (CPU Time, hundredths) used by the process CPU Total time, unit 1/100 Second 
b: PPID = (Parent Process Pid) parent process Id 
c: RUSER = (Real user name) 
d: UID = (User Id) user of the process owner id 
f: GROUP = (Group Name) The group name of the process owner 
g: TTY = (Controlling Tty) The name of the terminal from which the process was started. Processes not started from a terminal are displayed as ? 
j: P = (Last used cpu (SMP)) last used CPU,only in many CPU meaningful in context 
p: SWAP = (Swapped size (kb)) In the virtual memory used by the process, the size that is swapped out, unit kb 
l: TIME = (CPU Time) used by the process CPU Total time, in seconds 
r: CODE = (Code size (kb)) The size of the physical memory occupied by the executable code, in units kb 
s: DATA = (Data+Stack size (kb)) Parts other than executable code(data segment+stack)Occupied physical memory size, unit kb 
u: nFLT = (Page Fault count) page faults 
v: nDRT = (Dirty Pages count) The number of pages modified since the last write 
y: WCHAN = (Sleeping in Function) If the process is sleeping, display the name of the sleeping system function 
z: Flags = (Task Flags <sched.h>) mission flag, reference sched.h
X: COMMAND = (Command name/line) command name/Command Line

2. Understand the usage of cpu

vmstat

Generally only look at the procs and cpu parts

procs:

  • r: The number of processes running and waiting for CPU time slices. Generally speaking, the running queue of the entire system should not exceed twice the total number of cores, otherwise the system pressure will be too high.
  • b: The number of processes waiting for resources, such as waiting for disk IO, network IO, etc.
    cpu:
  • us: The percentage of CPU time consumed by the user process. If the us value is high, it means that the user process consumes the CPU for a long time. If it is more than 50% for a long time, it means that the program still needs to be optimized.
  • sy: percentage of CPU time consumed by kernel processes
  • The reference value of us + sy is 80%. If it is greater than 80%, it means that there may be insufficient CPU.

free
Use the free command to view memory usage. It mainly has three commands, free, free -g, free -m,
It is recommended to use free -m. If the available memory of the application/system physical memory is greater than 70%, it proves that the memory is sufficient.
If it is less than 20%, it is necessary to consider increasing the memory.

df(disk free)
-h or --human-readable Display information in a more readable way.

Check disk space with the two commands df or df -h.

iostat
Use iostat to view the disk io situation, if prompted: -bash: iostat:command not found,
That's because sysstat is not installed, just install it: yum install -y sysstat
Next run the command: iostat -xdk 3 2, much like the vmstat command.

Just look at these metrics:

  • rkb/s The amount of data read per second in kb;
  • wkb/s: The amount of data written per second in kb;
  • svctm: Average service time of I/O requests, in milliseconds;
  • util: A few percent of the time in a second is used for I/O operations. If it is close to 100%, it means that the disk bandwidth is full, and the program should be optimized or disks should be added at this time.

Network IO command: sar
Check with sar -n DEV 3 2

  • IFACE: LAN interface
  • rxpck/s: packets received per second
  • txpck/s: packets sent per second
  • rxKB/s: the amount of data received per second, in KByte
  • txKB/s: The amount of data sent per second, in KByte
  • rxcmp/s: compressed packets sent per second
  • txcmp/s: compressed packets sent per second
  • rxmcst/s: multicast packets received per second

ps
Display process information

netstat
show network status

Tags: Linux

Posted by ruzztec on Mon, 23 May 2022 14:51:10 +0300