Windows OS Hub
  • Windows Server
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Group Policies
  • Windows Clients
    • Windows 10
    • Windows 8
    • Windows 7
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
  • PowerShell
  • Exchange
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Group Policies
  • Windows Clients
    • Windows 10
    • Windows 8
    • Windows 7
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
  • PowerShell
  • Exchange

 Windows OS Hub / Windows Server 2012 R2 / How to See Number of Active User Sessions on IIS site?

November 2, 2018 PowerShellWindows Server 2012 R2Windows Server 2016

How to See Number of Active User Sessions on IIS site?

How to quickly estimate the current number of user connections (sessions) to the IIS sites on webserver running on Windows Server? Such information will allow to determine and predict the load on the server, choose the best time for the maintenance and updates of the website, predict the IIS server’s load when the number of users increases.

The easiest way to determine the number of active user sessions on the IIS Web site is to use the performance counters in Windows Performance Monitor.

Open the Performance Monitor console by running the perfmon command and go the Performance monitor section (Monitoring Tools — > Performance Monitor).

Then you need to add the necessary counters to the monitor window (by default, the total CPU usage counter is displayed, but you can remove it). To add a new counter, click the green button on the toolbar (you can see it on the screenshot) or press Ctrl+N on the keyboard.

windows performance monitor

In the list of available counters, find and expand the Web Service group. In this category, we are interested in three counters:

  • Current Anonymous Users – the number of anonymous IIS users;
  • Current Non-Anonymous Users – the number of authorized IIS users;
  • Current Connections – total number of active connections on the IIS server.

Select the desired counter and in the Instances of selected objects choose one or more IIS websites for which you want to display connection information. The information about users of all websites on the server is stored in the _Total instance. Now you only have to click the Add >> button to move the counter to the list of the counters to be added in the right pane.

iis performance counters

Add all the necessary counters in the same way and click OK.

iis current user connections graph

Now the information about the number of user sessions in the Performance Manager console is being displayed in the real time (by default, the counter values are displayed as linear graphs). If you select any of the counters in the bottom pane, you can view its last, average, minimum or maximum value for a given period of time.

You can add custom performance counters to this console and save them in a separate view, which can be used later to quickly access the web server load data.

You can access the IIS performance counters from PowerShell. To do this, you can use the Get-Counter cmdlet. The list of all available Web Service performance counters can be displayed as follows:

(Get-Counter -ListSet 'Web Service').counter

Get-Counter Web-Service

To get information about the current number of active connections on the IIS server (the counter \Web Service(*)\Current Connections), use this command:

Get-Counter -Counter “\Web Service(*)\Current Connections”

As you can see, this command returned both the total number of connections to the IIS server and the statistics for each of the sites.

Tip.

  • The values of several counters can be displayed if you specify them separated by the commas;
  • With the –Continuous option, the information about the value of the counter is constantly displayed in the console until you’ll interrupt it using CTRL+C.

You can get the number of active sessions for a specific IIS site. For example, to get the current number of connections on a site named Site1, run the following command:

Get-Counter "web service(Site1)\current connections" -ComputerName web-srv01

You can specify the name of the server on which the counter value is checked. When you are checking the number of connections on the site locally, specifying localhost is not allowed:

powershell get iis connections
In order not to specify the server name each time, you can use the environment variable COMPUTERNAME:

Get-Counter "web service(Site1)\current connections" -ComputerName $env:COMPUTERNAME

To get the numeric value of the counter “current connections” of the entire IIS web server (total users on IIS), you can use this command:

((Get-Counter -Counter 'web service(_total)\current connections' -computer $env:COMPUTERNAME) |     Select-Object -Expand countersamples).Cookedvalue

Let’s try using a simple script to create several additional sessions with our site and check the counter value. You can increase the number of connections to the IIS website using the Invoke-WebRequest cmdlet, or you can simply open several windows in the browser:

