Question

Ive created a server monitoring script written in classic ASP (Hosted on IIS 7.5).

It has a main page which uses jQuery to automatically reload the content (updating WMI information) It works great, but seems to have an appetite for memory!

There are 4 pages (Service status for 2 servers, printer status on a main DC and disk usage on the same server) The service status pages update every 10 seconds, the printers every 5 seconds and disk usage every minute.

The script basically works for a few hours, then i get code 500 internal server errors, once checking the IIS logs its because of it being "Out of memory" and look at the processes on the server and WmiPrvSvc.exe (NETWORK SERVICE account) is in the hundreds (500mb) and the ISS worker process (w3wp.exe) is using about 50mb (there are other w3ps.exe processes that are higher)

Once i end them both it kicks back into action… Or if i stop the page/requests for a while (varies between 30 sec and 5 mins) the WmiPrvScs ends and i don't get the problem.

Is there a way to minimise the memory usage or is there a command to properly disconnect / clear the memory?

Below is the basics of one of my pages to give you an idea of what's going on...

Thanks, Paul.

<%
    strComputer = "." 
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colListOfServices = objWMIService.ExecQuery("SELECT Caption, Started FROM Win32_Service WHERE StartMode = 'Auto'")

    Set arrServices = Server.CreateObject("System.Collections.ArrayList")


    intServices = colListOfServices.Count

    For Each objService in colListOfServices 
        arrServices.Add objService.Caption & "@" & objService.Started
    Next

    arrServices.Sort()
    Response.Write "<table width=""100%"" class=""tblServices"">" & vbCr
    For Each strService in arrServices
        If InStr(strService, ".NET Framework") = 0 AND InStr(strService, "Sophos Web Intelligence Update") = 0 AND InStr(strService, "Shell Hardware Detection") = 0 Then
            ' Above services, start at system startup and then stop after nothing to do
            arrServiceDetails = Split(strService, "@")
            strServiceName = arrServiceDetails(0)
            strServiceStatus = arrServiceDetails(1)


        End If
    Next

    Response.Write "</table>"

    Set objWMIService = Nothing
    Set colListOfServices = Nothing
    Set arrServices = Nothing   
%>
Was it helpful?

Solution

Are you calling the above code every 10 seconds? I´m not sure, but i looks like you are creating a new WMI object / connection everytime and that adds up. Instead try to keep the object around instead of recreating it. Something like a SingleTon class to hold the connection.

Also, try making a strongly typed class instead of the WMI query, you can do that by looking at this site: MGMTClassGen

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top