Linux 系统监控
Top命令
Processes: 355 total, 3 running, 352 sleeping, 1540 threads 22:53:50
Load Avg: 2.23, 1.85, 1.79 CPU usage: 2.91% user, 3.4% sys, 94.3% idle
SharedLibs: 203M resident, 47M data, 29M linkedit.
MemRegions: 67938 total, 2480M resident, 96M private, 956M shared.
PhysMem: 9029M used (3177M wired), 7345M unused.
VM: 995G vsize, 627M framework vsize, 66673141(0) swapins, 67456042(0) swapouts.
Networks: packets: 10075546/9110M in, 7870367/1935M out.
Disks: 5209393/349G read, 3216109/340G written.
PID COMMAND %CPU TIME #TH #WQ #PORT MEM PURG CMPRS PGRP
36055 git 0.0 00:00.06 1 0 10 928K 0B 0B 35626
36054 git 0.0 00:01.33 2 0 11 7628K 0B 0B 35626
36052 mdworker 0.0 00:00.06 4 1 48 5224K 0B 0B 36052
36051 mdworker 0.0 00:00.03 3 1 46 2932K 0B 0B 36051
36050 mdworker 0.0 00:00.06 4 1 48 8084K 0B 0B 36050
36049 top 2.8 00:06.87 1/1 0 25 3400K 0B 0B 36049
35964 bash 0.0 00:00.07 1 0 16 2668K 0B 0B 35964
35963 login 0.0 00:00.02 2 1 29 1132K 0B 0B 35963
35961 Google Chrom 0.0 00:05.98 18 2 156 77M 0B 0B 4804
35955 git-remote-h 0.1 00:00.29 2 1 37 10M 0B 0B 35626
35954 git 0.0 00:00.02 1 0 10 6932K 0B 0B 35626
35949 git-remote-h 0.1 00:00.26 2 1 37 4672K+ 0B 0B 35626
35948 git 0.0 00:00.01 1 0 10 968K 0B 0B 35626
35940 bash 0.0 00:00.00 1 0 8 460K 0B 0B 35626
然而还有个好用的工具那就是 glances(惊鸿一瞥)
mac下载方法:
brew install -y glances
Linux Ubuntu:
apt install -y glances
Linux Centos:
yum install -y glances
Pip:
pip install glances
glances使用方法:
在终端直接敲glances:
CPU [ 9.3%] CPU / 9.3% nice: 0.0% ctx_sw: 441 MEM - 61.2% SWAP - 52.6% LOAD 8-core
MEM [ 61.3%] user: 6.7% inter: -2515 total: 16.0G total: 2.00G 1 min: 1.69
SWAP [ 52.6%] system: 2.7% sw_int: 446 used: 9.80G used: 1.05G 5 min: 1.72
idle: 90.7% syscal: 0 free: 6.20G free: 970M 15 min: 1.73
NETWORK Rx/s Tx/s TASKS 195 (939 thr), 195 run, 0 slp, 0 oth sorted automatically by cpu_percent, flat view
awdl0 0b 0b
bridge0 0b 0b CPU% MEM% VIRT RES PID USER NI S TIME+ Command
en0 2Kb 864b 39.3 0.7 3.45G 121M 293 yuqibing 0 R 11:12.56 /Applications/Utilities/Terminal.
en1 0b 0b 4.9 0.9 4.21G 155M 18921 yuqibing 0 R 47:40.92 /Applications/Google Chrome.app/C
en2 0b 0b 2.9 0.1 2.44G 13.1M 4811 yuqibing 0 R 22:06.99 /System/Library/Frameworks/VideoT
lo0 280b 280b 2.7 0.3 2.41G 43.9M 38637 yuqibing 0 R 0:03.34 /Library/Frameworks/Python.framew
p2p0 0b 0b 2.4 1.2 9.44G 190M 4809 yuqibing 0 R 1h10:32 /Applications/Google Chrome.app/C
utun0 0b 0b 1.4 1.7 5.19G 276M 4804 yuqibing 0 R 2h05:54 /Applications/Google Chrome.app/C
utun1 0b 0b 1.2 0.7 2.96G 115M 370 yuqibing 0 R 7:49.55 /System/Library/Input Methods/SCI
0.5 2.3 4.04G 383M 19198 yuqibing 0 R 3:53.39 /Applications/Google Chrome.app/C
DISK I/O R/s W/s 0.3 0.6 3.63G 103M 35137 yuqibing 0 R 0:42.80 /Applications/Google Chrome.app/C
disk0 494K 0 0.1 0.2 3.55G 34.1M 18920 yuqibing 0 R 1:15.87 /Applications/Google Chrome.app/C
disk2 0 0 0.1 0.5 3.70G 83.3M 18944 yuqibing 0 R 3:57.14 /Applications/Google Chrome.app/C
disk3 0 0 0.1 0.5 3.67G 90.0M 19058 yuqibing 0 R 1:23.48 /Applications/Google Chrome.app/C
0.1 0.1 4.48G 10.1M 19543 yuqibing 0 R 0:54.79 /Library/Java/JavaVirtualMachines
FILE SYS Used Total 0.1 0.2 3.57G 25.7M 19560 yuqibing 0 R 0:52.25 /Applications/Google Chrome.app/C
/ (disk1) 115G 233G 0.1 0.6 3.39G 106M 35625 yuqibing 0 R 0:01.54 /Applications/Google Chrome.app/C
_sX-NG-R8 18.0M 22.4M 0.0 0.4 2.67G 72.3M 111 root 0 R 2:18.93 /System/Library/CoreServices/logi
_CCB6B9D7 118G 233G 0.0 0.1 2.41G 13.4M 278 yuqibing 0 R 0:54.79 /usr/sbin/cfprefsd agent
0.0 0.1 2.43G 20.3M 279 yuqibing 0 R 1:11.77 /usr/libexec/UserEventAgent (Aqua
SENSORS 0.0 0.1 2.40G 11.8M 281 yuqibing 0 R 2:58.90 /usr/sbin/distnoted agent
Battery 46% 0.0 0.2 2.45G 25.4M 283 yuqibing 0 R 0:49.88 /System/Library/Frameworks/CoreTe
0.0 0.1 2.43G 16.4M 284 yuqibing 0 R 0:12.73 /usr/libexec/lsd
0.0 0.1 3.46G 18.3M 285 yuqibing 0 R 1:55.30 /usr/libexec/trustd --agent
0.0 0.1 2.42G 13.4M 289 yuqibing 0 R 0:06.44 /System/Library/CoreServices/shar
Glances 会用一下几种颜色来代表状态:
更多glances的选项,可以用
man glances来参看。
glances -s
Define the password for the Glances server
Password:
Password (confirm):
Glances server is running on 0.0.0.0:61209
当你执行了glances -s命令后,会让你为 Glances 服务器设置密码。当你设置完毕,你将看到 “Glances server is running on 0.0.0.0:61209” (Glances 服务器正在 0.0.0.0 的 61209 端口运行)的消息。当 Glances 服务器启动后,到本地执行下面的命令来指定服务器IP地址或主机名以链接。
注:这里的172.16.27.56是我 Glances 服务器的 IP 地址。glances -c -P 172.16.27.56
下面是一些在使用服务器/客户端模式时必须知道的事情:
-B 地址
来设置绑定地址,也可以通过 -p 端口
来绑定监听的 TCP 端口-p 端口
来指定服务器端口-P 密码
的方式来为服务器端设置一个密码pmap
可以根据进程查看进程相关信息占用的内存情况,(进程号可以通过ps查看)如下所示:
$ pmap -d 5647
Linux中使用free来查看内存
$ free
total used free shared buffers cached
Mem: 8193564 7868388 325176 0 198848 2645932
-/+ buffers/cache: 5023608 3169956
Swap: 0 0 0
如何看额定值:
cat /proc/meminfo
proc:
/proc是Linux的一个伪文件系统,存储的是当前内核运行状态的一系列特殊文件,用户可以通过这些文件查看有关系统硬件及当前正在运行进程的信息,甚至可以通过更改其中某些文件来改变内核的运行状态。
/proc/cpuinfo cpu的相关信息