内存占用率监控分享

在系统中,获取内存占用率有多种方法,以下是几种常用方式:

  1. 使用 free 命令:
free -m  # 显示内存使用情况,不同设备可能单位不一样

输出中,Mem行的used/total即可计算内存占用率

  1. 使用 top 命令(实时监控):
top

在 top 界面中,Mem行显示了内存使用情况,其中%MEM列显示各进程占用的内存百分比

  1. 使用 vmstat 命令:
vmstat -s  # 显示内存统计信息

可以用输出中的used memory/total memory

  1. 使用如下脚本可获取内存占用率

Some suggestions about this topic:

  1. There are some more commands and arguments about Linux command for monitoring memory, for example:
    (1) free -m/-k
    (2) top
    (3) ps -ef | grep <pid>
    etc.
    There are more than one arguments about these commands, and this topic should be completed with more details about these commands and usages.
  2. There is another way to obtain the memory usage, which is that App read the process statistics file which located at /proc/<pid>/status, please offers more details about this

CPU、内存等占用率监控可以参考可观测技术,使用prometheus和grafana实现监控数据可视化展示

1 个赞