来到新单位,发现这里的服务器不说成千上万,也比以前单位足足多出来五、六倍。看来只有用把一些监控的任务自动化才有可能达到目的。遂拣起来以前有兴趣看过两眼的WMI脚本编程,在网上一顿狂啃,花了半天的时间写出了一个可以获得CPU、内存以及硬盘剩余空间的数据信息的程序:
===================enumsingel.vbs===================
Const HARD_DISK = 3
Wscript.Echo "Program start at " & Now()
strComputer = "."
' Connect to server
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
' Memory/CPU/DiskFree
Set colItems = objWMIService.ExecQuery("Select * from Win32_PerfRawData_PerfOS_Memory",,48)
For Each objItem in colItems
Wscript.Echo "AvailableMBytes: " & objItem.AvailableMBytes & "M"
Next
Set colItems = objWMIService.InstancesOf("Win32_LogicalMemoryConfiguration")
For Each colItem In colItems
WScript.Echo "Total Physical Memory: " & CLng(colItem.TotalPhysicalMemory / 1024) & "M"
Next
i = 0
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor",,48)
For Each objItem in colItems
Wscript.Echo "CPU(" & i & "): " & objItem.LoadPercentage
i = i + 1
Next
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")
For Each objDisk in colDisks
Wscript.Echo objDisk.DeviceID & vbTab & CLng(objDisk.FreeSpace /1024/1024) & "M"
Next
Wscript.Echo "End at " & Now()
===================End===================
随后又针对新环境,加了一个壳,从AD中获得所有服务器的列表,循环了一下。测试运行了一把,66台服务器,花了3分钟左右。
本文地址:http://com.8s8s.com/it/it36378.htm