WMI Learning Notes (1) - Write the Script to Monitor the Performance of the Windows Server

xiaoxiao2021-03-06  100

Copyright Notice: You can reprint anything, you must indicate the original source and author information in hyperlink when reprint.

Come to the new unit, I found that the server here is not mentioning thousands, it is more than five, six times more than the previous unit. It seems that only use of some monitoring tasks can be achieved. I didn't have interest to read the WMI scripting programming of the two eyes. I spent a half-day time to write a program that gains data information of the CPU, memory and the remaining space of the hard disk:

=================== Enumsingerl.vbs ====================

Const hard_disk = 3wscript.echo "Program Start AT" & now ()

? strComputer = "."

? 'Connection 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 * WIN32_PROCESSOR", 48) ??? for each Objitem in colitems ??????? wscript.echo "CPU (" & i & "):" & objitem.loadpercentage ???? i = i 1 ??? Next

??? set colorisks = objwmiservice.execquery _ ??????? ("SELECT * WIN32_LOGICALDISK WHERE DRIVETYPE =" & HARD_DISK & ") ??? for Each ObjDisk in Coldisks ??????? WScript. Echo objDisk.deviceid & vbtab & clng (ObjDisk.Freespace / 1024/1024) & "m"? Nextwscript.echo "End At" & now "& now ()

=================== End ====================

Subsequently, it adds a shell to the new environment, and obtains a list of all servers from the AD, which is loop. The test runs a, 66 servers, spent about 3 minutes.

Currently, it is a very rough version, which plans to make some improvements in the future time in the future, data collection, and critical alarms.

How to write WMI scripts, see "WMI Learning Notes".

转载请注明原文地址:https://www.9cbs.com/read-123589.html

New Post(0)