当前位置:首页 > 内存 > 正文

linux怎么查看内存使用率百分比(linux中查看内存大小和使用)

  • 内存
  • 2024-03-15 19:01:29
  • 8771
查看 Linux 内存使用率百分比
方法 1:使用 free 命令
bash
free -h
示例输出:
Total: 8192 MiB
Used: 7696 MiB (94%)
Free: 496 MiB (6%)
Shared: 128 MiB
...
元素:
Total: 系统总内存大小
Used: 已使用的内存大小
Free: 可用内存大小
Used %: 已用内存占总内存的百分比
方法 2:使用 vmstat 命令
bash
vmstat -s
示例输出:
...
Swap usage: 0.00 kB
Committed_AS: 355540 kB
Committed_AS peaks: 355540 kB
...
元素:
Committed_AS: 正在使用的内存大小
Committed_AS peaks: 已达到的最大内存使用量
计算内存使用率:
bash
mempercent=$(vmstat -s | grep Committed_AS | cut -d ':' -f 2 | sed 's/[^0-9]//g')
echo "$mempercent%"
示例输出:
94%
其他方法:
使用 top 命令: top -b -n 1 | grep Mem
使用 SAR 命令: sar -r 1 1 | grep Memory
使用 perf stat 命令: perf stat -a sleep 1