标题: [原创] VBS监测windows主机IO利用率 [打印本页]
作者: zhangrenfang 时间: 2011-8-30 16:40 标题: VBS监测windows主机IO利用率
本帖最后由 zhangrenfang 于 2012-2-28 14:53 编辑
- '程序名称: btlwchk_DiskIO.vbs
- '程序用途: 监测windows主机IO利用率
- '创建日期: 2011-08-10
- '作者信息: zhangkai
- '运行环境: vbs
- 'QQ: 276371791
- MonSubject="DiskIO"
- strComputer = "."
- Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
- '第1次采样IO
- Set colItems = objWMIService.ExecQuery("Select * from Win32_PerfRawData_PerfDisk_LogicalDisk where name='_Total' ",,48)
- For Each objItem in colItems
- DiskTime1 = objItem.PercentDiskTime
- BaseTime1 = objItem.PercentDiskTime_Base
- DiskBytes1 = objItem.DiskBytesPerSec
- DiskReadBytes1 = objItem.DiskReadBytesPerSec
- DiskWriteBytes1 = objItem.DiskWriteBytesPerSec
- AvgDiskTransfer1 = objItem.AvgDiskSecPerTransfer
- AvgDiskTransferBase1 = objItem.AvgDiskSecPerTransfer_Base
- AvgDiskRead1 = objItem.AvgDiskSecPerRead
- AvgDiskReadBase1 = objItem.AvgDiskSecPerRead_Base
- AvgDiskWrite1 = objItem.AvgDiskSecPerWrite
- AvgDiskWriteBase1 = objItem.AvgDiskSecPerWrite_Base
- TimeValue1 = objItem.Timestamp_PerfTime
- TimeBase = objItem.Frequency_PerfTime
- Next
- '第2次采样IO
- WScript.Sleep 1000
- Set colItems = objWMIService.ExecQuery("Select * from Win32_PerfRawData_PerfDisk_LogicalDisk where name='_Total' ",,48)
- For Each objItem in colItems
- DiskTime2 = objItem.PercentDiskTime
- BaseTime2 = objItem.PercentDiskTime_Base
- DiskBytes2 = objItem.DiskBytesPerSec
- DiskReadBytes2 = objItem.DiskReadBytesPerSec
- DiskWriteBytes2 = objItem.DiskWriteBytesPerSec
- AvgDiskTransfer2 = objItem.AvgDiskSecPerTransfer
- AvgDiskTransferBase2 = objItem.AvgDiskSecPerTransfer_Base
- AvgDiskRead2 = objItem.AvgDiskSecPerRead
- AvgDiskReadBase2 = objItem.AvgDiskSecPerRead_Base
- AvgDiskWrite2 = objItem.AvgDiskSecPerWrite
- AvgDiskWriteBase2 = objItem.AvgDiskSecPerWrite_Base
- TimeValue2 = objItem.Timestamp_PerfTime
- CurrentDiskQueueLength = objItem.CurrentDiskQueueLength
- Next
- '获取IO利用率
- If BaseTime2 - BaseTime1 = 0 Then
- strio ="Name=_Toltal" & ",PercentDiskTime=0%"
- Else
- PercentDiskTime =(DiskTime2 - DiskTime1)/(BaseTime2 - BaseTime1)*100
- strio = "Name=_Total" & ",PercentDiskTime=" & PercentDiskTime
- End If
- '获取Disk Bytes/sec
- If TimeValue2 - TimeValue1 = 0 Then
- strdiskbyte = ",DiskBytesPerSec=0"
- Else
- DiskBytesPerSec = (DiskBytes2 - DiskBytes1) / ( (TimeValue2 - TimeValue1) / TimeBase)
- strdiskbyte = ",DiskBytesPerSec=" & DiskBytesPerSec
- End If
- '获取Disk Read Bytes/sec
- If TimeValue2 - TimeValue1 = 0 Then
- strdiskreadbyte = ",DiskReadBytesPerSec=0"
- Else
- DiskReadBytesPerSec = (DiskReadBytes2 - DiskReadBytes1) / ( (TimeValue2 - TimeValue1) / TimeBase)
- strdiskreadbyte = ",DiskReadBytesPerSec=" & DiskReadBytesPerSec
- End If
- '获取Disk Write Bytes/sec
- If TimeValue2 - TimeValue1 = 0 Then
- strdiskwritebyte = ",DiskWriteBytesPerSec=0"
- Else
- DiskWriteBytesPerSec = (DiskWriteBytes2 - DiskWriteBytes1) / ( (TimeValue2 - TimeValue1) / TimeBase)
- strdiskwritebyte = ",DiskWriteBytesPerSec=" & DiskWriteBytesPerSec
- End If
- '获取Avg. Disk sec/Transfer
- If AvgDiskTransferBase2 - AvgDiskTransferBase1 = 0 Then
- stravgdisktran = ",AvgDiskSecPerTransfer=0"
- Else
- AvgDiskSecPerTransfer = ((AvgDiskTransfer2 - AvgDiskTransfer1) / TimeBase) / (AvgDiskTransferBase2 - AvgDiskTransferBase1)
- stravgdisktran = ",AvgDiskSecPerTransfer=" & AvgDiskSecPerTransfer
- End If
- '获取Avg. Disk sec/Read
- If AvgDiskReadBase2 - AvgDiskReadBase1 = 0 Then
- stravgdiskread = ",AvgDiskSecPerRead=0"
- Else
- AvgDiskSecPerRead = ((AvgDiskRead2 - AvgDiskRead1) / TimeBase) / (AvgDiskReadBase2 - AvgDiskReadBase1)
- stravgdiskread = ",AvgDiskSecPerRead=" & AvgDiskSecPerRead
- End If
- '获取Avg. Disk sec/Write
- If AvgDiskWriteBase2 - AvgDiskWriteBase1 = 0 Then
- stravgdiskwrite = ",AvgDiskSecPerWrite=0"
- Else
- AvgDiskSecPerWrite = ((AvgDiskWrite2 - AvgDiskWrite1) / TimeBase) / (AvgDiskWriteBase2 - AvgDiskWriteBase1)
- stravgdiskwrite = ",AvgDiskSecPerWrite=" & AvgDiskSecPerWrite
- End If
- '获取Current Disk Queue Length
- strdisklength = ",CurrentDiskQueueLength=" & CurrentDiskQueueLength
- Wscript.Echo MonSubject & " 0:OK|" & strio & strdiskbyte & strdiskreadbyte & strdiskwritebyte & stravgdisktran & stravgdiskread & stravgdiskwrite & strdisklength
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |