프로세스 메모리 사용량 초과 시 프로세스 Kill 규칙 VB Script (VBS) SystemCenter2009. 11. 12. 14:04
'Parameter [ProcessName.exe] [WorkingSetLimit(MB)] [EventID]
Set oArgs = WScript.Arguments
strTaskName = oArgs(0)
strWorkingSet = oArgs(1)
eNumber = oArgs(2)
Set oArgs = nothing
Set shellobj = WScript.CreateObject("WScript.Shell")
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Process where name ='" & strTaskName & "'", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
if clng(objItem.WorkingSetSize/(1024*1024)) > clng(strWorkingSet) then
objItem.Terminate()
strMsg = objItem.Name & "(이)가 WorkingSet 임계치(" & strWorkingSet & "MB)를 초과하여 Operations Manager에서 " & strTaskName & " 프로세스 중지명령을 내렸습니다. 이 프로세스(PID:" & cstr(objItem.ProcessId) & ")의 Workingset은 " & clng(objItem.WorkingSetSize/(1024*1024)) & "MB 입니다. "
strCommand = "EventCreate /L " & chr(34) & "Operations Manager" & chr(34) & " /SO " & chr(34) & "Operations Manager Agent" & chr(34) & " /T INFORMATION /ID " & eNumber & " /D " & chr(34) & strMsg & chr(34)
shellobj.Run "%COMSPEC% /C START /W " & strCommand, 0, TRUE
end if
Next
Set shellobj = nothing