[zz]sar命令使用指南

little lily posted @ Thu, 12 Aug 2010 20:04:46 +0800 in Testing with tags unix sar cpu , 1624 readers

纯粹记录一下,在做performance test的时候很有用~~

 zz from http://blog.chinaunix.net/u/20492/showart_164619.html

呵呵,这是偶朋友发过来给偶的,偶一直不大会用,这回大家一起来交流一下吧,希望对大家也有所帮助啊!

  在使用UNIX操作系统的过程中,我们常常会用到各种各样的问题,比如系统运行速度 突然变慢,系统容易死机或者主机所带的终端常出现死机,这时我们常常猜测,是硬盘空间太小,还是内存不足?I/O出现瓶颈,或者是系统的核心参数出了问题?这时,我们应该考虑使用系统给我们提供的sar命令来对系统作一个了解,该命令是系统维护 的重要工具,主要帮助我们掌握系统资源的使用情况,特别是内存和CPU 的使用情况, 是UNIX系统使用者应该掌握的工具之一。 
sar 命令行的常用格式: 

sar [options] [-A] [-o file] t [n] 

在命令行中,n 和t 两个参数组合起来定义采样间隔和次数,t为采样间隔,是必须有的参数,n为采样次数,是可选的,默认值是1,-o file表示将命令结果以二进制格式 存放在文件中,file 在此处不是关键字,是文件名。options 为命令行选项,sar命令 的选项很多,下面只列出常用选项: 

-A:所有报告的总和。 
-u:CPU利用率 
-v:进程、I节点、文件和锁表状态。 
-d:硬盘使用报告。 
-r:没有使用的内存页面和硬盘块。 
-g:串口I/O的情况。 
-b:缓冲区使用情况。 
-a:文件读写情况。 
-c:系统调用情况。 
-R:进程的活动情况。 
-y:终端设备活动情况。 
-w:系统交换活动。 

下面将举例说明。 

例一:使用命令行 sar -u t n 

例如,每60秒采样一次,连续采样5次,观察CPU 的使用情况,并将采样结果以二进制形式存入当前目录下的文件zhou中,需键入如下命令: 

# sar -u -o zhou 60 5 

屏幕显示: 

SCO_SV   scosysv 3.2v5.0.5 i80386   10/01/2001 
14:43:50   %usr   %sys  %wio    %idle(-u) 
14:44:50   0     1    4      94 
14:45:50   0     2    4      93 
14:46:50   0     2    2      96 
14:47:50   0     2    5      93 
14:48:50   0     2    2      96 
Average    0     2    4      94 

在显示内容包括: 

%usr:CPU处在用户模式下的时间百分比。 
%sys:CPU处在系统模式下的时间百分比。 
%wio:CPU等待输入输出完成时间的百分比。 
%idle:CPU空闲时间百分比。 

在所有的显示中,我们应主要注意%wio和%idle,%wio的值过高,表示硬盘存在I/O瓶颈,%idle值高,表示CPU较空闲,如果%idle值高但系统响应慢时,有可能是CPU等待分配内存,此时应加大内存容量。%idle值如果持续低于10,那么系统的CPU处理能力相对较低,表明系统中最需要解决的资源是CPU。 

如果要查看二进制文件zhou中的内容,则需键入如下sar命令: 

# sar -u -f zhou 

可见,sar命令即可以实时采样,又可以对以往的采样结果进行查询。 

例二:使用命行sar -v t n 

例如,每30秒采样一次,连续采样5次,观察核心表的状态,需键入如下命令: 

# sar -v 30 5 

屏幕显示: 
SCO_SV scosysv 3.2v5.0.5 i80386 10/01/2001 
10:33:23 proc-sz ov inod-sz ov file-sz ov lock-sz   (-v) 
10:33:53 305/ 321  0 1337/2764  0 1561/1706 0 40/ 128 
10:34:23 308/ 321  0 1340/2764  0 1587/1706 0 37/ 128  
10:34:53 305/ 321  0 1332/2764  0 1565/1706 0 36/ 128 
10:35:23 308/ 321  0 1338/2764  0 1592/1706 0 37/ 128 
10:35:53 308/ 321  0 1335/2764  0 1591/1706 0 37/ 128  

