VBScript: Monitor HTTP response time

I needed to check if my Nagios monitoring system was working properly because I got a lot of error messages about web sites response time, so I decided to log this result generated with another monitoring tool; what is quicker than vbscript ?

The following script and many other are also available on my web site http://www.vittorio.tk

CheckHost("http://www.vittorio.tk")

Sub CheckHost(host)
dim startdate
Dim objXmlHttp
Dim strHTML
Set objXmlHttp = CreateObject("Msxml2.ServerXMLHTTP")
lResolve = 1 * 1000
lConnect = 5 * 1000
lSend = 10 * 1000
lReceive = 10 * 1000
objXmlHttp.setTimeouts lResolve, lConnect, lSend, lReceive
startdate = now
t1 = timer
objXmlHttp.open "GET", host , False
objXmlHttp.send
If Err.number = 0 and objXmlHttp.status = 200 then
Result = "OK"
'objXmlHttp.responseText
else
Result = "Error"
end if
t2 = timer
Set objXmlHttp = Nothing
wscript.echo "Host: " & host & vbcrlf & "StartTime: " & startdate & vbcrlf & "Result: " & Result & vbcrlf & "Response Time: " & TimeDiff(t2,t1) & "msec"
End sub

Function TimeDiff(iEnd, iStart)
Dim iReturn
iReturn = iEnd - iStart
If iReturn < ireturn =" iEnd" timediff =" 1000">
TimeDiff = 1000 * iReturnEnd Function

End Function


Share on Google Plus

About Vittorio Pavesi

    Blogger Comment
    Facebook Comment

2 commenti:

Anonymous said...

Minimum timer interval is 1/256 seconds = 3,9 milliseconds

Anonymous said...

got error, expected end of statement