arraylist从大到小排序_使用hcache排序当前内存中的缓存文件,找出内存缓存大户

576ad47014d5673ffd5f4de19246ec46.png

在内存告警中,经常会遇到系统OOM,登陆服务器查看大部分内存是被cache 使用了。

7a605d6c5c5ea91868950f12640b62ec.png

free -mh

通过cat /proc/meminfo 或者free命令我也只能看出内存大部分是被buff/cache,至于是哪些程序占用了,毫无头绪。所以需要一个工具能帮助我去查看下当前系统环境下内存缓存的使用情况,最好能做个排序,从而一目了然知道缓存文件大户。

答案是 hcache - a tool fork from pcstat, with a feature that showing top X biggest cache files globally,来源于pcstat,新增了top功能对缓存文件大小进行排序。

https://github.com/silenceshell/hcache

构建

需要go版本> 1.12

git clone https://github.com/silenceshell/hcache.gitcd hcachemake buildsudo cp hcache /usr/local/bin/ 

或者直接下载hcache作者已构建好的,下载地址如下:

https://silenceshell-1255345740.cos.ap-shanghai.myqcloud.com/hcache

hcache的命令介绍

a63905bd41dfab6333b47c9790a506bc.png

-bname 路径名称转换成简写名称

-histo 直方图显示缓存文件比例

-json 返回json数据

-pid int 返回特定pid的数据

-terse 显示简短输出

示例

./hcache -top 10

23e0f4b19b71642046cd224e706bfdce.png

./hcache -top 10

可以看到是按照cache的大小从大到小排序,从而很直观看到那些文件路径占用了缓存页面。

再结合lsof就可以找到文件的进程信息了。

./hcache -top 10 -bname

+--------------------------+----------------+------------+-----------+---------+| Name                             | Size (bytes)    | Pages       | Cached    | Percent ||--------------------------+----------------+------------+-----------+---------|| containerd                     | 49085976       | 11984      | 8420         | 070.260 || dockerd                         | 102122240     | 24933      | 1786         | 007.163 || system.journal               | 24834048       | 6063        | 1106         | 018.242 || libmysqlclient.so.18.0.0 | 3135664         | 766          | 766           | 100.000 || containerd-shim            | 6120256         | 1495        | 621           | 041.538 || hcache                           | 2542252         | 621          | 621           | 100.000 || libcrypto.so.1.0.2k         | 2521144         | 616          | 616           | 100.000 || libc-2.17.so                    | 2156240         | 527          | 527           | 100.000 || libdb-5.3.so                    | 1850600        | 452          | 452           | 100.000 || libpython2.7.so.1.0        | 1847752         | 452          | 452           | 100.000 |+--------------------------+----------------+------------+-----------+---------+

hcache -pid 1

79072f8a49a5e6d93f425aa17de0b3ae.png

hcache -pid 1

./hcache -top 10 -histo

3b6c335c177db10aedf3b895e97d13cf.png

hcache -top 10 -histo

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值