磁盘IO性能监控(Linux 和 Windows)

作者:终南   <li.zhongnan@hotmail.com>

磁盘的IO性能是衡量计算机总体性能的一个重要指标。Linux提供了iostat命令来获却磁盘输入/输出(即IO)统计信息,Windows则提供了WMI接口,可以通过编写一个简单的脚本来获取与iostat相当的功能。

1、Linux下的iostat命令

iostat -d -k -t 2

每隔2秒统计一次磁盘IO信息,直到按Ctrl+C终止程序,-d 选项表示统计磁盘信息, -k 表示以每秒KB的形式显示,-t
要求打印出时间信息,2 表示每隔 2
秒输出一次。第一次输出的磁盘IO负载状况提供了关于自从系统启动以来的统计信息。随后的每一次输出则是每个间隔之间的平均IO负载状况。

运行该命令后,输出:

Linux 2.6.9-67.0.7.ELsmp (localhost.localdomain)        11/19/2008

Time: 03:15:25 PM
Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda               3.53        26.66        54.76   30122033   61864280
sda1              0.51         1.07         1.73    1207649    1949740
sda2              0.00         0.00         0.00        538        256
sda3             13.84        25.59        53.03   28913291   59914092

Time: 03:15:27 PM
Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda             275.38         0.00      1738.69          0       3460
sda1             14.57         0.00        58.29          0        116
sda2              0.00         0.00         0.00          0          0
sda3            419.60         0.00      1678.39          0       3340

...

每次输出都会打印时间信息, 接下来显示磁盘IO情况列表。

Device: 显示磁盘名称
tps: 表示每秒钟输出到物理磁盘的传输次数。一次传输就是一个对物理磁盘的 I/O 请求。多个逻辑请求可被并为对磁盘的一个单一 I/O 请求。传输具有中等的大小。
kB_read/s: 每秒从磁盘读取的数据量,单位为KB。
kB_wrtn/s: 每秒从写入磁盘的数据量,单位为KB。
Kb_read: 读取的 KB 总数。
Kb_wrtn: 写入的 KB 总数。

2、WMI中的 Win32_PerfFormattedData_PerfDisk_LogicalDisk 对象

Win32_PerfFormattedData_PerfDisk_LogicalDisk
代表逻辑磁盘性能数据对象,利用该对象可以获得磁盘的心能信息。
Win32_PerfFormattedData_PerfDisk_LogicalDisk对象有以下一些主要的属性:

Name: 磁盘名称
DiskTransfersPerSec:每秒磁盘传输次数。
DiskReadBytesPerSec:每秒从磁盘读取得数据量,单位为Byte。
DiskWriteBytesPerSec:每秒从磁盘读取得数据量,单位为Byte。
PercentFreeSpace:可用磁盘百分比。

3、使用 Win32_PerfFormattedData_PerfDisk_LogicalDisk 的注意事项

在使用 Win32_PerfFormattedData_PerfDisk_LogicalDisk 时,需要注意:

(1)不能使用 objWMIService.ExecQuery 执行 Select 语句来获取磁盘性能数据
(2)必须使用 WbemScripting.SWbemRefresher 将 Win32_PerfFormattedData_PerfDisk_LogicalDisk 加入,然后不断调用 Refresh 方法刷新数据来获取性能信息
(3)第一次刷新的时候,并不能获取有用的数据,从第二次开始,才能获取到磁盘性能数据
(4)以上问题与 WMI 中性能监控使用计数器的机制有关

4、使用举例

为了对监控磁盘性能提供一个良好的用户界面,可以利用VBScript编写脚本来获取磁盘性能数据。脚本的代码如下:

'Script File Name: DiskMonitor.vbs

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!//" & strComputer & "/root/cimv2")
set objRefresher = CreateObject("WbemScripting.SWbemRefresher")
Set colDisks = objRefresher.AddEnum(objWMIService, "Win32_PerfFormattedData_PerfDisk_LogicalDisk").objectSet

