Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is XMLHTP the best solution for site monitoring?

Status
Not open for further replies.

jmreinwald

Technical User
Jun 3, 2002
46
US
First off, coming from a PHP background, I'm an absolute beginner to ASP and vbscript. My company needs a very simple monitoring tool built for some internal sites. They are not allowing me to install PHP, so I have to deal with what I already have available.

Basically, we have 10 hot-swappable drives, each configured for a particular portal environment (SAP, Plumtree, etc) with its own url.

I need the outline of a simple monitoring tool. With 10 portals running off only 3 servers, clearly only three will be "active" at any given time. That's what I need to know. Basically querying all 10 in turn and providing a simple check mark or "x" if it's up or not.

Again, being a complete newbie to asp/vbscript, I see (or at least think) that XMLHTTP may be the way to go, since it can "open" pages. Any help on where to go from there? With PHP it's actually very simple (using fopen()), but asp/vbscript is definitely a different beast!

Thanks in advance,
Joe
 
XMLHTTP would work in this situation, it's similar enough to fopen that the logic shouldn't be that differant. One thing that may be better than fopen in this case is that you could start opening all 10 pages synchronously and let them load before handling them like fopen OR you can allow them to load asynchronously, compressing the amount of time it takes to do the check.
Example:
Code:
'create an array of XMLHTTP objects
Dim objXMLHTTP(9)
'create an array of end addresses and array of matching server names
Dim addy(9), server(9)
'create an array of their status's
Dim status(9)

'Loop to 0-9 to crearte and start pulling in each address
Dim i
For i = 0 to 9
   'create individual object
   Set objXMLHTTP(i) = Server.CreateObject("Microsoft.XMLHTTP")
   'allow it to start it's request for it's address
   objXMLHTTP.Open "GET",addy(i),True
Next

'now for each one, wait until it is finished loading and post it's status
'   some of these will be done quicker then others, but the asynchrnous method we used ought to be faster than doing them one at a time
For i = 0 to 9
   Do Until objXMLHTTP(i).ReadyState = 4
      'state 4 means everything is loaded...so do nothing till it occurs
   Loop
   
   'content has loaded for this instance, set it's status
   status(i) = objXMLHTTP(i).Status

   'kill this object now that we are done with it, kinder to the server
   Set objXMLHTTP(i) = Nothing
Next

'now we can do whatever we want with the statuses
'   these are std HTTP statuses, ie 200 means success, 404 means not found, etc
For i = 0 to 9
   If status(i) = "200" Then
      Response.Write "<span style=""color:green"">" & server(i) & "</span>"
   Else
      Response.Write "<span style=""color:green"">" & server(i) & "</span>"
   End If
Next

Anyways, I just threw that together so it may have a typo or two in it.

One thing I would suggest doing is to not do this in the ASP script. I would suggest writing a small vbs file that has the same logic (array of XMLHTTP objects, etc) that writes the results to a text file. You could even have it output a static HTML file to the web directory for you. Then add it as a scheduled task to run every 5 minutes or so. This will increase the load if your page won't be getting many hits, but decrease the load if people are going to be looking at it frequently. I would also suggest adding a meta refresh tag to the static html page that refreshes it automatically every 5 minutes. I have a similar schdulued script (except it is in perl and is a cron job on my nix box) because I didn't want to incur extra load if more than 1 person was looking at it every 5 minutes.

Hope this helps,
-T

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
The never-completed website:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top