I/O、内存、网络性能优化命令 iostat , vmstat,netstat

原贴地址:http://www.qqread.com/solaris/v225295.html

I/O、内存、网络性能优化命令 iostat , vmstat,netstat

来源: 作者: 出处:巧巧读书  2006-10-09  进入讨论组
关 键 词: 数据结构   vc   os   opera   ie  

  是在sun网站上看到的,原文是e文,连接如下:
http://www.adminschoice.com/docs/iostat_vmstat_netstat.htm

大概翻译了一下,总觉得好像以前哪位大大贴过类似的
不管了,觉得有点用,大家一起看看

width="300" scrolling="no" height="250" frameborder="0" allowtransparency="true" hspace="0" vspace="0" marginheight="0" marginwidth="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-1572879403720716&dt=1188313475668&hl=zh-CN&lmt=1185339196&alternate_ad_url=http%3A%2F%2Fwww.qqread.com%2F0000js%2Fgoogle300.htm&prev_fmts=336x280_as&format=300x250_as&output=html&correlator=1188313475619&channel=6686853775&pv_ch=6686853775%2B&url=http%3A%2F%2Fwww.qqread.com%2Fsolaris%2Fv225295.html&color_bg=EFF5FF&color_text=323232&color_link=6183BA&color_url=888888&color_border=EFF5FF&ad_type=text_image&ref=http%3A%2F%2Fwww.google.cn%2Fsearch%3Fq%3Dlinux%2Biostat%26complete%3D1%26hl%3Dzh-CN%26newwindow%3D1%26start%3D30%26sa%3DN&cc=100&ga_vid=620485682.1188313476&ga_sid=1188313476&ga_hid=220138613&flash=9&u_h=800&u_w=1280&u_ah=776&u_aw=1280&u_cd=24&u_tz=480&u_his=1&u_nplug=2&u_nmime=3" name="google_ads_frame">
翻译得不好,见笑了……如果有错,请指正哦,先谢了

Input Output statistics ( iostat )

iostat反映了终端、磁盘I/O情况和CPU活动。输出结果的第一行是从系统启动到现在为止的这段 时间 的结果,接下去的每一行是interval时

间段内的结果。Kernel里有一组计数器用来跟踪这些值。
iostat的默认参数是tdc(terminal, disk, and CPU)。如果任何其他的选项被指定,这个默认参数将被完全替代,例如,iostat -d将只反

映磁盘的统计结果。

语法:

基本语法: iostat <options> interval count

option - 让你指定所需信息的 设备 ,像磁盘、cpu或者终端(-d , -c , -t or -tdc ) 。x 选项给出了完整的统计结果(gives the extended

statistic)。

interval - 在两个samples之间的时间(秒)。

count - 就是需要统计几次

例子:

$ iostat -xtc 5 2
extended disk statistics tty cpu
disk r/s w/s Kr/s Kw/s wait actv svc_t %w %b tin tout us sy wt id
sd0 2.6 3.0 20.7 22.7 0.1 0.2 59.2 6 19 0 84 3 85 11 0
sd1 4.2 1.0 33.5 8.0 0.0 0.2 47.2 2 23
sd2 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0
sd3 10.2 1.6 51.4 12.8 0.1 0.3 31.2 3 31


The fields have the following meanings:

disk name of the disk
r/s reads per second
w/s writes per second
Kr/s kilobytes read per second
Kw/s kilobytes written per second
wait average number of transactions waiting for service (Q length)
actv average number of transactions actively
being serviced (removed from the
queue but not yet
completed)
%w percent of time there are transactions waiting
for service (queue non-empty)
%b percent of time the disk is busy (transactions
in progress)




Results and Solutions:

从iostat输出结果中需要注意的值:

Reads/writes per second (r/s , w/s)
Percentage busy (%b)
Service time (svc_t)

如果磁盘显示长时间的高reads/writes,并且磁盘的percentage busy (%b)也远大于5%,同时average service time (svc_t)也远大于30

milliseconds,这以下的措施需要被执行:
1.)调整应用,令其使用磁盘i/o更加有效率,可以通过修改磁盘队列、使用应用服务器的cache

2.)将文件 系统 分布到2个或多个磁盘上,并使用volume manager/disksuite的条带化特点

3.) 增加系统参数值,如inode cache , ufs_ninode。Increase the system parameter values for inode cache , ufs_ninode , which

is Number of inodes to be held in memory. Inodes are cached globally (for UFS), not on a per-file system basis

4.) 将文件系统移到更快的磁盘/控制器,或者用更好的设备来代替

还有两段等会翻好了再贴……

Virtual Memory Statistics ( vmstat )

vmstat - vmstat反映了进程的虚拟 内存 、虚拟内存、磁盘、trap(是不是翻译成中断??)和cpu的活动情况