显示内容包括: 

proc-sz:目前核心中正在使用或分配的进程表的表项数,由核心参数MAX-PROC控制。 

inod-sz:目前核心中正在使用或分配的i节点表的表项数,由核心参数 
MAX-INODE控制。 

file-sz: 目前核心中正在使用或分配的文件表的表项数,由核心参数MAX-FILE控制。 

ov:溢出出现的次数。 

Lock-sz:目前核心中正在使用或分配的记录加锁的表项数,由核心参数MAX-FLCKRE控制。 

显示格式为 

实际使用表项/可以使用的表项数 

显示内容表示,核心使用完全正常,三个表没有出现溢出现象,核心参数不需调整,如果出现溢出时,要调整相应的核心参数,将对应的表项数加大。 

例三:使用命行sar -d t n 

例如,每30秒采样一次,连续采样5次,报告设备使用情况,需键入如下命令: 

# sar -d 30 5 

屏幕显示: 

SCO_SV scosysv 3.2v5.0.5 i80386 10/01/2001 
11:06:43 device %busy   avque   r+w/s  blks/s  avwait avserv (-d) 
11:07:13 wd-0   1.47   2.75   4.67   14.73   5.50 3.14 
11:07:43 wd-0   0.43   18.77   3.07   8.66   25.11 1.41 
11:08:13 wd-0   0.77   2.78   2.77   7.26   4.94 2.77 
11:08:43 wd-0   1.10   11.18   4.10   11.26   27.32 2.68 
11:09:13 wd-0   1.97   21.78   5.86   34.06   69.66 3.35 
Average wd-0   1.15   12.11   4.09   15.19   31.12 2.80  

显示内容包括: 

device: sar命令正在监视的块设备的名字。 
%busy: 设备忙时,传送请求所占时间的百分比。 
avque: 队列站满时,未完成请求数量的平均值。 
r+w/s: 每秒传送到设备或从设备传出的数据量。 
blks/s: 每秒传送的块数,每块512字节。 
avwait: 队列占满时传送请求等待队列空闲的平均时间。 
avserv: 完成传送请求所需平均时间(毫秒)。 

在显示的内容中,wd-0是硬盘的名字,%busy的值比较小,说明用于处理传送请求的有效时间太少,文件系统效率不高,一般来讲,%busy值高些,avque值低些,文件系统的效率比较高,如果%busy和avque值相对比较高,说明硬盘传输速度太慢,需调整。 

例四:使用命行sar -b t n 

例如,每30秒采样一次,连续采样5次,报告缓冲区的使用情况,需键入如下命令: 

# sar -b 30 5 

屏幕显示: 

SCO_SV scosysv 3.2v5.0.5 i80386 10/01/2001 
14:54:59 bread/s lread/s %rcache bwrit/s lwrit/s %wcache pread/s pwrit/s (-b) 
14:55:29 0  147  100  5  21  78   0   0 
14:55:59 0  186  100  5  25  79   0   0 
14:56:29 4  232   98  8  58  86   0   0 
14:56:59 0  125  100  5  23  76   0   0 
14:57:29 0   89  100  4  12  66   0   0 
Average  1  156   99  5  28  80   0   0 

显示内容包括: 

bread/s: 每秒从硬盘读入系统缓冲区buffer的物理块数。 
lread/s: 平均每秒从系统buffer读出的逻辑块数。 
%rcache: 在buffer cache中进行逻辑读的百分比。 
bwrit/s: 平均每秒从系统buffer向磁盘所写的物理块数。 
lwrit/s: 平均每秒写到系统buffer逻辑块数。 
%wcache: 在buffer cache中进行逻辑读的百分比。 
pread/s: 平均每秒请求物理读的次数。 
pwrit/s: 平均每秒请求物理写的次数。 

