1. 通过检测系统,可以获取一些基准数据,进行分析,根据不同的业务特点系统不同组件的压力,可以有cpu密集型,内存密集型,网络吞吐密集性型,io密集型 
  2. 一  系统检测工具 
  3. FreeTop,ps,Vmstat,Sysstat 
  4. 二 Free工具的使用:用来查看linux系统中内存和缓存的状态 
  5. [root@hky-linux1 ~]# free 
  6.              total       used       free     shared    buffers     cached 
  7. Mem:        275756     208948      66808          0      16260     125608 
  8. -/+ buffers/cache:      67080     208676 
  9. Swap:      1028120          0    1028120 
  10. Total:物理内存总数 
  11. Used:总计分配给缓存使用的数量,其中部分缓存可能未被实际使用 
  12. Free:未被分配的内存数量,还有多少可用 
  13. Shared:多个进程共享的内存总额 
  14. Buffers :是在内存中准备写入磁盘的缓冲区,实现一次性批量写入,避免频繁写入 
  15. Cached:是从磁盘中读取的内容在内存中的缓存,为后续读取提供一种快速的访问方式 
  16. Mem(第二行):针对os的,buffers和cached都是被使用的,所以tatal=used+free 
  17.      [root@hky-linux1 ~]# echo $[208948+66808] 
  18. 275756 
  19. -/+ buffers/cached: 
  20. -buffers/cached:被程序实实在在吃掉的内存 
  21. + buffers/cached:可以挪用的内存 
  22. 所以total=used3+free3 
  23.     [root@hky-linux1 ~]# echo $[208676+67080] 
  24. 275756 
  25. Used2= buffers2+cached2+used3 
  26. [root@hky-linux1 ~]# echo $[16260+125608+67080] 
  27. 208948 
  28. Free3=buffers2+cached2+free2 
  29. [root@hky-linux1 ~]# echo $[16260+125608+66808] 
  30. 208676 
  31.    不做清除操作:0 
  32.    清除pagecache:1 
  33.    清除dentires和inodes:2 
  34.    清除dentires和inodes和pagecache:3 
  35. 清除缓存操作方法 
  36. 这里不得不介绍一下proc 
  37. Proc是一个虚拟文件系统是用户和内核之间实现通信的一种手段 
  38.    “取值”不做清除操作:0 
  39.    清除pagecache:1 
  40.    清除dentires和inodes:2 
  41.    清除dentires和inodes和pagecache:3、 
  42. Proc里的文件不能直接vi编辑,可以通过如下方法编辑 
  43. Echo [0,1,2,3] >/proc/sys/vm/drop_caches/ 
  44. 下面是我使用proc的实例 
  45. [root@hky vm]# free 
  46.              total       used       free     shared    buffers     cached 
  47. Mem:        255412     143964     111448    0        684      37396 
  48. -/+ buffers/cache:     105884     149528 
  49. Swap:      1020116          0    1020116 
  50. echo 1 > /proc/sys/vm/drop_caches 
  51. [root@hky vm]# free 
  52.              total       used       free     shared    buffers     cached 
  53. Mem:        255412     142912     112500    0        204      36788 
  54. -/+ buffers/cache:     105920     149492 
  55. Swap:      1020116          0    1020116 
  56. Buffer明显变小 
  57. echo 2 > /proc/sys/vm/drop_caches 
  58. [root@hky vm]# free 
  59.              total       used       free     shared    buffers     cached 
  60. Mem:        255412     143548     111864      0        588      37164 
  61. -/+ buffers/cache:     105796     149616 
  62. Swap:      1020116          0    1020116 
  63. 因为2不清除脏页,所以buffer有所上升 
  64. echo 3 > /proc/sys/vm/drop_caches 
  65. [root@hky vm]# free 
  66.              total       used       free     shared    buffers     cached 
  67. Mem:        255412     142808     112604          0        132      36768 
  68. -/+ buffers/cache:     105908     149504 
  69. Swap:      1020116          0    1020116 
  70. 看见没3效果最好 
  71. 注意: 
  72. 在执行清除缓存之前,必须手动执行sync 
  73.      1 sync命令 
  74. 运行sync子进程,将所有未写的系统缓冲区写入到磁盘中,包含已经修改的inode,保证文件系统的完整性 
  75.      2 sysnc在修改drop_caches的值,可以清除磁盘缓存,释放内存,得出真实的磁盘io 
  76.      3 清除磁盘缓存的另外一种方法就是执行sync后umount掉对应的磁盘分区设备 
  77. [root@hky-linux1 ~]# free;sync;free 
  78.              total       used       free     shared    buffers     cached 
  79. Mem:        275756     209728      66028    0      16928     125616 
  80. -/+ buffers/cache:      67184     208572 
  81. Swap:      1028120          0    1028120 
  82.              total       used       free     shared    buffers     cached 
  83. Mem:        275756     209756      66000   0      16936     125608 
  84. -/+ buffers/cache:      67212     208544 
  85. Swap:      1028120          0    1028120 
  86.  
  87. [root@hky-linux1 ~]# echo "3" > /proc/sys/vm/drop_caches 
  88. [root@hky-linux1 ~]# free 
  89.              total       used       free     shared    buffers     cached 
  90. Mem:        275756      83112     192644    0        200      19680 
  91. -/+ buffers/cache:      63232     212524 
  92. Swap:      1028120          0    1028120 
  93. 新命令:Last | more   //查看都有哪些用户登录 
  94. Top  –d  1  –n  1 > file 
  95. Strings file 
  96. 举例看看缓存的作用 
  97. [root@hky vm]# time find / >/dev/null 
  98. real    2m9.407s 
  99. user    0m0.231s 
  100. sys     0m7.445s 
  101. 用时2分钟多 
  102. Free 
  103. [root@hky vm]# free 
  104.              total       used       free     shared    buffers     cached 
  105. Mem:        255412     231016      24396     0      77620      37452 
  106. -/+ buffers/cache:     115944     139468 
  107. Swap:      1020116          0    1020116 
  108. Cached变的很大 
  109. 现在重复执行 
  110. [root@hky vm]# time find / >/dev/null 
  111. real    0m2.538s 
  112. user    0m0.445s 
  113. sys     0m1.092s 
  114. 用时两秒; 
  115. echo "3" > /proc/sys/vm/drop_caches 
  116. [root@hky vm]# free 
  117.              total       used       free     shared    buffers     cached 
  118. Mem:        255412     144052     111360          0        188      36800 
  119. -/+ buffers/cache:     107064     148348 
  120.  
  121. Swap:      1020116          0    1020116 
  122.  
  123. [root@hky vm]# time find / >/dev/null 
  124. real    1m29.158s 
  125. user    0m0.195s 
  126. sys     0m5.109s 
  127.   Free命令有用的参数: 
  128.     引用 
  129.     ·-b,-k,-m和-g分别按照bytes, kilobytes, megabytes, gigabytes显示结果。 
  130.     ·-l区别显示low和high内存 
  131.     ·-s 每隔若干秒刷新一次 
  132.  
  133. 三 Vmstat 
  134. vmstat命令是显示Linux性能指标的方法,输出分为6个类别:进程、内存、交换区、I/O、系统和CPU 
  135. [root@hky-linux1 ~]# vmstat 
  136. 进程        内存         交换分区  io     系统      cpu 
  137. procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----     - 
  138.  r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs   us  sy id   wa st 
  139.  0  0    0    190212 872  21760    0    0    42   14  1043  106  1  1  97  1  0 
  140. 进程: 
  141. r列是可运行进程的数量,长期大于1,cpu不足,当业务繁忙时,不超过两倍的cpu数量,也算正常,r越大,系统越繁忙 
  142. b列是阻塞进程的数量:正常小为0 
  143. 内存:Swpd:已用的交换空间数量 
  144. Free:尚未分配的内存 
  145. Buff:缓冲使用的内存,对块设备读写才需要缓冲 
  146. Cache:文件系统缓存使用的, 
  147. Swap:si和so为0是正常的 
  148. Si:从交换区到内存的数量 
  149. So:从内存到交换区的数量 
  150. I/O 
  151. Bi:从磁盘读去的块数,数量越大,表示读取的越频繁 
  152. Bo:每秒写入到磁盘的块数。数量越大,磁盘活动率越高 
  153. System 
  154. In:系统中断 
  155. Cs:进程上下文开关 
  156. Cpu 
  157. Us:用户进程消耗—值比较高,则用户进程消耗cpu时间太长,长期大于50%,考虑优化用户程序,持续大于50,业务高峰期算是正常 
  158. Sy:内核进程消耗—us+sy大于80%,则cpu不足 
  159. Wa:I/O进程消耗的cpu,超过30%,可能由磁盘大量随即访问造成 
  160. Id:空闲,持续小于50,服务高峰期可以接受 
  161. [root@hky-linux1 ~]# vmstat 2 5    //每两秒查看一次,查看五次 
  162. procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------ 
  163.  r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st 
  164.  0  0      0 127740  21412  54752    0    0    42    13 1041  105  0  1 97  1  0 
  165.  0  0      0 127500  21412  54752    0    0     0     0 1015  105  1  3 96  0  0 
  166.  0  0      0 127500  21412  54752    0    0     0     0 1015   93  0  0 100  0  0 
  167.  0  0      0 127560  21420  54752    0    0     0    34 1015   94  0  1 99  0  0 
  168.  0  0      0 127560  21420  54752    0    0     0     0 1014   93  0  1 99  0  0 
  169. 现在测试一下查看5次,每次2秒用多少时间 
  170. [root@hky ~]# time vmstat 2 5 
  171. procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------ 
  172.  r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st 
  173.  0  0    116  18784  32052  88552    0    0    49    20  710  119  2  4 91  3  0 
  174.  0  0    116  18784  32052  88552    0    0     0     0  609   62  0  1 99  0  0 
  175.  0  0    116  18784  32052  88552    0    0     0    44  627   71  0  0 100  0  0 
  176.  0  0    116  18784  32068  88552    0    0     0    24  624   79  0  1 97  2  0 
  177.  0  0    116  18784  32068  88552    0    0     0     0  614   71  0  0 100  0  0 
  178.   
  179. real    0m8.016s 
  180. user    0m0.002s 
  181. sys     0m0.003s 
  182. 用时8秒,因为第一次不要时间 
  183. 这里有一个时间函数需要掌握 
  184. [root@hky ~]# ceshi=$(date +%s.%N);vmstat 2 3;hky=$(date +%s.%N); awk -v ceshi=${ceshi} -v hky=${hky} 'BEGIN {print hky-ceshi}' 
  185. procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------ 
  186.  r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st 
  187.  0  0    116  14580  34872  89084    0    0    46    19  706  117  1  4 92  3  0 
  188.  0  0    116  14580  34880  89076    0    0     0    18  596   76  0  1 99  0  0 
  189.  0  0    116  14580  34880  89088    0    0     0     0  589   67  0  0 100  0  0 
  190. 4.01254 
  191. 大家自己理解 
  192. Vmstat-a  看出内存使用的和未使用的 
  193. [root@hky ~]# vmstat -a 
  194. procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------ 
  195.  r  b   swpd   free  inact active   si   so    bi    bo   in   cs us sy id wa st 
  196.  0  0    116  14400  70408 143008    0    0    46    19  706  117  1  4 92  3  0 
  197. Vmstat –d : 硬盘读写情况 
  198. [root@hky ~]# vmstat -d 
  199. disk- ------------reads------------ ------------writes----------- -----IO------ 
  200.        total merged sectors      ms  total merged sectors      ms    cur    sec 
  201. ram0       0      0       0       0      0      0       0       0      0      0 
  202. ram1       0      0       0       0      0      0       0       0      0      0 
  203. ram2       0      0       0       0      0      0       0       0      0      0 
  204. ram3       0      0       0       0      0      0       0       0      0      0 
  205. ram4       0      0       0       0      0      0       0       0      0      0 
  206. ram5       0      0       0       0      0      0       0       0      0      0 
  207. ram6       0      0       0       0      0      0       0       0      0      0 
  208. ram7       0      0       0       0      0      0       0       0      0      0 
  209. ram8       0      0       0       0      0      0       0       0      0      0 
  210. ram9       0      0       0       0      0      0       0       0      0      0 
  211. ram10      0      0       0       0      0      0       0       0      0      0 
  212. ram11      0      0       0       0      0      0       0       0      0      0 
  213. ram12      0      0       0       0      0      0       0       0      0      0 
  214. ram13      0      0       0       0      0      0       0       0      0      0 
  215. ram14      0      0       0       0      0      0       0       0      0      0 
  216. ram15      0      0       0       0      0      0       0       0      0      0 
  217. sda    90558  27351 1569858  606361  25774  55985  653314  776684      0    512 
  218. sdb      115    464    2272     229     30     20     100     299      0      0 
  219. hdc      701     10    2920     310      0      0       0       0      0      0 
  220. fd0        0      0       0       0      0      0       0       0      0      0 
  221. disk- ------------reads------------ ------------writes----------- -----IO------ 
  222.        total merged sectors      ms  total merged sectors      ms    cur    sec 
  223. md0        0      0       0       0      0      0       0       0      0      0 
  224. loop0      0      0       0       0      0      0       0       0      0      0 
  225. loop1      0      0       0       0      0      0       0       0      0      0 
  226. loop2      0      0       0       0      0      0       0       0      0      0 
  227. loop3      0      0       0       0      0      0       0       0      0      0 
  228. loop4      0      0       0       0      0      0       0       0      0      0 
  229. loop5      0      0       0       0      0      0       0       0      0      0 
  230. loop6      0      0       0       0      0      0       0       0      0      0 
  231. loop7      0      0       0       0      0      0       0       0      0      0 
  232. Vmstat –p /dev/sdb2  1 某一块盘的读写情况 
  233. 四 Sysstay工具 
  234.  Iostat /sar /mpstat 三个工具都来自Sysstay包 
  235. 安装sysstat很简单 
  236.  [root@hky-linux1 sysstat]# rpm -ivh sysstat-9.0.6.1-3.i386.rpm-----安装 
  237. Sar收集器 /var/log/sa 
  238. 修改配置文件 
  239. [root@hky-linux1 ~]# vi /etc/cron.d/sysstat 
  240. # Run system activity accounting tool every 10 minutes 
  241. */10 * * * * root /usr/lib/sa/sa1 -S DISK 10  60 
  242. # 0 * * * * root /usr/lib/sa/sa1 -S DISK 600 6 & 
  243. # Generate a daily summary of process accounting at 23:53 
  244. 59 23 * * * root /usr/lib/sa/sa2 –A 
  245. [root@hky-linux1 ~]# vi /etc/sysconfig/sysstat 
  246. # sysstat-9.0.6.1 configuration file. 
  247. # How long to keep log files (in days). 
  248. # If value is greater than 28, then log files are kept in 
  249. # multiple directories, one for each month
  250. HISTORY=7000 
  251. # Compress (using gzip or bzip2) sa and sar files older than (in days): 
  252. COMPRESSAFTER=3 
  253. 统计cpu信息 
  254. [root@hky-linux1 ~]# sar -u 
  255. Linux 2.6.18-53.el5 (hky-linux1)        07/01/2010      _i686_  (1 CPU) 
  256. 06:30:02 AM     CPU     %user     %nice   %system   %iowait    %steal     %idle 
  257. 06:40:01 AM     all      0.04      0.00      0.48      0.13      0.00     99.35 
  258. 06:50:01 AM     all      0.05      0.00      0.50      0.15      0.00     99.30 
  259. 07:00:01 AM     all      0.05      0.00      0.60      0.46      0.00     98.90 
  260. 07:10:01 AM     all      0.09      0.00      0.65      0.51      0.00     98.76 
  261. 07:20:01 AM     all      0.04      0.20      1.59      4.55      0.00     93.63 
  262. 07:30:01 AM     all      0.06      0.00      0.57      0.28      0.00     99.08 
  263. Average:        all      0.05      0.03      0.73      1.01      0.00     98.17 
  264. Cpu 
  265. All: 表示统计信息为所有 CPU 的平均值 
  266. %user:用户运行进程所花的时间 
  267. %nice:运行正常进程所花的时间 
  268. %system:在内核模式中运行进程所花的时间 
  269. %iowait:没有进程在该CPU上执行时,处理器等待I/O完成的时间 
  270. %steal 管理程序(hypervisor)为另一个虚拟进程提供服务而等待虚拟 CPU 的百分比 
  271. %idle:没有进程在该CPU上执行的时间 
  272. 查看报告 
  273. [root@hky-linux1 sa]# sar -f /var/log/sa/sa01 
  274. Linux 2.6.18-53.el5 (hky-linux1)        07/01/2010      _i686_  (1 CPU) 
  275. 06:30:02 AM     CPU     %user     %nice   %system   %iowait    %steal     %idle 
  276. 06:40:01 AM     all      0.04      0.00      0.48      0.13      0.00     99.35 
  277. 06:50:01 AM     all      0.05      0.00      0.50      0.15      0.00     99.30 
  278. 07:00:01 AM     all      0.05      0.00      0.60      0.46      0.00     98.90 
  279. 在多cpu的系统中,查看分解的cpu信息 
  280. [root@hky-linux1 sa]# sar -u -P ALL 5 5 
  281. Linux 2.6.18-53.el5 (hky-linux1)        07/01/2010      _i686_  (1 CPU) 
  282. 07:38:51 AM     CPU     %user     %nice   %system   %iowait    %steal     %idle 
  283. 07:38:56 AM     all      0.00      0.00      0.80      0.00      0.00     99.20 
  284. 07:38:56 AM       0      0.00      0.00      0.80      0.00      0.00     99.20 
  285. 磁盘io数据统计 
  286. [root@hky-linux1 ~]# sar -d 5 2 
  287. Linux 2.6.18-53.el5 (hky-linux1)        07/01/2010      _i686_  (1 CPU) 
  288. 07:40:36 AM       DEV       tps  rd_sec/s  wr_sec/s  avgrq-sz  avgqu-sz     await     svctm     %util 
  289. 07:40:41 AM    dev8-0      0.00      0.00      0.00      0.00      0.01      0.00      0.00      0.54 
  290. 07:40:41 AM   dev8-16      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00 
  291. 07:40:41 AM   dev8-32      0.00      0.00      0.00      0.00      0.00      0.00   
  292. DEV:磁盘设备 
  293. Tps:每秒传输数 
  294. rd_sec/s:每秒xx字节读取数 
  295. wr_sec/s:每秒xx字节写入数 
  296. 显示io和传送速率的信息 
  297. [root@hky-linux1 ~]# sar -b 5 3 
  298. Linux 2.6.18-53.el5 (hky-linux1)        07/01/2010      _i686_  (1 CPU) 
  299. 07:53:25 AM       tps      rtps      wtps   bread/s   bwrtn/s 
  300. 07:53:30 AM      0.00      0.00      0.00      0.00      0.00 
  301. 07:53:35 AM      1.00      0.00      1.00      0.00     25.60 
  302. 07:53:40 AM      0.00      0.00      0.00      0.00      0.00 
  303. Average:         0.33      0.00      0.33      0.00      8.54 
  304. tps 每秒钟物理设备的 I/O 传输总量 
  305. rtps 每秒钟从物理设备读入的数据总量 
  306. wtps 每秒钟向物理设备写入的数据总量 
  307. bread/s 每秒钟从物理设备读入的数据量,单位为 块/s 
  308. bwrtn/s 每秒钟向物理设备写入的数据量,单位为 块/s 
  309. 显示内存页面统计 
  310. [root@hky-linux1 ~]# sar -B 5 
  311. Linux 2.6.18-53.el5 (hky-linux1)        07/01/2010      _i686_  (1 CPU) 
  312. 07:55:26 AM  pgpgin/s pgpgout/s   fault/s  majflt/s  pgfree/s pgscank/s pgscand/s pgsteal/s    %vmeff 
  313. 07:55:31 AM      0.00      8.02     15.83      0.00     15.63      0.00      0.00      0.00      0.00 
  314. 07:55:36 AM      0.00      6.45     11.69      0.00     25.20      0.00      0.00      0.00      0.00 
  315. pgpgin/s 每秒钟从磁盘读入的系统页面的 KB 总数 
  316. pgpgout/s 每秒钟向磁盘写出的系统页面的 KB 总数 
  317. fault/s 系统每秒产生的页面失效(major + minor)数量 
  318. majflt/s 系统每秒产生的页面失效(major)数量 
  319. 每秒创建的进程数的进程统计 
  320. [root@hky-linux1 ~]# sar -C 5 3 
  321. Linux 2.6.18-53.el5 (hky-linux1)        07/01/2010      _i686_  (1 CPU) 
  322. 07:57:12 AM     CPU     %user     %nice   %system   %iowait    %steal     %idle 
  323. 07:57:17 AM     all      0.21      0.00      2.06      0.82      0.00     96.91 
  324. 07:57:22 AM     all      0.00      0.00      0.60      0.20      0.00     99.19 
  325. 网络信息统计 
  326. [root@hky-linux1 ~]# sar -n DEV 5 3 |grep eth0 
  327. 07:58:22 AM      eth0      0.40      0.20      0.02      0.01      0.00      0.00      0.00 
  328. 07:58:27 AM      eth0      0.20      0.20      0.01      0.04      0.00      0.00      0.00 
  329. [root@hky-linux1 ~]# sar -n DEV 5 3 
  330. Linux 2.6.18-53.el5 (hky-linux1)        07/01/2010      _i686_  (1 CPU) 
  331. 07:45:44 AM     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s 
  332. 07:45:49 AM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00 
  333. 07:45:49 AM      eth0      0.20      0.20      0.01      0.03      0.00      0.00      0.00 
  334. 07:45:49 AM      sit0      0.00      0.00      0.00      0.00      0.00      0.00      0.00 
  335. IFACE:LAN接口 
  336. rxpck/s:每秒钟接收的数据包 
  337. txpck/s:每秒钟发送的数据包 
  338. rxbyt/s:每秒钟接收的字节数 
  339. txbyt/s:每秒钟发送的字节数 
  340. rxcmp/s:每秒钟接收的压缩数据包 
  341. txcmp/s:每秒钟发送的压缩数据包 
  342. rxmcst/s:每秒钟接收的多播数据包 
  343. 网络错误信息统计 
  344. [root@hky-linux1 ~]# sar -n EDEV 5 3 
  345. Linux 2.6.18-53.el5 (hky-linux1)        07/01/2010      _i686_  (1 CPU) 
  346. 07:48:24 AM     IFACE   rxerr/s   txerr/s    coll/s  rxdrop/s  txdrop/s  txcarr/s  rxfram/s  rxfifo/s  txfifo/ 
  347. 07:48:29 AM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00 
  348. 07:48:29 AM      eth0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00 
  349. 07:48:29 AM      sit0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00 
  350. [root@hky-linux1 ~]# sar -n EDEV 5 |egrep 'eth0|IFACE' 
  351. 07:59:16 AM     IFACE   rxerr/s   txerr/s    coll/s  rxdrop/s  txdrop/s  txcarr/s  rxfram/s  rxfifo/s  txfifo/s 
  352. 07:59:21 AM      eth0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00 
  353. IFACE:LAN接口 
  354. rxerr/s:每秒钟接收的坏数据包 
  355. txerr/s:每秒钟发送的坏数据包 
  356. coll/s:每秒冲突数 
  357. rxdrop/s:因为缓冲充满,每秒钟丢弃的已接收数据包数 
  358. txdrop/s:因为缓冲充满,每秒钟丢弃的已发送数据包数 
  359. txcarr/s:发送数据包时,每秒载波错误数 
  360. rxfram/s:每秒接收数据包的帧对齐错误数 
  361. rxfifo/s:接收的数据包每秒FIFO过速的错误数 
  362. txfifo/s:发送的数据包每秒FIFO过速的错误数 
  363.  
  364. dstat工具,可以做更多的信息采集 
  365.    安装 
  366.    [root@hky-linux1 Server]# rpm -ivh dstat-0.6.6-3.el5_4.1.noarch.rpm 
  367. warning: dstat-0.6.6-3.el5_4.1.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 37017186 
  368. Preparing...                ########################################### [100%] 
  369.    1:dstat                  ########################################### [100%] 
  370.    执行 dstat 命令,默认情况它会收集-cpu-、-disk-、-net-、-paging-、-system-的数据,一秒钟收集一次 
  371.   语法结构:dstat [-afv] [options..] [delay [count]] 
  372. Dstat  -c 检测cpu的情况 
  373. [root@hky-linux1 ~]# dstat -c 
  374. ----total-cpu-usage---- 
  375. usr sys idl wai hiq siq 
  376.   2   4  90   4   0   0 
  377.   0   0 100   0   0   0 
  378.   0   0 100   0   0   0 
  379. Dstat  -d 检测硬盘读写情况 
  380. [root@hky-linux1 ~]# dstat -d 
  381. -dsk/total- 
  382.  read  writ 
  383.  212k   47k 
  384.    0     0 
  385.    0     0 
  386. 0           184k 
  387. Dstat  -m检测内存使用情况 
  388. [root@hky-linux1 ~]# dstat -m 
  389. ------memory-usage----- 
  390.  used  buff  cach  free 
  391.   69M   30M  120M   50M 
  392.   69M   30M  120M   50M 
  393.   69M   30M  120M   50M 
  394.   69M   30M  120M   50M 
  395. Dstat  -n 检测网络使用状况 
  396. [root@hky-linux1 ~]# dstat -n 
  397. -net/total- 
  398.  recv  send 
  399.    0     0 
  400.   60B  138B 
  401.   60B  154B 
  402. [root@hky-linux1 ~]# dstat -N eth0,total 
  403. Terminal width too small, trimming output
  404. ----total-cpu-usage---- -dsk/total- --net/eth0---net/total- ---paging--> 
  405. usr sys idl wai hiq siq| read  writ| recv  send: recv  send|  in   out > 
  406.   1   2  93   3   0   0| 140k   36k|   0     0 :   0     0 |   0     0 > 
  407.   0   0 100   0   0   0|   0     0 |  60B  314B:  60B  314B|   0     0 > 
  408.   0   0  99   0   0   1|   0     0 |  60B  314B:  60B  314B|   0     0 > 
  409. [root@hky-linux1 ~]#  dstat -dnyc -N eth0 -C total -f 5 
  410. Terminal width too small, trimming output
  411. --dsk/hda-----dsk/sda-----dsk/sdb-----dsk/sdc-- --net/eth0- ---system--> 
  412.  read  writ: read  writ: read  writ: read  writ| recv  send| int   csw > 
  413.  537B    0 : 116k   32k:1252B    0 :1354B    0 |   0     0 |1017   112 > 
  414.    0     0 :   0     0 :   0     0 :   0     0 |  60B  314B|1005    79 > 
  415. [root@hky-linux1 ~]#  dstat -M time,cpu,net,disk,sys,load,proc,app 
  416. Terminal width too small, trimming output
  417. -----time----- ----total-cpu-usage---- -net/total- -dsk/total- ---system--> 
  418.   date/time   |usr sys idl wai hiq siq| recv  send| read  writ| int   csw > 
  419. 04-07 01:03:00|  1   2  94   2   0   0|   0     0 | 113k   31k|1016   111 > 
  420. 04-07 01:03:01|  0   3  96   1   0   0|  60B  420B|   0     0 |1008    94 > 
  421. 04-07 01:03:02|  1   1  96   2   0   0|  60B  420B|   0   380k|1036    82 > 
  422. ……………………….. 
  423. [root@hky-linux1 ~]# man dstat 
  424. Iptraf的使用:流量监控工具 
  425. 安装 
  426. Yum –y install iptraf 
  427. [root@hky-linux1 ~]# iptraf -d eth0  //检测eth0 inout的数据包 
  428. 掌握tcpdump的使用 
  429. [root@hky-linux1 ~]# tcpdump -nn -vv dst net 192.168.1.0/24 and not port 22 
  430. [root@hky-linux1 ~]# tcpdump  -nn -vv -i eth0 icmp 
  431. tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes 
  432. 01:37:31.691978 IP (tos 0x0, ttl 128, id 10925, offset 0, flags [none], proto: ICMP (1), length: 60) 192.168.1.101 > 192.168.1.6: ICMP echo request, id 1, seq 5338, length 40 
  433. 01:37:31.692256 IP (tos 0x0, ttl  64, id 34721, offset 0, flags [none], proto: ICMP (1), length: 60) 192.168.1.6 > 192.168.1.101: ICMP echo reply, id 1, seq 5338, length 40 
  434. Strace工具:跟踪程式执行时的系统调用和所接收的信号 
  435. [root@hky-linux1 ~]# man strace 
  436. STRACE(1)                                                            STRACE(1) 
  437. NAME 
  438.        strace - trace system calls and signals 
  439. SYNOPSIS 
  440.        strace  [  -dffhiqrtttTvxx  ] [ -acolumn ] [ -eexpr ] ...  [ -ofile ] [ 
  441.        -ppid ] ...  [ -sstrsize ] [ -uusername ] [ -Evar=val ] ...  [ -Evar  ] 
  442.        ...  [ command [ arg ...  ] ] 
  443.       strace  -c  [ -eexpr ] ...  [ -Ooverhead ] [ -Ssortby ] [ command [ arg 
  444.        ...  ] ] 
  445. 参数: 
  446. -c 统计每一系统调用的所执行的时间,次数和出错的次数等 
  447. [root@hky-linux1 ~]# strace -c pwd 
  448. /root 
  449. time     seconds  usecs/call     calls    errors syscall 
  450. ------ ----------- ----------- --------- --------- ---------------- 
  451.  66.08    0.000596         596         1           execve 
  452.  14.86    0.000134          17         8           mmap2 
  453.   6.76    0.000061          20         3           brk 
  454.   6.76    0.000061          31         2           fcntl64 
  455.   5.54    0.000050          25         2           munmap 
  456.   0.00    0.000000           0         1           read 
  457.   0.00    0.000000           0         1           write 
  458.   0.00    0.000000           0         3           open 
  459.   0.00    0.000000           0         5           close 
  460.   0.00    0.000000           0         1         1 access 
  461.   0.00    0.000000           0         2           mprotect 
  462.   0.00    0.000000           0         2           lstat64 
  463.   0.00    0.000000           0         6           fstat64 
  464.   0.00    0.000000           0         1           getdents64 
  465.   0.00    0.000000           0         1           set_thread_area 
  466.   0.00    0.000000           0         1           openat 
  467.   0.00    0.000000           0         1           fstatat64 
  468. ------ ----------- ----------- --------- --------- ---------------- 
  469. 100.00    0.000902                    41         1 total 
  470. -d 输出strace关于标准错误的调试信息 
  471. -f 跟踪由fork调用所产生的子进程 
  472. -ff 如果提供-o filename,则所有进程的跟踪结果输出到相应的filename.pid中,pid是各进程的进程号 
  473. -F 尝试跟踪vfork调用.在-f时,vfork不被跟踪 
  474. -h 输出简要的帮助信息 
  475. -i 输出系统调用的入口指针 
  476. -q 禁止输出关于脱离的消息 
  477. -r 打印出相对时间关于,,每一个系统调用 
  478. -t 在输出中的每一行前加上时间信息 
  479. -tt 在输出中的每一行前加上时间信息,微秒级 
  480. -ttt 微秒级输出,以秒了表示时间 
  481. -T 显示每一调用所耗的时 
  482. -v 输出所有的系统调用.一些调用关于环境变量,状态,输入输出等调用由于使用频繁,默认不输出 
  483. -V 输出strace的版本信息 
  484. -x 以十六进制形式输出非标准字符串 
  485. -xx 所有字符串以十六进制形式输出 
  486. -a column 
  487. 五 制造系统压力 
  488. [root@hky-linux1 ~]#  S=1000; echo "scale=${S}; 4*a(1)" | bc -l -q 
  489. Vmstat的一个脚本 
  490. [root@hky-linux1 ~]# vmstat 1 2 | grep -v sw | awk '{print $0; for (i=1;i<=NF;i++){r[i]+=$i}}END {for(i=1;i<=NF;i++){printf"%d",r[i]/NR;printf("\n")}}'