If Wscript.Arguments.Count = 0 Then
objRefresher.Refresh
For Each objDisk in colDisks
   Wscript.Echo objDisk.Name & " " & objDisk.DiskReadBytesPerSec & " " & objDisk.DiskWriteBytesPerSec
Next
End If

If Wscript.Arguments.Count = 1 Then
Interval = CInt(Wscript.Arguments(0)) * 1000
Do While True
   objRefresher.Refresh

Wscript.Echo
   Wscript.Echo "Time: " & " " & Time()
  
Wscript.Echo FormatStr("Device:", 15, 0) & FormatStr("tps", 7, 1)
& FormatStr("    kB_read/s", 13, 1) & FormatStr("kB_wrtn/s", 13,
1) & FormatStr("Free Space", 13, 1)

For Each objDisk in colDisks
    Wscript.Echo
FormatStr(objDisk.Name, 15, 0) &
FormatStr(objDisk.DiskTransfersPerSec, 7, 1) &
FormatStr(objDisk.DiskReadBytesPerSec, 13, 1) &
FormatStr(objDisk.DiskWriteBytesPerSec, 13, 1) &
FormatStr(objDisk.PercentFreeSpace & "%", 13, 1)
   Next
   Wscript.Sleep Interval
Loop
End If

If Wscript.Arguments.Count = 2 Then
i = 0
Interval = CInt(Wscript.Arguments(0)) * 1000
Count = CInt(Wscript.Arguments(1))
Do While i < Count
   objRefresher.Refresh

Wscript.Echo
   Wscript.Echo "Time: " & " " & Time()
  
Wscript.Echo FormatStr("Device:", 15, 0) & FormatStr("tps", 7, 1)
& FormatStr("    kB_read/s", 13, 1) & FormatStr("kB_wrtn/s", 13,
1) & FormatStr("Free Space", 13, 1)

For Each objDisk in colDisks
    Wscript.Echo
FormatStr(objDisk.Name, 15, 0) &
FormatStr(objDisk.DiskTransfersPerSec, 7, 1) &
FormatStr(objDisk.DiskReadBytesPerSec, 13, 1) &
FormatStr(objDisk.DiskWriteBytesPerSec, 13, 1) &
FormatStr(objDisk.PercentFreeSpace & "%", 13, 1)
   Next
   Wscript.Sleep Interval
   i = i + 1
Loop
End If

Function FormatStr(str, tLen, direction)
sLen = Len(str)
fStr = ""
num = tLen - sLen

j = 0
Do While j < num
   fStr = fStr & " "
   j = j + 1
Loop

If direction = 1 Then
   fStr = fStr & str
Else
   fStr = str & fStr
End If
FormatStr = fStr
End Function

使用举例:

(1)CSCript DiskMonitor.vbs
止刷新一次 Win32_PerfFormattedData_PerfDisk_LogicalDisk 对象,不会获取到有用的数据。

(2)CSCript DiskMonitor.vbs 2
每隔 2 秒获取一次磁盘性能数据并输出,直到按 Ctrl+C 终止程序。

(3)CSCript DiskMonitor.vbs 2 100
每隔 2 秒获取一次磁盘性能数据并输出,总共获取 100 次,然后退出。

该脚本输出的信息包括 DiskTransfersPerSec、DiskReadBytesPerSec、DiskWriteBytesPerSec 和 PercentFreeSpace。

转载:

http://blog.csdn.net/magicbreaker/archive/2008/11/22/3351964.aspx

http://blog.csdn.net/forandever/article/details/5464902