$counter = 20
for($i=1;$i -le $counter;$i++){
$SiteAdress = "http://localhost:9666/"
Start-Process $SiteAdress
}

Check the value of the current connections counter and make sure that it increases.

If several IIS sites are running on the server, and you need to get the number of connections to each of them in a form of table, you can use this script (to receive data from IIS into PowerShell, you need to load the WebAdministration module):

import-module webadministration
function get-CurrentConnection($Site) {
Get-Counter "web service($Site)\current connections,web service($Site)\ Bytes Received/sec,web service($Site)\Bytes Sent/sec" -ComputerName $env:COMPUTERNAME
}
$IISsites = dir IIS:\Sites | Select Name
$CurrentConnection = @()
foreach ($site in $IISsites)
{
Write-Host $site
$ConnCount = New-Object psobject | get-CurrentConnection -Site $site.name
$CurrentConnection += $ConnCount
}
$CurrentConnection|out-gridview

posh script to get iis user connections number

You can also display the numerical values of connection counters for all sites (the first value is the total number of connections to IIS):

Get-wmiObject -class Win32_PerfRawData_W3SVC_WebService | select-object -expand currentconnections

Get-wmiObject Win32_PerfRawData_W3SVC_WebService currentconnectionsYou can display information about the amount of received/sent data for each site or the entire web server using the Web service(sitename)\Bytes Received/sec and Web service(sitename)\Bytes Sent/sec counters.

So, we looked at a way to get information about the load on sites running on the IIS web server.

0 comment
3
Facebook Twitter Google + Pinterest
previous post
High CPU Usage by Ntoskrnl.exe (System) Process in Windows 10
next post
How to Clean Up “System Volume Information” Folder

Related Reading

How to Backup Hyper-V Virtual Machines?

December 10, 2019

How to Change a Network Location from Public...

December 9, 2019

Configuring Storage Replica on Windows Server 2016

December 4, 2019

Running PowerShell Script (*.PS1) as a Windows Service

November 27, 2019

How to Delete Old User Profiles Using GPO...

November 19, 2019

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange
  • Windows 10
  • Windows 8
  • Windows 7
  • Windows Server 2016
  • Windows Server 2012 R2
  • Windows Server 2008 R2
  • PowerShell
  • VMWare
  • MS Office

Follow us

woshub.com

Recent Posts

  • How to Backup Hyper-V Virtual Machines?

    December 10, 2019
  • How to Change a Network Location from Public to Private on Windows 10/Windows Server 2016?

    December 9, 2019
  • Configuring Storage Replica on Windows Server 2016

    December 4, 2019
  • Windows 10 Install Error 0x80300024

    December 2, 2019
  • Running PowerShell Script (*.PS1) as a Windows Service

    November 27, 2019
  • Creating Multiple Partitions on a USB Drive in Windows 10

    November 26, 2019
  • VMWare vSphere: Failed to Upload Files to Datastore

    November 21, 2019
  • How to Delete Old User Profiles Using GPO and PowerShell?

    November 19, 2019
  • Get-ADUser: Getting Active Directory Users Info via Powershell

    November 18, 2019
  • How to Recover Deleted Files from a TRIM-Enabled SSD?

    November 14, 2019
  • Facebook
  • Twitter
  • RSS
Popular Posts
  • Get-ADUser: Getting Active Directory Users Info via Powershell
  • Install RSAT Feature on Demand on Windows 10 1809 and Later
  • Get-ADComputer: Find Computer Details in Active Directory with PowerShell
  • Managing Printers and Drivers with PowerShell in Windows 10 / Server 2016
  • How to Create a Self-Signed Certificate Using PowerShell
  • Invoke-WebRequest: Parsing HTML Webpages with Powershell
  • Using PowerShell Behind a Proxy
Footer Logo

@2014 - 2018 - Windows OS Hub. All about operating systems for sysadmins


Back To Top