Everything about Web and Network Monitoring

Home > Server Management > Windows Servers Monitoring > Monitoring IIS With VBScript via Monitis; It’s so Easy!

Monitoring IIS With VBScript via Monitis; It’s so Easy!

As Buddy Holly once said: “It’s so easy!”  Rock star Holly was talking about falling in love. But we’re talking about monitoring Internet Information Services (IIS) with Visual Basic Scripting (VBScript) via Monitis. 

In previous posts, we already learned how to access Performance Counters metrics, and How to Monitor Windows Servers with VBScript, WMI and Monitis.  But, in this article, we will put everything together and create a Monits page with the most important parameters for monitoring an IIS Server in production.

Here are the parameters we are going to discuss for monitoring:

Availability: Monitorig your webisite to see if it’s available and to measure how fast it responds; this can be performed using a Monitis External Monitor.

Bytes Sent per Minute, Bytes Received per Minute: The amount of bytes transferred by your website as a result of serving web pages or accepting requests and POST data.  You can do this via Monitis Web Traffic Monitoring.

Current Connections: The number of users currently connected to all websites served by your IIS server.

Total Get Requests per Minute: The number of GET requests (a URL and headers) are received by all websites served by your IIS server.

Monitoring the current usage parameter will help you understand how your site is used and after establishing a baseline you will also be able to configure thresholds — with Monitis Web Load Testing — to detect unusually high activity.

 

Creating a page with the Custom Monitors

Powerful Monits API allows you to write script that performs a lot of work on your behalf.
The following script creates all the necessary monitors and adds them to a new page.

apiKey = "You API key here"
secretKey = "You Secret Key here”

dtGMT = GMTDate()

'Initialize HTTP connection object
Set objHTTP = CreateObject("Microsoft.XMLHTTP")

