阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Linux监控工具介绍系列——smem

142次阅读
没有评论

共计 6136 个字符,预计需要花费 16 分钟才能阅读完成。

smem 工具介绍

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

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

smem 有许多功能特性:

系统概况列表

按进程、映射和用户列表

按用户、映射或用户过滤

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

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

可配置的标题和总和

从 /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 report proportional 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

Linux 监控工具介绍系列——smem

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

smem -p

Linux 监控工具介绍系列——smem

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)来排序.

Linux 监控工具介绍系列——smem

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

Linux 监控工具介绍系列——smem

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]#

Linux 监控工具介绍系列——smem

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

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2015-12/126810.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计6136字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中