在多cpu系统中,vmstat在输出结果中平均了cpu数量。For per-process statistics .如果没有选项,vmstat显示一行虚拟内存活动的概要

结果,是从系统启动时开始的。

语法:

vmstat <options> interval count

option - 让你指定所需的信息类型,例如 paging -p , cache -c ,.interrupt -i etc.

如果没有指定选项,将会显示进程、内存、页、磁盘、中断和cpu信息

interval - 同iostat

count - 同iostat

例子
The following command displays a summary of what the system
is doing every five seconds.

example% vmstat 5
procs memory page disk faults cpu
r b w swap free re mf pi p fr de sr s0 s1 s2 s3 in sy cs us sy id
0 0 0 11456 4120 1 41 19 1 3 0 2 0 4 0 0 48 112 130 4 14 82
0 0 1 10132 4280 0 4 44 0 0 0 0 0 23 0 0 211 230 144 3 35 62
0 0 1 10132 4616 0 0 20 0 0 0 0 0 19 0 0 150 172 146 3 33 64
0 0 1 10132 5292 0 0 9 0 0 0 0 0 21 0 0 165 105 130 1 21 78




The fields of vmstat's display are
procs
r in run queue
b blocked for resources I/O, paging etc.
w swapped

memory (in Kbytes)
swap - amount of swap space currently available
free - size of the free list

page ( in units per second).
re page reclaims - see -S option for how this field is modified.
mf minor faults - see -S option for how this field is modified.
pi kilobytes paged in
po kilobytes paged out
fr kilobytes freed
de anticipated short-term memory shortfall (Kbytes)
sr pages scanned by clock algorithm

disk ( operations per second )
There are slots for up to four disks, labeled with a single letter and number.
The letter indicates the type of disk (s = SCSI, i = IPI, etc) . The number is
the logical unit number.

faults
in (non clock) device interrupts
sy system calls
cs CPU context switches

cpu - breakdown of percentage usage of CPU time. On multiprocessors this is an a
verage across all processors.
us user time
sy system time
id idle time

结果和解决方案:

A. CPU issues:

下面几列需要被察看,以确定cpu是否有问题

Processes in the run queue (procs r)
User time (cpu us)
System time (cpu sy)
Idle time (cpu id)
procs cpu
r b w us sy id
0 0 0 4 14 82
0 0 1 3 35 62
0 0 1 3 33 64
0 0 1 1 21 78



问题情况:
1.) 如果processes in run queue (procs r)的数量远大于系统中cpu的数量,将会使系统便慢。
2.) 如果这个数量是cpu的4倍的话,说明系统正面临cpu能力短缺,这将使系统运行速度大幅度降低
3.) 如果cpu的idle时间经常为0的话,或者系统占用时间(cpu sy)是用户占用时间(cpu us)两辈的话,系统面临缺少cpu资源

解决方案 :
解决这些情况,涉及到调整应用程序,使其能更有效的使用cpu,同时增加cpu的能力或数量。

B. Memory Issues:
内存的瓶颈取决于scan rate (sr) 。scan rate是每秒时钟对页的扫描 (he scan rate is the pages scanned by the clock algorithm per

second.)如果 scan rate (sr)一直大于200 pages每秒,这时就是内存短缺的现实。

解决方案 :
1. 调整应用和 服务 器,使其能更好的使用memory和cache
2. 增加系统内存
3. Implement priority paging in s in pre solaris 8 versions by adding line "set priority paging=1" in
/etc/system. Remove this line if upgrading from Solaris 7 to 8 & retaining old /etc/system file.

Network Statistics (netstat)

netstat通过选项来显示不通的 网络 相关的 数据结构(netstat displays the contents of various network-related data structures

in depending on the options selected.)

语法 :

netstat <option/s>

多个选项可以同时使用

Options

-a - displays the state of all sockets.
-r - shows the system routing tables
-i - gives statistics on a per-interface basis.
-m - displays information from the network memory buffers. On Solaris, this shows statistics
forSTREAMS
-p [proto] - retrieves statistics for the specified protocol
-s - shows per-protocol statistics. (some implementations allow -ss to remove fileds with a value of 0 (zero) from the

display.)
-D - display the status of DHCP configured interfaces. <
 
