常用命令top, atop, iotop, free, gnome-system-monitor
top 查看的是所有cpu的平均值
carl@carl-X556UQK:~$ top top - 16:13:45 up 1:14, 1 user, load average: 1.76, 1.83, 1.67 Tasks: 275 total, 1 running, 219 sleeping, 0 stopped, 0 zombie %Cpu(s): 16.1 us, 14.9 sy, 0.0 ni, 61.7 id, 4.9 wa, 0.0 hi, 2.4 si, 0.0 st KiB Mem : 8046208 total, 1117996 free, 3889296 used, 3038916 buff/cache KiB Swap: 8265724 total, 8265724 free, 0 used. 3252208 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 13207 carl 20 0 43660 4200 3476 R 22.2 0.1 0:00.06 top 5635 carl 20 0 5286944 896516 68836 S 5.6 11.1 2:34.92 java 12507 carl 20 0 3144052 186128 124432 S 5.6 2.3 0:12.03 chromium-b+ 1 root 20 0 225724 9588 6780 S 0.0 0.1 0:03.33 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 4 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/0:+ 6 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 mm_percpu_+ 7 root 20 0 0 0 0 S 0.0 0.0 0:09.63 ksoftirqd/0在top窗口中,按下键盘1,可以查看每一个cpu的值。
carl@carl-X556UQK:~$ top top - 16:17:38 up 1:08, 1 user, load average: 0.41, 1.04, 1.41 Tasks: 262 total, 1 running, 208 sleeping, 0 stopped, 0 zombie %Cpu0 : 2.3 us, 0.7 sy, 0.0 ni, 96.7 id, 0.0 wa, 0.0 hi, 0.3 si, 0.0 st %Cpu1 : 1.3 us, 0.7 sy, 0.0 ni, 98.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st %Cpu2 : 2.0 us, 0.3 sy, 0.0 ni, 97.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st %Cpu3 : 4.0 us, 0.7 sy, 0.0 ni, 95.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 8046208 total, 2104732 free, 3470380 used, 2471096 buff/cache KiB Swap: 8265724 total, 8265724 free, 0 used. 3776088 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 3622 carl 20 0 3704548 251820 159036 S 5.3 3.1 1:22.77 gnome-shell 4193 carl 20 0 3758140 382948 210712 S 3.0 4.8 2:12.21 firefox 3257 carl 20 0 637068 130752 106176 S 1.3 1.6 1:08.73 Xorg 1714 mysql 20 0 2066560 396428 28104 S 1.0 4.9 0:29.36 mysqldatop窗口下,在键盘上按下d 可以查看详细进程。
free 命令能够显示系统中物理上的空闲和已用内存,还有交换内存,同时,也能显示被内核使用的缓冲和缓存
语法:free [param]param可以为:
-b:以Byte为单位显示内存使用情况; -k:以KB为单位显示内存使用情况; -m:以MB为单位显示内存使用情况; -o:不显示缓冲区调节列; -s<间隔秒数>:持续观察内存使用状况; -t:显示内存总和列; -V:显示版本信息。
carl@carl-X556UQK:~$ free -h -t total used free shared buff/cache available Mem: 7.7G 3.6G 1.3G 487M 2.8G 3.3G Swap: 7.9G 0B 7.9G Total: 15G 3.6G 9.1GMen:表示物理内存统计
total:表示物理内存总数(total=used+free) used:表示系统分配给缓存使用的数量(这里的缓存包括buffer和cache) free:表示未分配的物理内存总数 shared:表示共享内存 buffers:系统分配但未被使用的buffers 数量。 cached:系统分配但未被使用的cache 数量。 -/+ buffers/cache:表示物理内存的缓存统计
(-buffers/cache) 内存数: (指的第一部分Mem行中的used – buffers – cached) (+buffers/cache) 内存数: (指的第一部分Mem行中的free + buffers + cached) (-buffers/cache)表示真正使用的内存数, (+buffers/cache) 表示真正未使用的内存数
Swap:表示硬盘上交换分区的使用情况
想了解更多可以参看如下文章 https://haydenjames.io/linux-server-performance-disk-io-slowing-application/ https://www.cyberciti.biz/faq/linux-check-memory-usage/ https://blog.csdn.net/u014427391/article/details/102785219