MOTOBIT.COMGet number of current users and other IIS performance values.

About | IIS monitor | ASP upload | ASP dictionary | UserManager | Pure ASP upload script | Programming tips
Other articles:
Read and write SQL image data, store binary file to sql table. (WSH, Database, Conversion, VBScript)
Work with binary files in VBSscript - read and write local and remote files (WSH, File & data transfer, Functions, VBScript)
Download multiple files in one http request (File & data transfer, VBScript)
Do you like this article?
Please, rate it
and write review!
Rated:
by Aspin.com users
What do you think?
Areas > WMI
Areas > ASP / ASP.Net
    Do you want to monitor what is a number of current users on your website? You can use Win32_PerfRawData_W3SVC_WebService object.

    1. Get current annonymous users

Dim WebPerf, n 
Set WebPerf = GetObject("winmgmts:root\cimv2:Win32_PerfRawData_W3SVC_WebService.Name='_Total'") 
n = WebPerf.CurrentAnonymousUsers
Response.Write "Current number of users on this server:" & n 

    'n' is number of AnonymousUsers for whole server. You can use web site name instead of "_Total". 
    But there is no good idea to query this value each time on hi-loaded servers. You can use next algorithm to cache this number in application dictionary for 30 second period.
Function CurrentUsers
  on error resume Next
  Dim n, t
  t = application("curuserst")
  If isempty(t) Then
  elseif cdate(now-t) > #00:00:30# Then
  Else
    n = application("curusers")
  End If
  If isempty(n) Then
    application("curuserst") = now
    Dim CommonWeb
    Set CommonWeb = GetObject("winmgmts:root\cimv2:Win32_PerfRawData_W3SVC_WebService.Name='_Total'")
    n = CommonWeb.CurrentAnonymousUsers
    application("curusers") = n
  end if'if isempty(n) Then

  If isempty(n) Then n = 0
  CurrentUsers = n
End Function

    2. List more values for each web site :

    Win32_PerfRawData_W3SVC_WebService object contains many values. You can get a list of these values using getObjectText_ method:
Dim WebPerf
Set WebPerf = GetObject("winmgmts:root\cimv2:Win32_PerfRawData_W3SVC_WebService.Name='_Total'") 
Response.ContentType = "text/plain"
Response.Write "Win32_PerfRawData_W3SVC_WebService values:" & vbCrLf & WebPerf.getObjectText_ 

   Next code is a list of all local web-sites as an HTML table with basic IIS load info
Function PerfQuery
  Dim wmi, wql, instance, instances, html

  'Get wmi object
  Set wmi = GetObject("winmgmts:root/cimv2")

  'Query web sites with annonymous users
  wql = "select TotalAnonymousUsers, CurrentAnonymousUsers, " & _
   " CurrentISAPIExtensionRequests, MaximumAnonymousUsers, ISAPIExtensionRequestsPersec " & _
   " from Win32_PerfRawData_W3SVC_WebService where TotalAnonymousUsers>0"
  Set instances = wmi.ExecQuery(wql)


  'Table header  
  html = html & "<Table Border=0 CellPadding=0 CellSpacing=1 class=pd>"
  html = html & "<TR Class=pf><td> Web site </td>"
    html = html & "<Td Align=center> TotalAnonymousUsers </td>"
    html = html & "<Td Align=center> CurrentAnonymousUsers </td>"
    html = html & "<Td Align=center> MaximumAnonymousUsers </td>"
    html = html & "<Td Align=center> CurrentISAPIExtensionRequests </td>"
  html = html & "</tr>"

  'Format row values
  For Each instance In instances
    html = html & "<TR Class=pl><td> " & instance.name & " </td>"

    html = html & "<Td Align=Right> " & instance.TotalAnonymousUsers & " </td>"
    html = html & "<Td Align=Right> " & instance.CurrentAnonymousUsers & " </td>"
    html = html & "<Td Align=Right> " & instance.MaximumAnonymousUsers & " </td>"
    html = html & "<Td Align=Right> " & instance.CurrentISAPIExtensionRequests & " </td>"

    html = html & "</tr>"
  Next
  html = html & "</Table>"

  PerfQuery = html
End Function 

    3. Connect to another computer

    First method is using wmi URL - simple append computer name to path:
  Set wmi = GetObject("winmgmts://computername/root/cimv2")
    You cannot access to a second computer with other user account using GetObject. Next source code uses ConnectServer method of SWbemLocator object.
  Dim Locator, Connection
  'Create Locator object
  Set Locator = CreateObject("WbemScripting.SWbemLocator")

  'Connect To another server
  Set Connection = Locator.connectserver("ComputerName", "root\cimv2", "UserName", "Password")
  
  'Execute query on the server
  Dim Instances, wql
  wql = "..."
  Set Instances = Connection.ExecQuery(wql)

See also

for 'Get number of current users and other IIS performance values.' article

Copyright and use this code

The source code on this page and other samples at http://www.motobit.com/tips/ are a free code, you can use it as you want: copy it, modify it, use it in your products, ...
If you use this code, please:
1. Leave the author note in the source.
or
2. Link this sample from you page.
<A
 Href="http://www.motobit.com/tips/detpg_wmi-iis-performance/"
 Title="Short working wmi samples to show
	several IIS performance monitoring values
	- Current annonymous users, isapi extensions,
	etc."
>Get number of current users and other IIS performance values.</A>

© 1996 - 2012 Antonin Foller, Motobit Software | About, Contacts | e-mail: info@pstruh.cz


Partner sites: Search Czech Last minute Zajezdy Obsah na mobil Hry na mobil Java Hry Print-shop Affiliate programy

Kurzy: Akcie | Urad prace | Zakony | Zlato | Firmy | Dane


     IISTracer - IIS ISAPI real-time monitor IISTracer is a real-time monitoring tool for Microsoft IIS, which will show/log you what is happenning on IIS server right now. It let's you reveal problems with long-running scripts (.asp, .cgi, cfm...), hang-up states and low resource situations and lets you stop long-running requests (uploads/downloads).      ActiveX User account Manager - Set of simple objects for creating, deleting, and managing user accounts, groups, servers and domains in the Windows NT environment.
     Active log file - Hi-performance text file logging for ASP/VBS/VBA applications. Lets you create daily/weekly/monthly log files with variable number of logged values and extra timing and performance info.      ActiveX windows registry editor - Intuitive, easy to use COM interface to windows registry. Set of classes to read/enumerate/modify windows registry keys and values from ASP, VBS and T-SQL.
     ActiveX/ASP Multi Dictionary object - Free-threaded hi-speed dictionary algorithm with unique/nonunique keys (map/multimap). Connect to another dictionary object in the same process. Lock and Unlock methods to synchronize tasks (application scope). Share ASP Application/Session objects.      Export DBF/MDB from ASP - Conversion from recordset to MDB/DBF. Direct binary output of MDB or DBF files from ASP pages with one row of code.
     Pure-ASP upload - lets you upload files using Pure ASP VBS code (using multipart/form-data and input type=file).      ByteArray - Works with safearray binary data (VT_UI1 | VT_ARRAY) - save/restore binary data from disk, find, work with code pages, convert to string/hexstring(SQL).
     WebChecker - Checks http, https, ftp and gopher internet connections in regular intervals. Lets you monitor web site functionality (uptime). Enables restart or notification on problems.      HTTPLog ISAPI filter - Lets you log incomming/outgoing http header and document data to separate files. Monitor of IIS service input/output.
Motobit.com