磁盘IO性能监控(Linux 和 Windows)的更多相关文章

  1. 018 磁盘 IO 性能监控/压测工具(sar、iotop、fio、iostat)

    1 sar 命令查看当前磁盘 IO 读写 sar(System Activity Reporter 系统活动情况报告)是 Linux 上最为全面的系统性能分析工具之一,可以从多方面对系统的活动进行报告 ...

  2. cacti监控linux和windows磁盘IO

    cacti监控linux和windows磁盘IO 标签:cacti linux磁盘IO windows磁盘IO 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则 ...

  3. Linux如何查看与测试磁盘IO性能

    1. 查看磁盘 IO 性能 1.1 top 命令 top 命令通过查看 CPU 的 wa% 值来判断当前磁盘 IO 性能,如果这个数值过大,很可能是磁盘 IO 太高了,当然也可能是其他原因,例如网络 ...

  4. 转载 IMP时数据库的IO性能监控,并提供IOPS的计算方法

     IMP时数据库的IO性能监控,并提供IOPS的计算方法 2011-07-15 17:36:10 分类: Linux [root@ntkdb oradata]# iostat -x 1 10     ...

  5. Linux系统性能测试工具(六)——磁盘io性能工具之dd

    本文介绍关于Linux系统(适用于centos/ubuntu等)的磁盘io性能测试工具-dd.磁盘io性能测试工具包括: fio: dd

  6. Linux系统性能测试工具(五)——磁盘io性能工具之fio

    本文介绍关于Linux系统(适用于centos/ubuntu等)的磁盘io性能测试工具-fio.磁盘io性能测试工具包括: fio: dd

  7. windows上测试磁盘io性能

    一.问题由来 前两天搭建一套演示环境,同样的java war包,放在我们这边服务器好好的,放在那边就运行缓慢. 后来把日志改成异步之后就好了. 后边找了个程序测了下io性能,竟然差了7,8倍. 二.软 ...

  8. zabbix之 自动发现磁盘io util 监控

    一.iostat Zabbix并没有提供模板来监控磁盘的IO性能,所以我们需要自己来创建一个.iostat主要用于监控系统设备的IO负载情况,iostat首次运行时显示自系统启动开始的各项统计信息,之 ...

  9. LoadRunner监控Linux与Windows方法

    1.首先保证被监视的windows系统开启以下二个服务Remote Procedure Call(RPC) 和Remote Registry Service: 2.被监视的WINDOWS机器:右击我的 ...

随机推荐

  1. cf C. Knight Tournament

    http://codeforces.com/contest/357/problem/C #include <cstdio> #include <cstring> #includ ...

  2. 黑马程序员_Java面向对象2_继承

    4.面向对象_继承 4.1继承的概述 提高了代码的复用性. 让类与类之间产生了关系,有了这个关系,才有多态的特性. 注意:千万不要为了获取其他类的功能而去继承,简化代码而继承.必须是类与类之间有所属关 ...

  3. TortoiseGit 使用教程

    原文地址:http://blog.csdn.net/ethan_xue/article/details/7749639 git的使用越来越广泛 使用命令比较麻烦,下面讲解一下tortoisegit的使 ...

  4. Codeforces Round #322 (Div. 2) —— F. Zublicanes and Mumocrates

    It's election time in Berland. The favorites are of course parties of zublicanes and mumocrates. The ...

  5. You don't have permission to access / on this server for debian_8

    Forbidden You don't have permission to access / on this server. Apache/2.4.10 (Debian) Server at www ...

  6. Appium 一个测试套件多次启动android应用

    AppiumDriver<WebElement> driver; File classpathRoot = new File(System.getProperty("user.d ...

  7. Adroid APPIUM实例步骤

      1.下载eclipse 2.安装java 配置环境变量 3.eclipse 安装adt android development tools 4.android sdk manager 安装tool ...

  8. AllocConsole

    #include<iostream> using namespace std; AllocConsole(); freopen("CONIN$", "r+t& ...

  9. c++11 之 decltype

    在C++中,decltype作为操作符,用于查询表达式的数据类型.decltype在C++11标准制定时引入,主要是为泛型编程而设计,以解决泛型编程中,由于有些类型由模板参数决定,而难以(甚至不可能) ...

  10. 转载 Silverlight实用窍门系列:1.Silverlight读取外部XML加载配置---(使用WebClient读取XAP包同目录下的XML文件))

    转载:程兴亮文章,地址;http://www.cnblogs.com/chengxingliang/archive/2011/02/07/1949579.html 使用WebClient读取XAP包同 ...