- 论坛徽章:
- 0
|
RT
新的需求是nagios监控服务器磁盘IO,目前监控Linux系统的磁盘IO已通过nagios提供的iostat插件实现,并可以顺利获取数值。
windows的磁盘IO应该是调取WMI的数值,现在利用vbs脚本以实现数值获取,在传值方面遇到了问题,麻烦有相关经验的同学帮帮忙,讲解一下,多谢。
附上我目前的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
- strFileDir = left(Wscript.ScriptFullName,len(Wscript.ScriptFullName)-len(Wscript.ScriptName))
- strFileName = strFileDir + "DiskMonitor.xls"
- Set oExcel = CreateObject( "Excel.Application" )
- oExcel.WorkBooks.open(strFileName)
- oExcel.DisplayAlerts = False
- If Wscript.Arguments.Count = 0 Then
- MsgBox "输入参数错误!"
- End If
- If Wscript.Arguments.Count = 1 Then
- RowNum = 4
- Interval = CInt(Wscript.Arguments(0)) * 1000
- oExcel.Cells(1,1).Value = "运行命令为:DiskMonitor.vbs " + Wscript.Arguments(0)
- oExcel.Cells(1,2).Value = "运行时间为:" + CStr(Time())
- oExcel.Cells(3,1).Value = "Device"
- oExcel.Cells(3,2).Value = "TPS"
- oExcel.Cells(3,3).Value = "kB_read/s"
- oExcel.Cells(3,4).Value = "kB_wrtn/s"
- oExcel.Cells(3,5).Value = "Free Space"
- Do While True
- objRefresher.Refresh
-
- ColumnsNum = 1
- For Each objDisk in colDisks
- oExcel.Cells(RowNum,1).Value = CStr(objDisk.Name)
- oExcel.Cells(RowNum,2).Value = CStr(objDisk.DiskTransfersPerSec)
- oExcel.Cells(RowNum,3).Value = CStr(objDisk.DiskReadBytesPerSec)
- oExcel.Cells(RowNum,4).Value = CStr(objDisk.DiskWriteBytesPerSec)
- oExcel.Cells(RowNum,5).Value = CStr(objDisk.PercentFreeSpace) + "%"
- RowNum = RowNum + 1
- Next
- Wscript.Sleep Interval
- Loop
- End If
- If Wscript.Arguments.Count = 2 Then
- i = 0
- RowNum = 4
- Interval = CInt(Wscript.Arguments(0)) * 1000
- Count = CInt(Wscript.Arguments(1))
- oExcel.Cells(1,1).Value = "运行命令为:DiskMonitor.vbs " + CStr(Wscript.Arguments(0)) + " " + CStr(Wscript.Arguments(1))
- oExcel.Cells(1,2).Value = "运行时间为:" + CStr(Time())
- oExcel.Cells(3,1).Value = "Device"
- oExcel.Cells(3,2).Value = "TPS"
- oExcel.Cells(3,3).Value = "kB_read/s"
- oExcel.Cells(3,4).Value = "kB_wrtn/s"
- oExcel.Cells(3,5).Value = "Free Space"
- Do While i < Count
- objRefresher.Refresh
-
- For Each objDisk in colDisks
- oExcel.Cells(RowNum,1).Value = CStr(objDisk.Name)
- oExcel.Cells(RowNum,2).Value = CStr(objDisk.DiskTransfersPerSec)
- oExcel.Cells(RowNum,3).Value = CStr(objDisk.DiskReadBytesPerSec)
- oExcel.Cells(RowNum,4).Value = CStr(objDisk.DiskWriteBytesPerSec)
- oExcel.Cells(RowNum,5).Value = CStr(objDisk.PercentFreeSpace) + "%"
- RowNum = RowNum + 1
- Next
- Wscript.Sleep Interval
- i = i + 1
- Loop
- End If
- oExcel.Workbooks(1).Save
- oExcel.Workbooks(1).Close
- oExcel.Quit
复制代码 [/code]
第二个脚本,收集到信息后写入同目录下的DiskMonitor.xls表中- 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
- strFileDir = left(Wscript.ScriptFullName,len(Wscript.ScriptFullName)-len(Wscript.ScriptName))
- strFileName = strFileDir + "DiskMonitor.xls"
- Set oExcel = CreateObject( "Excel.Application" )
- oExcel.WorkBooks.open(strFileName)
- oExcel.DisplayAlerts = False
- If Wscript.Arguments.Count = 0 Then
- MsgBox "输入参数错误!"
- End If
- If Wscript.Arguments.Count = 1 Then
- RowNum = 4
- Interval = CInt(Wscript.Arguments(0)) * 1000
- oExcel.Cells(1,1).Value = "运行命令为:DiskMonitor.vbs " + Wscript.Arguments(0)
- oExcel.Cells(1,2).Value = "运行时间为:" + CStr(Time())
- oExcel.Cells(3,1).Value = "Device"
- oExcel.Cells(3,2).Value = "TPS"
- oExcel.Cells(3,3).Value = "kB_read/s"
- oExcel.Cells(3,4).Value = "kB_wrtn/s"
- oExcel.Cells(3,5).Value = "Free Space"
- Do While True
- objRefresher.Refresh
-
- ColumnsNum = 1
- For Each objDisk in colDisks
- oExcel.Cells(RowNum,1).Value = CStr(objDisk.Name)
- oExcel.Cells(RowNum,2).Value = CStr(objDisk.DiskTransfersPerSec)
- oExcel.Cells(RowNum,3).Value = CStr(objDisk.DiskReadBytesPerSec)
- oExcel.Cells(RowNum,4).Value = CStr(objDisk.DiskWriteBytesPerSec)
- oExcel.Cells(RowNum,5).Value = CStr(objDisk.PercentFreeSpace) + "%"
- RowNum = RowNum + 1
- Next
- Wscript.Sleep Interval
- Loop
- End If
- If Wscript.Arguments.Count = 2 Then
- i = 0
- RowNum = 4
- Interval = CInt(Wscript.Arguments(0)) * 1000
- Count = CInt(Wscript.Arguments(1))
- oExcel.Cells(1,1).Value = "运行命令为:DiskMonitor.vbs " + CStr(Wscript.Arguments(0)) + " " + CStr(Wscript.Arguments(1))
- oExcel.Cells(1,2).Value = "运行时间为:" + CStr(Time())
- oExcel.Cells(3,1).Value = "Device"
- oExcel.Cells(3,2).Value = "TPS"
- oExcel.Cells(3,3).Value = "kB_read/s"
- oExcel.Cells(3,4).Value = "kB_wrtn/s"
- oExcel.Cells(3,5).Value = "Free Space"
- Do While i < Count
- objRefresher.Refresh
-
- For Each objDisk in colDisks
- oExcel.Cells(RowNum,1).Value = CStr(objDisk.Name)
- oExcel.Cells(RowNum,2).Value = CStr(objDisk.DiskTransfersPerSec)
- oExcel.Cells(RowNum,3).Value = CStr(objDisk.DiskReadBytesPerSec)
- oExcel.Cells(RowNum,4).Value = CStr(objDisk.DiskWriteBytesPerSec)
- oExcel.Cells(RowNum,5).Value = CStr(objDisk.PercentFreeSpace) + "%"
- RowNum = RowNum + 1
- Next
- Wscript.Sleep Interval
- i = i + 1
- Loop
- End If
- oExcel.Workbooks(1).Save
- oExcel.Workbooks(1).Close
- oExcel.Quit
复制代码 [/code] |
|