<think>好的,我现在需要帮助用户解决关于Ubuntu系统中磁盘I/O日志存储位置及查看方法的问题。首先,我要确认用户的需求是什么。他们想了解在哪里可以找到磁盘I/O相关的日志,以及有哪些工具或方法可以用来查看这些信息。用户提到了dmesg和iostat,可能已经知道这两个工具,但需要更详细的指导。 首先,我应该回忆一下Ubuntu系统中常见的日志位置。系统日志通常存放在/var/log目录下,比如syslog、kern.log等。这些日志文件可能会记录磁盘I/O相关的错误或警告信息。用户可能需要知道具体是哪个文件,所以需要明确说明路径。 接下来是工具部分。用户提到了dmesg和iostat,这两个确实是常用的工具。dmesg用于查看内核环缓冲区中的消息,包括硬件和驱动相关的信息,而iostat属于sysstat包,可以提供磁盘I/O的统计信息。除此之外,还有一些其他工具如iotop、pidstat、dstat、fio等,用户可能也需要了解这些工具的使用方法,以全面监控和分析I/O性能。 需要检查每个工具的具体用法,比如iostat需要安装sysstat,并且可能需要更新间隔和次数参数。dmesg可以通过管道配合grep过滤出相关消息。另外,像iotop这样的工具可以实时显示进程的I/O使用情况,帮助定位高I/O的进程。 用户还可能希望知道如何安装这些工具,比如sysstat的安装命令是sudo apt-get install sysstat,fio的安装方法等。此外,基准测试工具如fio的使用步骤也需要简要说明,以便用户进行性能测试。 在引用部分,需要根据提供的参考资料,正确标注引用标识。例如,pidstat的用法参考了引用[1],iotop和dmesg的问题在引用[2]中提到,dstat在引用[3],fio在引用[4],iostat中的指标在引用[5]。需要确保每个引用准确对应到相关内容。 还需要考虑用户可能的后续问题,比如如何分析I/O性能瓶颈,或者如何优化磁盘I/O,因此生成相关问题时要涵盖这些方面,帮助用户进一步探索解决方案。 最后,要确保回答结构清晰,分点列出存储位置和查看方法,每个工具的使用步骤简明扼要,语法正确,符合用户的要求。同时,生成的相关问题应引导用户深入理解磁盘I/O监控和优化的各个方面。</think>### Ubuntu 系统磁盘 I/O 日志的存储位置及查看方法 #### 1. **磁盘 I/O 日志的存储位置** - **系统日志文件**: Ubuntu 的磁盘 I/O 相关日志通常存储在系统日志文件中,路径为 `/var/log/syslog` 和 `/var/log/kern.log`。这两个文件记录了内核和系统服务的详细事件,包括磁盘 I/O 错误、硬件故障等信息[^2][^5]。 - 使用命令查看: ```bash cat /var/log/syslog | grep -i 'disk\|io\|sdb' ``` - **内核环缓冲区**: 通过 `dmesg` 命令可以直接查看内核输出的实时日志,包括磁盘驱动、I/O 超时等事件,无需依赖持久化存储的日志文件[^2]。 - 示例: ```bash dmesg | grep -i 'io\|sdb' ``` --- #### 2. **磁盘 I/O 监控工具及使用方法** - **`iostat`(sysstat 包)**: 提供磁盘 I/O 的实时统计信息,如吞吐量、IOPS、延迟等。需先安装 `sysstat`: ```bash sudo apt-get install sysstat ``` - 查看实时统计(间隔 2 秒,共 5 次): ```bash iostat -dx 2 5 ``` - 输出字段解析: - `r/s` 和 `w/s`:每秒读写请求数 - `rkB/s` 和 `wkB/s`:每秒读写数据量 - `await`:I/O 平均等待时间。 - **`dmesg`**: 直接查看内核日志中的磁盘事件: ```bash dmesg | grep -i 'io\|disk\|error' ``` - **`iotop`**: 实时监控进程级磁盘 I/O 使用情况,需安装: ```bash sudo apt-get install iotop ``` - 运行后按 `o` 键仅显示活跃 I/O 进程。 - **`pidstat`**: 结合进程和 I/O 统计,查看具体进程的 I/O 负载: ```bash pidstat -d 1 # 每秒刷新一次[^1] ``` - **`dstat`**: 综合性能监控工具,支持实时查看磁盘 I/O: ```bash dstat -d # 显示磁盘读写速率[^3] ``` - **基准测试工具 `fio`**: 用于评估磁盘 I/O 极限性能,例如测试随机读: ```bash sudo apt-get install fio fio --name=randread --ioengine=libaio --rw=randread --bs=4k --numjobs=4 --size=1G --runtime=60 --time_based --end_fsync=1 ``` 可自定义测试模式(顺序/随机、读/写)[^4]。 --- #### 3. **关键场景示例** - **定位高 I/O 进程**: 若系统卡顿,使用 `iotop` 发现 `[flush-8:16]` 和 `[jbd2/sdb2-8]` 占用 99.99% I/O,说明文件系统正在同步日志或元数据,可能是正常行为[^2]。 - **分析历史 I/O 问题**: 检查 `/var/log/syslog` 中是否有 `I/O error` 或 `device reset` 等关键字,结合 `dmesg` 时间戳排查硬件故障。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值