|
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 https://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="https://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>
|