Board logo

标题: [原创] VBS监测windows主机IO利用率 [打印本页]

作者: zhangrenfang    时间: 2011-8-30 16:40     标题: VBS监测windows主机IO利用率

本帖最后由 zhangrenfang 于 2012-2-28 14:53 编辑
  1. '程序名称:      btlwchk_DiskIO.vbs
  2. '程序用途:      监测windows主机IO利用率
  3. '创建日期:      2011-08-10
  4. '作者信息:      zhangkai
  5. '运行环境:      vbs
  6. 'QQ:        276371791
  7. MonSubject="DiskIO"
  8. strComputer = "."  
  9. Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  10. '第1次采样IO
  11. Set colItems = objWMIService.ExecQuery("Select * from Win32_PerfRawData_PerfDisk_LogicalDisk where name='_Total' ",,48)
  12. For Each objItem in colItems
  13.      DiskTime1 = objItem.PercentDiskTime
  14.      BaseTime1 = objItem.PercentDiskTime_Base
  15.   DiskBytes1 = objItem.DiskBytesPerSec
  16.   DiskReadBytes1 = objItem.DiskReadBytesPerSec
  17.   DiskWriteBytes1 = objItem.DiskWriteBytesPerSec
  18.   AvgDiskTransfer1 = objItem.AvgDiskSecPerTransfer
  19.   AvgDiskTransferBase1 = objItem.AvgDiskSecPerTransfer_Base
  20.   AvgDiskRead1 = objItem.AvgDiskSecPerRead
  21.   AvgDiskReadBase1 = objItem.AvgDiskSecPerRead_Base
  22.   AvgDiskWrite1 = objItem.AvgDiskSecPerWrite
  23.   AvgDiskWriteBase1 = objItem.AvgDiskSecPerWrite_Base
  24.   TimeValue1 = objItem.Timestamp_PerfTime
  25.   TimeBase = objItem.Frequency_PerfTime
  26. Next
  27. '第2次采样IO
  28. WScript.Sleep 1000
  29. Set colItems = objWMIService.ExecQuery("Select * from Win32_PerfRawData_PerfDisk_LogicalDisk where name='_Total' ",,48)
  30. For Each objItem in colItems
  31.      DiskTime2 = objItem.PercentDiskTime
  32.   BaseTime2 = objItem.PercentDiskTime_Base
  33.   DiskBytes2 = objItem.DiskBytesPerSec
  34.   DiskReadBytes2 = objItem.DiskReadBytesPerSec
  35.   DiskWriteBytes2 = objItem.DiskWriteBytesPerSec
  36.   AvgDiskTransfer2 = objItem.AvgDiskSecPerTransfer
  37.   AvgDiskTransferBase2 = objItem.AvgDiskSecPerTransfer_Base
  38.   AvgDiskRead2 = objItem.AvgDiskSecPerRead
  39.   AvgDiskReadBase2 = objItem.AvgDiskSecPerRead_Base
  40.   AvgDiskWrite2 = objItem.AvgDiskSecPerWrite
  41.   AvgDiskWriteBase2 = objItem.AvgDiskSecPerWrite_Base
  42.   TimeValue2 = objItem.Timestamp_PerfTime
  43.         CurrentDiskQueueLength = objItem.CurrentDiskQueueLength
  44. Next
  45. '获取IO利用率
  46. If BaseTime2 - BaseTime1 = 0 Then
  47. strio ="Name=_Toltal"  & ",PercentDiskTime=0%"
  48. Else
  49. PercentDiskTime =(DiskTime2 - DiskTime1)/(BaseTime2 - BaseTime1)*100
  50. strio = "Name=_Total"  & ",PercentDiskTime="  & PercentDiskTime
  51. End If
  52. '获取Disk Bytes/sec
  53. If TimeValue2 - TimeValue1 = 0 Then
  54.     strdiskbyte = ",DiskBytesPerSec=0"
  55. Else
  56.     DiskBytesPerSec = (DiskBytes2 - DiskBytes1) / ( (TimeValue2 - TimeValue1) / TimeBase)
  57.     strdiskbyte = ",DiskBytesPerSec="  & DiskBytesPerSec
  58. End If
  59. '获取Disk Read Bytes/sec
  60. If TimeValue2 - TimeValue1 = 0 Then
  61.     strdiskreadbyte = ",DiskReadBytesPerSec=0"
  62. Else
  63.     DiskReadBytesPerSec = (DiskReadBytes2 - DiskReadBytes1) / ( (TimeValue2 - TimeValue1) / TimeBase)
  64.     strdiskreadbyte = ",DiskReadBytesPerSec="  & DiskReadBytesPerSec
  65. End If
  66. '获取Disk Write Bytes/sec
  67. If TimeValue2 - TimeValue1 = 0 Then
  68.     strdiskwritebyte = ",DiskWriteBytesPerSec=0"
  69. Else
  70.     DiskWriteBytesPerSec = (DiskWriteBytes2 - DiskWriteBytes1) / ( (TimeValue2 - TimeValue1) / TimeBase)
  71.     strdiskwritebyte = ",DiskWriteBytesPerSec="  & DiskWriteBytesPerSec
  72. End If
  73. '获取Avg. Disk sec/Transfer
  74. If AvgDiskTransferBase2 - AvgDiskTransferBase1 = 0 Then
  75.     stravgdisktran = ",AvgDiskSecPerTransfer=0"
  76. Else
  77.     AvgDiskSecPerTransfer = ((AvgDiskTransfer2 - AvgDiskTransfer1) / TimeBase) / (AvgDiskTransferBase2 - AvgDiskTransferBase1)
  78.     stravgdisktran = ",AvgDiskSecPerTransfer="  & AvgDiskSecPerTransfer
  79. End If
  80. '获取Avg. Disk sec/Read
  81. If AvgDiskReadBase2 - AvgDiskReadBase1 = 0 Then
  82.     stravgdiskread = ",AvgDiskSecPerRead=0"
  83. Else
  84.     AvgDiskSecPerRead = ((AvgDiskRead2 - AvgDiskRead1) / TimeBase) / (AvgDiskReadBase2 - AvgDiskReadBase1)
  85.     stravgdiskread = ",AvgDiskSecPerRead="  & AvgDiskSecPerRead
  86. End If
  87. '获取Avg. Disk sec/Write
  88. If AvgDiskWriteBase2 - AvgDiskWriteBase1 = 0 Then
  89.     stravgdiskwrite = ",AvgDiskSecPerWrite=0"
  90. Else
  91.     AvgDiskSecPerWrite = ((AvgDiskWrite2 - AvgDiskWrite1) / TimeBase) / (AvgDiskWriteBase2 - AvgDiskWriteBase1)
  92.     stravgdiskwrite = ",AvgDiskSecPerWrite="  & AvgDiskSecPerWrite
  93. End If
  94. '获取Current Disk Queue Length
  95. strdisklength = ",CurrentDiskQueueLength="  & CurrentDiskQueueLength
  96. Wscript.Echo MonSubject & " 0:OK|" & strio & strdiskbyte & strdiskreadbyte & strdiskwritebyte & stravgdisktran & stravgdiskread & stravgdiskwrite & strdisklength
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2