在显示的内容中,最重要的是%cache和%wcache两列,它们的值体现着buffer的使用效率,%rcache的值小于90或者%wcache的值低于65,应适当增加系统buffer的数量,buffer数量由核心参数NBUF控制,使%rcache达到90左右,%wcache达到80左右。但buffer参数值的多少影响I/O效率,增加buffer,应在较大内存的情况下,否则系统效率反而得不到提高。 

例五:使用命行sar -g t n 

例如,每30秒采样一次,连续采样5次,报告串口I/O的操作情况,需键入如下命令: 

# sar -g 30 5 

屏幕显示: 

SCO_SV scosysv 3.2v5.0.5 i80386  11/22/2001 
17:07:03  ovsiohw/s  ovsiodma/s  ovclist/s (-g) 
17:07:33   0.00   0.00   0.00 
17:08:03   0.00   0.00   0.00 
17:08:33   0.00   0.00   0.00 
17:09:03   0.00   0.00   0.00 
17:09:33   0.00   0.00   0.00 
Average    0.00   0.00   0.00 

显示内容包括: 

ovsiohw/s:每秒在串口I/O硬件出现的溢出。 

ovsiodma/s:每秒在串口I/O的直接输入输出通道高速缓存出现的溢出。 

ovclist/s :每秒字符队列出现的溢出。 

在显示的内容中,每一列的值都是零,表明在采样时间内,系统中没有发生串口I/O溢出现象。 

 

Avatar_small
NCERT Chemistry Samp said:
Mon, 26 Sep 2022 01:03:08 +0800

Country level subject experts and teaching staff of leading educational institutes have prepared and suggested these NCERT 10th Class Chemistry Question Bank 2023 Pdf with Answers for all lessons in step by step solutions with detailed explanations. NCERT Chemistry Sample Paper Class 10 These exercises question banks are formulated by expert tutors based on the newly revised syllabus and curriculum for the listed topics.Country level subject experts and teaching staff of leading educational institutes have prepared and suggested these NCERT 10th Class Chemistry Question Bank 2023 Pdf.

Avatar_small
meidir said:
Tue, 25 Oct 2022 18:13:00 +0800

Its good as your other content : D, thankyou for posting . investing in defi

Avatar_small
meidir said:
Tue, 25 Oct 2022 20:40:04 +0800

I discovered your blog site internet site on the internet and appearance many of your early posts. Keep in the really good operate. I just now extra up your Feed to my MSN News Reader. Looking for toward reading more of your stuff down the line!… Get details

Avatar_small
meidir said:
Tue, 25 Oct 2022 21:29:01 +0800

I this way blog a whole lot, saved to my bookmarks. How to Get Google AdSense Approval

Avatar_small
meidir said:
Sat, 05 Nov 2022 21:31:53 +0800

Aw, this became an incredibly nice post. In concept I would like to put in writing similar to this moreover – taking time and actual effort to generate a very good article… but what can I say… I procrastinate alot and also by no indicates find a way to get something completed. Grand Wailea Resort Maui photographers

Avatar_small
meidir said:
Fri, 11 Nov 2022 03:59:08 +0800

I would also like to add that if you do not surely have an insurance policy or perhaps you do not participate in any group insurance, you could well benefit from seeking the assistance of a health insurance professional. Self-employed or people with medical conditions usually seek the help of the health insurance specialist. Thanks for your writing. Lasik treatment in Dubai

Avatar_small
meidir said:
Sun, 13 Nov 2022 20:37:17 +0800

Thank you for any other magnificent post. Where else could anyone get that type of information in such a perfect way of writing? I’ve a presentation subsequent week, and I’m at the search for such information. Crypto news

 

==============

 

I have really learned some new things through your blog post. Also a thing to I have noticed is that normally, FSBO sellers can reject an individual. Remember, they’d prefer to never use your expert services. But if you maintain a steady, professional romance, offering help and remaining in contact for about four to five weeks, you will usually have the capacity to win a meeting. From there, a listing follows. Thanks Buy Formuler Z10 Pro Max

