'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 = 2 Then
DiskName = CStr(Wscript.Arguments(1)) & ":"
objRefresher.Refresh
For Each objDisk in colDisks
   if DiskName=CStr(objDisk.Name) then
   Dim DiskReadBytes,DiskWriteBytes
   if Round(objDisk.DiskReadBytesPerSec/1048576,2) > 0 And Round(objDisk.DiskReadBytesPerSec/1048576,2) <1 Then
   DiskReadBytes = "0" & Round(objDisk.DiskReadBytesPerSec/1048576,2)
  Else
  DiskReadBytes = Round(objDisk.DiskReadBytesPerSec/1048576,2)
  End If

  if Round(objDisk.DiskWriteBytesPerSec/1048576,2) > 0 And Round(objDisk.DiskWriteBytesPerSec/1048576,2) < 1 Then
   DiskWriteBytes = "0" & Round(objDisk.DiskWriteBytesPerSec/1048576,2)
  Else
  DiskWriteBytes = Round(objDisk.DiskWriteBytesPerSec/1048576,2)
  End If

   Wscript.Echo "{" & """rbytes""" & ":"& DiskReadBytes & "," & """wbytes""" & ":" & DiskWriteBytes & "," & """reads""" & ":" & objDisk.DiskReadsPerSec & ","  & """writes""" & ":" & objDisk.DiskWritesPerSec & ","  & """queue""" & ":" & objDisk.CurrentDiskQueueLength & ","  & """svctm""" & ":" & """""" & ","  & """cpname""" & ":" & """win_diskio""" & "}"
   end if
Next
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

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code