smem的學習

smem的學習


背景

勞動節加班時主要進行了疲勞驗證
當時關注了jvm_exporter的內存數據
節後再看了下 NMT的跟蹤
發現NMT的結果比exporter的總要高一些.
然後前幾天又有項目反饋OOM killer
我懷疑 是有本進程或者是其他進程大量佔用內存導致踩踏
但是一直沒有比較好的方式來實現檢查. 
然後最近又找到了一個 smem 工具. 不知道可行不可行
遂學習和記錄一下. 

smem的安裝

一般網上都是介紹使用 yum 安裝
但是發現國產設備, 尤其是銀河麒麟v10 好像沒有源

所以可以使用 tar包
其實smem 是一個分析 /proc的工具
他不區分CPU的架構.

https://www.selenic.com/smem/download/

注意 centos8 可以直接安裝 yum install smem -y 
使用epel倉庫

smem的幫助

smem -h
Usage: smem [options]

Options:
  -h, --help            show this help message and exit
  -H, --no-header       disable header line
  -c COLUMNS, --columns=COLUMNS
                        columns to show
  -t, --totals          show totals
  -a, --autosize        size columns to fit terminal size
  -R REALMEM, --realmem=REALMEM
                        amount of physical RAM
  -K KERNEL, --kernel=KERNEL
                        path to kernel image
  -m, --mappings        show mappings
  -u, --users           show users
  -w, --system          show whole system
  -P PROCESSFILTER, --processfilter=PROCESSFILTER
                        process filter regex
  -M MAPFILTER, --mapfilter=MAPFILTER
                        map filter regex
  -U USERFILTER, --userfilter=USERFILTER
                        user filter regex
  -n, --numeric         numeric output
  -s SORT, --sort=SORT  field to sort on
  -r, --reverse         reverse sort
  -p, --percent         show percentage
  -k, --abbreviate      show unit suffixes
  --pie=PIE             show pie graph
  --bar=BAR             show bar graph
  -S SOURCE, --source=SOURCE
                        /proc data source

幾個關鍵方法

smem  -w -t -k -a -p
Area                     Used   Cache Noncache
firmware/hardware           0       0        0
kernel image                0       0        0
kernel dynamic memory   20.0G   19.5G   466.6M
userspace memory        41.0G  275.1M    40.7G
free memory            671.4M  671.4M        0
-----------------------------------------------
                        61.6G   20.4G    41.2G

其實還可以:
smem  -k -p -t
PID   User     Command                         Swap      USS      PSS      RSS
  961 root     /usr/local/cloudmonitor/bin        0    23.9M    28.0M    34.2M
 2005 root     /usr/local/aegis/alihips/Al        0    31.0M    31.4M    34.5M
 1692 root     /usr/local/aegis/aegis_clie        0    56.0M    58.1M    63.0M
 3692 root     ./server/runtime/java/x86_6        0    40.7G    40.7G    40.7G
-------------------------------------------------------------------------------
   41 7                                           0    41.0G    41.0G    41.2G

需要注意  -w 包含系統 -t 包含total  -a 自適應列寬 -p 顯示比率 -k自動修改單位.

其實還可以使用 
smem -u -k -t -a
User           Count    Swap     USS     PSS     RSS
libstoragemgmt     1       0  224.0K  267.0K    1.8M
rpc                1       0  908.0K    1.2M    5.3M
dbus               1       0    1.0M    1.5M    5.3M
chrony             1       0    1.2M    1.7M    5.0M
daemon             1       0    3.7M    4.4M    8.7M
polkitd            1       0   16.0M   17.7M   23.8M
root              35       0   41.0G   41.0G   41.1G
-----------------------------------------------------
                  41       0   41.0G   41.0G   41.2G

會把用戶 以及進程數量和使用的內存情況都拉取出來. 
想過挺好的. 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章