linux离线安装smem,Linux监控工具介绍系列——smem

smem工具介绍 html

smem是Linux系统上的一款能够生成多种内存耗用报告的命令行工具。与现有工具不同的是smem能够报告实际使用的物理内存(PSS),这是一种更有意义的指标。能够衡量虚拟内存系统的库和应用程序所占用的内存数量。 java

因为大部分的物理内存一般在多个应用程序之间共享,名为实际使用物理内存(RSS)的这个标准的内存耗用衡量指标会大大高估内存耗用状况。PSS这个参数而是衡量了每一个应用程序在每一个共享内存区中的“公平分配”,给出了一个切合实际的衡量指标。 python

smem有许多功能特性: mysql

系统概况列表 linux

按进程、映射和用户列表 web

按用户、映射或用户过滤 sql

来自多个数据源的可配置列 tomcat

可配置的输出单位和百分比 bash

可配置的标题和总和 服务器

从/proc读取活动数据

从目录镜像或通过压缩的打包文件读取数据快照

面向嵌入式系统的轻型捕获工具

内置的图表生成功能

smem的系统要求

系统内核为2.6.27以上

Python版本必须为2.4或以上

依赖matplotlib库生成图表(可选的,自动检测)依赖matplotlib,是由于smem除了通常的文本信息报告外,smem 也能够生成条状或饼状图。

对应的英文原文以下:

smem is a tool that can give numerous reports on memory usage on Linux systems. Unlike existing tools, smem can reportproportional set size (PSS), which is a more meaningful representation of the amount of memory used by libraries and applications in a virtual memory system.

Because large portions of physical memory are typically shared among multiple applications, the standard measure of memory usage known as resident set size (RSS) will significantly overestimate memory usage. PSS instead measures each application's "fair share" of each shared area to give a realistic measure.

smem has many features:

system overview listing

listings by process, mapping, user

filtering by process, mapping, or user

configurable columns from multiple data sources

configurable output units and percentages

configurable headers and totals

reading live data from /proc

reading data snapshots from directory mirrors or compressed tarballs

lightweight capture tool for embedded systems

built-in chart generation

smem has a few requirements:

a reasonably modern kernel (> 2.6.27 or so)

a reasonably recent version of Python (2.4 or so)

the matplotlib library for chart generation (optional, auto-detected)

Linux使用到了虚拟内存(virtual memory),所以要准确的计算一个进程实际使用的物理内存就不是那么简单。只知道进程的虚拟内存大小也并无太大的用处,由于仍是没法获取到实际分配的物理内存大小。

RSS(Resident set size),使用top命令能够查询到,是最经常使用的内存指标,表示进程占用的物理内存大小。可是,将各进程的RSS值相加,一般会超出整个系统的内存消耗,这是由于RSS中包含了各进程间共享的内存。

PSS(Proportional set size)全部使用某共享库的程序均分该共享库占用的内存时,每一个进程占用的内存。显然全部进程的PSS之和就是系统的内存使用量。它会更准确一些,它将共享内存的大小进行平均后,再分摊到各进程上去。

USS(Unique set size )进程独自占用的内存,它是PSS中本身的部分,它只计算了进程独自占用的内存大小,不包含任何共享的部分。

VSS – Virtual Set Size 虚拟耗用内存(包含共享库占用的内存)

RSS – Resident Set Size 实际使用物理内存(包含共享库占用的内存)

PSS – Proportional Set Size 实际使用的物理内存(比例分配共享库占用的内存)

USS – Unique Set Size 进程独自占用的物理内存(不包含共享库占用的内存)

smem工具安装

首先去官方网址https://www.selenic.com/smem/ 下载对应的smem安装包,目前最新的版本为smem-1.4.  下面安装是在RHEL 5.7上安装,不一样版本系统、以及不一样安装方法都有一些区别。

1: [root@DB-Server tmp]# tar -xzvf smem-1.4.tar.gz

2: smem-1.4/.hg_archival.txt

3: smem-1.4/.hgtags

4: smem-1.4/COPYING

5: smem-1.4/smem

6: smem-1.4/smem.8

7: smem-1.4/smemcap.c

8: [root@DB-Server tmp]# cd smem-1.4

9: [root@DB-Server smem-1.4]# ls

10: COPYING  smem  smem.8  smemcap.c

11: [root@DB-Server smem-1.4]# cp /tmp/smem-1.4/smem  /usr/bin

12: [root@DB-Server smem-1.4]# chmod +x /usr/bin/smem

smem工具使用

查看smem命令的相关帮助信息

1: [root@DB-Server tmp]# smem -h

2: usage: smem [options]

3:

4: options:

5:   -h, --help            show this help message and exit

6:   -H, --no-header       disable header line

7:   -c COLUMNS, --columns=COLUMNS

8:                         columns to show

9:   -t, --totals          show totals