'Request a token to use in following calls
url = "http://www.monitis.com/api?action=authToken&apikey=" + apiKey + "&secretkey=" + secretKey
objHTTP.open "GET", url, False
objHTTP.send
resp = objHTTP.responseText
token = DissectStr(resp, "authToken"":""", """")

'Add a page
url = "http://www.monitis.com/api"
page_title = "IIS"
group = "IIS"
columns = "2"
objHTTP.open "POST", url, False
objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
postData = "apikey=" + apiKey + "&validation=token&authToken=" + token + "&timestamp=" + FmtDate(dtGMT) + "&action=addPage&title=" + page_title + "&columnCount=" + columns
objHTTP.send postData
resp = objHTTP.responseText
pageID = DissectStr(resp, "pageId"":", "}")

tag = "IIS"

url = "http://www.monitis.com/api"
objHTTP.open "POST", url, False
site = "www.yoursite.com"
objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
postData = "apikey=" + apiKey + "&validation=token&authToken=" + token + "&timestamp=" + FmtDate(dtGMT) + "&action=addExternalMonitor&type=http&name=Availability"
postData = postData + "&tag=" + tag  + "&url=" + site + "&locationIds=1,2&interval=5&timeout=10000&overSSL=false&detailedTestType=1&fromDashboard=true"
objHTTP.send postData
resp = objHTTP.responseText
testID = DissectStr(resp, "testId"":", ",")

url = "http://www.monitis.com/api"
row = 1 : colunm = 1
objHTTP.open "POST", url, False
objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
postData = "apikey=" + apiKey + "&validation=token&authToken=" + token + "&timestamp=" + FmtDate(dtGMT) + "&action=addPageModule&moduleName=External&pageId=" + pageID + "&column=" & colunm & "&row=" & row & "&dataModuleId=" + testID

objHTTP.send postData
resp = objHTTP.responseText

'Current connections
monitorParams = "Connections:Current connections:Connections:3:false;"
resultParams = "connections:Connections:N%2FA:2;"
name = "Current connections" : row = 2 : colunm = 1
AddCustMon

'% Bytes transmitted
monitorParams = "Bytes:Bytes transmitted per minute:Bytes:3:false;"
resultParams = "sent:Sent:N%2FA:2;received:Received:N%2FA:2;"
name = "Bytes transmitted per minute" : row = 3 : colunm = 1
AddCustMon

'GET requests per minute
monitorParams = "GET Requests:GET requests per minute:req/min:3:false;"
resultParams = "requests:Requests/min:N%2FA:2;"
name = "GET requests per minute" : row = 4 : colunm = 1
AddCustMon

Sub AddCustMon
  url = "http://www.monitis.com/customMonitorApi"
  objHTTP.open "POST", url, False
  objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  postData = "apikey=" + apiKey + "&validation=token&authToken=" + token + "&timestamp=" + FmtDate(dtGMT) + "&action=addMonitor&monitorParams=" + monitorParams + "&resultParams=" + resultParams + "&name=" + name + "&tag=" + tag
  objHTTP.send postData
  resp = objHTTP.responseText
  testID = DissectStr(resp, "data"":", "}")

  url = "http://www.monitis.com/api"
  objHTTP.open "POST", url, False
  objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  postData = "apikey=" & apiKey & "&validation=token&authToken=" & token & "&timestamp=" & FmtDate(dtGMT) & "&action=addPageModule&moduleName=CustomMonitor&pageId=" & pageID & "&column=" & colunm & "&row=" & row & "&dataModuleId=" & testID
  objHTTP.send postData
  resp = objHTTP.responseText
End Sub

Function DissectStr(cString, cStart, cEnd)
  dim nStart, nEnd
  nStart = InStr(cString, cStart)
  if nStart = 0 then
    DissectStr = ""
  else
    nStart = nStart + len(cStart)
    if cEnd = "" then
      nEnd = len(cString)
    else
      nEnd = InStr(nStart, cString, cEnd)
      if nEnd = 0 then nEnd = nStart else nEnd = nEnd - nStart
    end if
    DissectStr = mid(cString, nStart, nEnd)
  end if
End Function

Function FmtDate(dt)
  FmtDate = cstr(Datepart("yyyy", dt)) + "-" + right("0" + cstr(Datepart("m", dt)),2) + "-" +  right("0" + cstr(Datepart ("d", dt)),2) + " " + right("0" + cstr(Datepart("h", dt)),2) + ":" + right("0" + cstr(Datepart("n", dt)),2) + ":" + right("0" + cstr(Datepart("S", dt)),2)
end function

Function GMTDate()
  dim oWMI, oRes, oEntry
  Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
  GMTDate = now
  Set oRes = oWMI.ExecQuery("Select LocalDateTime from Win32_OperatingSystem")
  For each oEntry in oRes
    GMTDate = DateAdd("n", -CInt(right(oEntry.LocalDateTime, 4)), GMTDate)
  next
End function

 

Uploading values

Values for this script comes from Performance Counter WMI classes.

apiKey = "You API key here"
secretKey = "You Secret Key here”

'Connecting to WMI, "." is for local computer, specify computer name for another computer
computer = "."
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + computer + "\root\cimv2")

'Finds current timezone to obtain GMT date
dtGMT = now
Set oRes = oWMI.ExecQuery("Select LocalDateTime from Win32_OperatingSystem")
For each oEntry in oRes
  dtGMT = DateAdd("n", -CInt(right(oEntry.LocalDateTime, 4)), dtGMT)
next

dtGMT = GMTDate()
unixDate = CStr(DateDiff("s", "01/01/1970 00:00:00", DateSerial(Year(dtGMT), Month(dtGMT), Day(dtGMT)) + TimeSerial(Hour(dtGMT), Minute(dtGMT), Second(dtGMT)))) + "000"

'Initialize HTTP connection object
Set objHTTP = CreateObject("Microsoft.XMLHTTP")

'Request a token to use in following calls
url = "http://www.monitis.com/api?action=authToken&apikey=" + apiKey + "&secretkey=" + secretKey
objHTTP.open "GET", url, False
objHTTP.send
resp = objHTTP.responseText
token = DissectStr(resp, "authToken"":""", """")

'Requests the monitor list in order to find the MonitorID
tag = "IIS"
url = "http://www.monitis.com/customMonitorApi?action=getMonitors&apikey=" + apiKey + "&tag=" + tag + "&output=xml"
objHTTP.open "GET", url, False
objHTTP.send
resp = objHTTP.responseText

Set oResp = CreateObject("Microsoft.XMLDOM")
oResp.async = False
oResp.LoadXML(resp)

Set oRes = oWMI.ExecQuery ("select * from Win32_PerfFormattedData_W3SVC_WebService where Name = '_Total'")
For each oEntry in oRes

  monitorID = FindMonitorID("Current connections")
  results = "connections:" & oEntry.CurrentConnections & ";"
  AddResult

  monitorID = FindMonitorID("Bytes transmitted per minute")
  results = "received:" & (oEntry.BytesReceivedPersec * 60) & ";sent:" & (oEntry.BytesSentPersec * 60) & ";"
  AddResult

  monitorID = FindMonitorID("GET requests per minute")
  results = "requests:" & (oEntry.GetRequestsPersec * 60) & ";"
  AddResult

next

Function FindMonitorID(monitorName)
  for each oNode in oResp.documentElement.childnodes
    if oNode.selectSingleNode("name").text = monitorName then
      FindMonitorID = oNode.selectSingleNode("id").text
	  exit for
    end if
  next
End Function

Sub AddResult
  url = "http://www.monitis.com/customMonitorApi"
  action = "addResult"
  objHTTP.open "POST", url, False
  objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  postData = "apikey=" + apiKey + "&validation=token&authToken=" + token + "&timestamp=" + FmtDate(dtGMT) + "&action=" + action + "&monitorId=" + monitorID + "&checktime=" + unixDate + "&results=" + results
  objHTTP.send postData
  resp = objHTTP.responseText
End sub

Function DissectStr(cString, cStart, cEnd)
  'Generic string manipulation function to extract value from JSON output
  dim nStart, nEnd
  nStart = InStr(cString, cStart)
  if nStart = 0 then
    DissectStr = ""
  else
    nStart = nStart + len(cStart)
    if cEnd = "" then
      nEnd = len(cString)
    else
      nEnd = InStr(nStart, cString, cEnd)
      if nEnd = 0 then nEnd = nStart else nEnd = nEnd - nStart
    end if
    DissectStr = mid(cString, nStart, nEnd)
  end if
End Function

Function FmtDate(dt)
  FmtDate = cstr(Datepart("yyyy", dt)) + "-" + right("0" + cstr(Datepart("m", dt)),2) + "-" +  right("0" + cstr(Datepart ("d", dt)),2) + " " + right("0" + cstr(Datepart("h", dt)),2) + ":" + right("0" + cstr(Datepart("n", dt)),2) + ":" + right("0" + cstr(Datepart("S", dt)),2)
end function

Function GMTDate()
  GMTDate = now
  Set oRes = oWMI.ExecQuery("Select LocalDateTime from Win32_OperatingSystem")
  For each oEntry in oRes
    GMTDate = DateAdd("n", -CInt(right(oEntry.LocalDateTime, 4)), GMTDate)
  next
End function

After letting the monitors run for a while, your console will look like this:

IIS Monitoring

Configuring Thresholds and Notifications

 

Monitis allows you to configure thresholds on monitored values so you can be alerted if any of the samples is above or below an acceptable value.

In order to be alerted, you need to configure at least one email address in your Monitis account:

  1. Click on the Account menu, then Contacts then Add Contact:
  2. Fill the values in the windows that will pop up and then click Add

To configure the notification rules follow these steps:

 

  1. Move the mouse cursor over the bar at the top of the Custom Monitor that you want to configure; a set of icons will appear in the right corner;
  2. Click on the orange pencil icon, the widget will expand and some buttons will appear. This is what you should see:

IIS Monitoring

 

  1. Click on the Notification Rules button, another window will pop up:

IIS notification rules

  1. In Event Value, configure the threshold value. Choose to alert when the current value is more than, less than or equal to the configured value.
  2. If the chart includes more that one value in Event Parameter, choose the value to set the alert for.
  3. In order to avoid being alerted for each transient peak, set a number in “Failures required to trigger an alert”. For example, if you’re monitoring the Connections with a sample rate of 5 minutes, setting “6” in this value will alert you only if the connections count exceed the threshold for longer that 30 minutes.
  4. Click Add Rule and then Done

See how easy it is to monitor IIS with Visual Basic Scripting (VBScript) via Monitis?! No need to take our word for it, though, check out what others are saying about Monitis and our monitoring cloudware.

Related blogs:
Top 8 Application-Based IIS Server Performance Tips
How to Monitor Windows Servers with VBScript, WMI and Monitis
Automating Data Collection for Your Custom Monitors
How to Easily Monitor Windows Performance Counters with VBScript on Monitis

 

Post Tagged with , ,
Hovhannes Avoyan

About Hovhannes Avoyan

Monitis CEO – Hovhannes is an international entrepreneur with a recognized and respected reputation in the high tech industry. His technical expertise, combined with his drive to build the best business/product, has positioned him as a visionary international extension of Silicon Valley.

Web & Cloud
Monitoring