批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程
[批处理文件精品]批处理版照片整理器[批处理文件精品]纯批处理备份&还原驱动在线第三方下载
返回列表 发帖

[转贴] VBScript脚本监控磁盘I/O利用率

  1. '程序名称:      btlwchk_DiskIO.vbs
  2. '版权信息:      Copyright (c)  2011 guangzhou bluetech technology Incorporated.All rights reserved
  3. '程序用途:      监测windows主机IO利用率
  4. '创建日期:      2011-08-10
  5. '作者信息:      zhangkai
  6. '运行环境:      vbs
  7. '处理参数
  8. MonSubject="DiskIO"
  9. Set Args=WScript.Arguments
  10. If (Args.Count<1) Then
  11. Wscript.Echo MonSubject & " -1:command line error"
  12. WScript.Quit(3)
  13. End If
  14. strcid=Args(0)
  15. '获取工作目录
  16. tmparr=Split(Wscript.ScriptFullName,"\",-1)
  17. g_strworkdir=tmparr(0)
  18. narr=UBound(tmparr,1)
  19. For i=1 to narr-3
  20.     g_strworkdir=g_strworkdir & "\" & tmparr(i)
  21. Next
  22. '装载公共库
  23. set g_fileSys = createObject ("Scripting.FileSystemObject")
  24. Sub includeFile (fSpec)
  25.     dim file, fileData
  26.     set file = g_fileSys.openTextFile (fSpec)
  27.     fileData = file.readAll ()
  28.     file.close
  29.     executeGlobal fileData
  30.     set file = nothing
  31. end sub
  32. includeFile g_strworkdir & "\nagios\libexec\libcomm.vbs"
  33. '输出版本和帮助信息
  34. getverhelp strcid,"v1.00"," <cid>"
  35. strComputer = "."
  36. Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  37. '第1次采样IO
  38. Set colItems = objWMIService.ExecQuery("Select * from Win32_PerfRawData_PerfDisk_LogicalDisk where name='_Total' ",,48)
  39. For Each objItem in colItems
  40.      DiskTime1 = objItem.PercentDiskTime
  41.      BaseTime1 = objItem.PercentDiskTime_Base
  42.   DiskBytes1 = objItem.DiskBytesPerSec
  43.   DiskReadBytes1 = objItem.DiskReadBytesPerSec
  44.   DiskWriteBytes1 = objItem.DiskWriteBytesPerSec
  45.   AvgDiskTransfer1 = objItem.AvgDiskSecPerTransfer
  46.   AvgDiskTransferBase1 = objItem.AvgDiskSecPerTransfer_Base
  47.   AvgDiskRead1 = objItem.AvgDiskSecPerRead
  48.   AvgDiskReadBase1 = objItem.AvgDiskSecPerRead_Base
  49.   AvgDiskWrite1 = objItem.AvgDiskSecPerWrite
  50.   AvgDiskWriteBase1 = objItem.AvgDiskSecPerWrite_Base
  51.   TimeValue1 = objItem.Timestamp_PerfTime
  52.   TimeBase = objItem.Frequency_PerfTime
  53. Next
  54. '第2次采样IO
  55. WScript.Sleep 1000
  56. Set colItems = objWMIService.ExecQuery("Select * from Win32_PerfRawData_PerfDisk_LogicalDisk where name='_Total' ",,48)
  57. For Each objItem in colItems
  58.      DiskTime2 = objItem.PercentDiskTime
  59.   BaseTime2 = objItem.PercentDiskTime_Base
  60.   DiskBytes2 = objItem.DiskBytesPerSec
  61.   DiskReadBytes2 = objItem.DiskReadBytesPerSec
  62.   DiskWriteBytes2 = objItem.DiskWriteBytesPerSec
  63.   AvgDiskTransfer2 = objItem.AvgDiskSecPerTransfer
  64.   AvgDiskTransferBase2 = objItem.AvgDiskSecPerTransfer_Base
  65.   AvgDiskRead2 = objItem.AvgDiskSecPerRead
  66.   AvgDiskReadBase2 = objItem.AvgDiskSecPerRead_Base
  67.   AvgDiskWrite2 = objItem.AvgDiskSecPerWrite
  68.   AvgDiskWriteBase2 = objItem.AvgDiskSecPerWrite_Base
  69.   TimeValue2 = objItem.Timestamp_PerfTime
  70.         CurrentDiskQueueLength = objItem.CurrentDiskQueueLength
  71. Next
  72. '获取IO利用率
  73. If BaseTime2 - BaseTime1 = 0 Then
  74. strio ="Name=_Toltal"  & ",PercentDiskTime=0%"
  75. Else
  76. PercentDiskTime =(DiskTime2 - DiskTime1)/(BaseTime2 - BaseTime1)*100
  77. strio = "Name=_Total"  & ",PercentDiskTime="  & PercentDiskTime
  78. End If
  79. '获取Disk Bytes/sec
  80. If TimeValue2 - TimeValue1 = 0 Then
  81.     strdiskbyte = ",DiskBytesPerSec=0"
  82. Else
  83.     DiskBytesPerSec = (DiskBytes2 - DiskBytes1) / ( (TimeValue2 - TimeValue1) / TimeBase)
  84.     strdiskbyte = ",DiskBytesPerSec="  & DiskBytesPerSec
  85. End If
  86. '获取Disk Read Bytes/sec
  87. If TimeValue2 - TimeValue1 = 0 Then
  88.     strdiskreadbyte = ",DiskReadBytesPerSec=0"
  89. Else
  90.     DiskReadBytesPerSec = (DiskReadBytes2 - DiskReadBytes1) / ( (TimeValue2 - TimeValue1) / TimeBase)
  91.     strdiskreadbyte = ",DiskReadBytesPerSec="  & DiskReadBytesPerSec
  92. End If
  93. '获取Disk Write Bytes/sec
  94. If TimeValue2 - TimeValue1 = 0 Then
  95.     strdiskwritebyte = ",DiskWriteBytesPerSec=0"
  96. Else
  97.     DiskWriteBytesPerSec = (DiskWriteBytes2 - DiskWriteBytes1) / ( (TimeValue2 - TimeValue1) / TimeBase)
  98.     strdiskwritebyte = ",DiskWriteBytesPerSec="  & DiskWriteBytesPerSec
  99. End If
  100. '获取Avg. Disk sec/Transfer
  101. If AvgDiskTransferBase2 - AvgDiskTransferBase1 = 0 Then
  102.     stravgdisktran = ",AvgDiskSecPerTransfer=0"
  103. Else
  104.     AvgDiskSecPerTransfer = ((AvgDiskTransfer2 - AvgDiskTransfer1) / TimeBase) / (AvgDiskTransferBase2 - AvgDiskTransferBase1)
  105.     stravgdisktran = ",AvgDiskSecPerTransfer="  & AvgDiskSecPerTransfer
  106. End If
  107. '获取Avg. Disk sec/Read
  108. If AvgDiskReadBase2 - AvgDiskReadBase1 = 0 Then
  109.     stravgdiskread = ",AvgDiskSecPerRead=0"
  110. Else
  111.     AvgDiskSecPerRead = ((AvgDiskRead2 - AvgDiskRead1) / TimeBase) / (AvgDiskReadBase2 - AvgDiskReadBase1)
  112.     stravgdiskread = ",AvgDiskSecPerRead="  & AvgDiskSecPerRead
  113. End If
  114. '获取Avg. Disk sec/Write
  115. If AvgDiskWriteBase2 - AvgDiskWriteBase1 = 0 Then
  116.     stravgdiskwrite = ",AvgDiskSecPerWrite=0"
  117. Else
  118.     AvgDiskSecPerWrite = ((AvgDiskWrite2 - AvgDiskWrite1) / TimeBase) / (AvgDiskWriteBase2 - AvgDiskWriteBase1)
  119.     stravgdiskwrite = ",AvgDiskSecPerWrite="  & AvgDiskSecPerWrite
  120. End If
  121. '获取Current Disk Queue Length
  122. strdisklength = ",CurrentDiskQueueLength="  & CurrentDiskQueueLength
  123. Wscript.Echo MonSubject & " 0:OK|" & strio & strdiskbyte & strdiskreadbyte & strdiskwritebyte & stravgdisktran & stravgdiskread & stravgdiskwrite & strdisklength
复制代码


http://80888888.blog.51cto.com/2741630/656434

返回列表