10:   -R REALMEM, --realmem=REALMEM

11:                         amount of physical RAM

12:   -K KERNEL, --kernel=KERNEL

13:                         path to kernel image

14:   -m, --mappings        show mappings

15:   -u, --users           show users

16:   -w, --system          show whole system

17:   -P PROCESSFILTER, --processfilter=PROCESSFILTER

18:                         process filter regex

19:   -M MAPFILTER, --mapfilter=MAPFILTER

20:                         map filter regex

21:   -U USERFILTER, --userfilter=USERFILTER

22:                         user filter regex

23:   -n, --numeric         numeric output

24:   -s SORT, --sort=SORT  field to sort on

25:   -r, --reverse         reverse sort

26:   -p, --percent         show percentage

27:   -k, --abbreviate      show unit suffixes

28:   --pie=PIE             show pie graph

29:   --bar=BAR             show bar graph

30:   -S SOURCE, --source=SOURCE

31:                         /proc data source

1:无参数时显示全部进程的内存使用状况

2:参数-u 显示每一个用户所耗用的内存总量

smem -u

9f9e383337094ec393716127.html

3: 参数-p 查看耗用内存状况的百分比。

smem -p

9f9e383337094ec393716127.html

4: 参数-w 查看系统内存使用状况

1: [root@DB-Server01 ~]# smem -w

2: Area                           Used      Cache   Noncache

3: firmware/hardware                 0          0          0

4: kernel image                      0          0          0

5: kernel dynamic memory      22021892   21721584     300308

6: userspace memory            1899296     122424    1776872

7: free memory                  686340     686340          0

8: [root@DB-Server01 ~]# smem -w -p

9: Area                           Used      Cache   Noncache

10: firmware/hardware             0.00%      0.00%      0.00%

11: kernel image                  0.00%      0.00%      0.00%

12: kernel dynamic memory        89.49%     88.27%      1.22%

13: userspace memory              7.73%      0.50%      7.23%

14: free memory                   2.78%      2.78%      0.00%

5: 参数-R REALMEM,REALMEM这个值是指物理内存数量。此参数可让smem在整个系统(-w)的输出中发现固件/硬件所耗用的内存数量(对比上下便可发现,注意firmware/hardware)

1: [root@DB-Server01 ~]# smem -R 24G -w

2: Area                           Used      Cache   Noncache

3: firmware/hardware            558296          0     558296

4: kernel image                      0          0          0

5: kernel dynamic memory      22024108   21722972     301136

6: userspace memory            1907676     122436    1785240

7: free memory                  675744     675744          0

6:参数-c 用来显示须要展现的列。

1: [root@DB-Server01 ~]# smem -c "name user pss"

2: Name                     User          PSS

3: mingetty                 root           18

4: mingetty                 root           18

5: mingetty                 root           18

6: mingetty                 root           18

7: mingetty                 root           18

8: bash                     root          911

9: sftp-server              root          939

10: cupsd                    root         1208

11: rsyslogd                 root         1403

12: smbd                     tibco        1474

13: hald                     haldaemon     1477

14: pickup                   postfix      1487

15: vmtoolsd                 root         2309

16: sshd                     root         2521

17: python                   root         5464

18: beremote                 root         7585

19: java                     weblogic    18454

20: java                     weblogic    31431

21: java                     weblogic    69389

22: java                     tomcat     339977

23: java                     tomcat     355037

24: java                     tomcat     421133

25: java                     weblogic   640531

7: 参数-s 根据某一列(例如 rss)来排序.

9f9e383337094ec393716127.html

8: 参数-r 通常与参数-s结合使用,表示反转排序(从升序改成降序)

9f9e383337094ec393716127.html

9:参数-M 过滤相关进程。Show processes filtered by mapping

1: [root@DB-Server tmp]# smem -M mysql

2:   PID User     Command                         Swap      USS      PSS      RSS

3:  4172 mysql    /usr/sbin/mysqld --basedir=        0     3924     3924     3924

4: [root@DB-Server tmp]# smem -M mysql -p

5:   PID User     Command                         Swap      USS      PSS      RSS

6:  4172 mysql    /usr/sbin/mysqld --basedir=    0.00%    0.38%    0.38%    0.38%

7: [root@DB-Server tmp]#

9f9e383337094ec393716127.html

10:参数-U 按用户过滤信息

另一些参数如何展现条状图或饼状图的功能,我的感受这些参数的用处不大,首先服务器通常都没有安装桌面系统,都是命令界面维护、管理。没法生成相关图形。其次服务器有桌面系统,也须要安装相关依赖包,至关麻烦。除非是为了生成报告须要。

Read data from capture tarball smem --source capture.tar.gz

Show a bar chart labeled by pid smem --bar pid -c "pss uss"

Show a pie chart of RSS labeled by name smem --pie name -s rss

参考资料

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值