Linux monitoring commands collected in those years

If only top and ps are used, wouldn't it be too small to use, and many parameters are not used.

The following are some practical solutions. This article does not explain the parameters or principles. The meaning of specific parameters is of interest to you.

View the processes with the most memory usage

In fact, generally only need to know the memory occupation, and its process start command, it is good to know which program.

ps dafa

# ps -eo pmem,pcpu,vsize,pid,cmd | sort -k 1 -nr | head -5
 9.3  0.1 9031172 16090 java -jar start.jar
 8.3  0.0 8487956 26303 java -jar web.jar

If more details:

# ps aux --sort -rss | head
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root     16090  0.1  9.3 9031172 1534136 ?     Sl   Mar26  10:48 java -jar start.jar
root     26303  0.0  8.3 8487956 1376960 ?     Sl   Mar23   7:38 java -jar web.jar

The following is easier to understand, but the command display is not complete

# ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head -10
  PID  PPID CMD                         %MEM %CPU
16090     1 java -jar start.jar          9.3  0.1
26303     1 java -jar web.jar  8.3  0.0

top Dafa is good

# top -b -o +%MEM | head -n 14
top - 19:40:37 up 16 days,  7:21,  3 users,  load average: 0.50, 0.51, 0.42
Tasks: 156 total,   1 running, 155 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  1.0 sy,  0.0 ni, 99.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem : 16432412 total,  3776164 free, 11291864 used,  1364384 buff/cache
KiB Swap:  8388604 total,  4448996 free,  3939608 used.  4711392 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
16090 root      20   0 9031172 1.463g   8308 S   0.0  9.3  10:49.47 java
26303 root      20   0 8487956 1.313g   5928 S   0.0  8.4   7:39.10 java
 1967 root      20   0 5810680 1.166g   5600 S   0.0  7.4 390:36.74 java
24983 root      20   0 9010736 988.6m  15032 S   0.0  6.2   2:03.30 java
30677 root      20   0 20.868g 796216  32420 S   0.0  4.8   4:48.23 java
21704 root      20   0 8949684 710076  13308 S   0.0  4.3   1:27.42 java
 9851 just      20   0 6189964 484484   4944 S   0.0  2.9 183:57.37 java

htop

The upgraded version of top, the interface is very beautiful, who knows who uses it.

View the most occupied files (folders)

The folder or file most occupied by the current directory (excluding subfolders):

# du -hs * | sort -rh | head -n 5
452M	lib
127M	cache
125M	ftp
93M	log
260K	spool

If you want to include subfolders:

# du -Sh | sort -rh | head -n 5
173M	./lib/mysql
125M	./ftp
101M	./lib/rpm
89M	./log
53M	./lib/mysql/jobserver

View only the files that occupy the most space:

# find -type f -exec du -Sh {} + | sort -rh | head -n 5
125M	./ftp/dependencies.jar
92M	./lib/rpm/Packages
76M	./lib/mysql/ibdata1
48M	./lib/mysql/ib_logfile1
48M	./lib/mysql/ib_logfile0

If you want to specify the path, just modify the findparameters:

# find /var/ftp -type f -exec du -Sh {} + | sort -rh | head -n 5
125M	/var/ftp/dependencies.jar
4.0K	/var/ftp/tmp.txt
4.0K	/var/ftp/pub/tmp.txt

The internet

View the process corresponding to a port

# lsof -i TCP:8080
COMMAND   PID USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
java    31876 root  269u  IPv6 1897559      0t0  TCP *:webcache (LISTEN)

I

iotop

View real-time disk read and write

iostat

Check hard disk read and write speed, generally used to troubleshoot disk performance

# iostat
Linux 3.10.0-693.el7.x86_64 (host) 	03/30/2020 	_x86_64_	(6 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           5.48    0.00    0.32    0.35    0.01   93.84

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
vda               7.57       120.45      1012.41  170193222 1430505193

To be continued ~

Published 80 original articles · Like 319 · Visits 340,000+

Guess you like

Origin blog.csdn.net/jimo_lonely/article/details/105208392