Avatar_small
meidir said:
Tue, 15 Nov 2022 03:11:10 +0800

Hey there I am so excited I found your site, I really found you by accident, while I was browsing on Bing for something else, Regardless I am here now and would just like to say thank you for a incredible post and a all round entertaining blog (I also love the theme/design), I don’t have time to go through it all at the minute but I have saved it and also included your RSS feeds, so when I have time I will be back to read more, Please do keep up the excellent work. 金禾娛樂城

 

===============

 

This is a really good site post, I’m delighted I came across it. I’ll be back down the track to check out other posts that PSLE English tuition Singapore

 

===============

 

My partner and i bookmared your internet site a couple of days ago coz your blog impresses me personally. 뮤가라오케

Avatar_small
meidir said:
Wed, 16 Nov 2022 19:44:29 +0800

I just additional this particular feed to be able to my book marks. I need to say, I seriously take pleasure in reading your own sites. Keep it up! Restoration companies Spokane wa

 

===============

 

A cool article at that time partner ! Regards for that article . Water damage restoration Spokane wa

 

===============

 

Thanks, thanks for the awesome blog post. I’m having troubles subscribing to your blogs feed. Thought I’d let you know School of ministry

 

===============

 

It’s really a great and helpful piece of info. I am satisfied that you simply shared this useful information with us. Please stay us up to date like this. Thank you for sharing. Rent bounce house

 

====================

 

My brother suggested I would possibly like this website. He used to be entirely right. This post actually made my day. You can not imagine just how much time I had spent for this info! Thanks! Does God forgive all sins

 

======================

 

Can I recently say that of a relief to discover someone that actually knows what theyre talking about over the internet. You actually discover how to bring a challenge to light to make it important. The diet have to look at this and fully grasp this side Basement remodeling Spokane wa

 

======================

 

Somebody necessarily lend a hand to make significantly posts I would state. This is the very first time I frequented your website page and to this point? I surprised with the analysis you made to make this particular put up amazing. Excellent activity! Spokane basement remodel

 

=======================

 

Excellent line up. We will probably be linking to this great article on our web site. Keep up the great creating. bathroom remodeling spokane wa

 

===================

 

There couple of intriguing points soon enough in this article but I do not know if I see every one of them center to heart. There exists some validity but I will take hold opinion until I investigate it further. Good write-up , thanks therefore we want far more! Included in FeedBurner likewise bathroom remodeling contractors spokane wa

 

===================

 

Do you write more? It merely required a few moments to see your entry and so have an awareness that I know most people miss out on. Getting more people to join the discussion is usually a great thing. bathroom remodelers spokane wa

 

====================

 

I’d need to check with you here. Which isn’t some thing It’s my job to do! I like reading an article that will get people to feel. Also, appreciate your permitting me to comment! Home remodel Spokane

 

=====================

 

As far as me being a member here, I didnt even know that I was a member here. When the article was published I received a username and password, so that I could participate in Comments, That would explain me stumbuling upon this post. But we’re certainly all members in the world of ideas. Spokane home remodeling contractors

Avatar_small
meidir said:
Thu, 17 Nov 2022 20:49:01 +0800

Only a few blogger would discuss this topic the way you do. تمويل شخصي حتى لو عليك قرض

Avatar_small
meidir said:
Fri, 18 Nov 2022 05:43:35 +0800

of course data entry services are very expensive that is why always make a backup of your files:: safety deposit boxes for sale

 

=============

 

you got to work hard to earn lots of money because it is not very easy to earn,, vault rooms

 

=============

 

I’d ought to talk with you here. Which isn’t some thing It’s my job to do! I quite like reading a post that will get people to think. Also, thanks for permitting me to comment! bank vaults for sale

Avatar_small
meidir said:
Thu, 05 Oct 2023 21:21:35 +0800

I am curious to find out what blog system you have been utilizing? I’m having some minor security problems with my latest site and I would like to find something more secure. Do you have any solutions? 花藝設計


Login *


loading captcha image...
(type the code from the image)
or Ctrl+Enter