Get the number of current SharePoint connections

Here is a PowerScript function to automate the process of getting/logging the current number of connections to a particular Web Server.  It will tell you the number of connections for each site on the server, so you can see the number of SharePoint connections, SharePoint Central Admin connections, etc.  Thanks to MOW and Lee Holmes for their examples of using the PerformanceCounter class in PowerShell.

function Get-WebServiceConnections()
{
$results = @{}
$perfmon = new-object System.Diagnostics.PerformanceCounter
$perfmon.CategoryName = "Web Service"
$perfmon.CounterName = "Current Connections"

$cat = new-object System.Diagnostics.PerformanceCounterCategory("Web Service")
$instances = $cat.GetInstanceNames()

foreach ($instance in $instances)
{
$perfmon.InstanceName = $instance
$results.Add($instance, $perfmon.NextValue())
}
write-output $results
}

This will give me output like so:

PS C:\> Get-WebServiceConnections

Name Value
---- -----
_Total 12
SharePoint Central Administ... 1
SharePoint - 80 9
Default Web Site 2




PS C:\> $conns = Get-WebServiceConnections
PS C:\> $conns["SharePoint - 80"]
9
PS C:\>

 

You could set the CounterName to any of the other Web Service counters that are available, to do things like measure incoming and/or outgoing bytes per second, the number of incoming HTTP requests per second, etc.  To see a list of all available counters, use the GetCounters() method of the PerformanceCounterCategory ($cat in the example above, ie $cat.GetCounters(“SharePoint – 80”)).

Also, to get more information, you can use $perfmon.NextSample() instead of .NextValue().  NextSample() will return the enture CounterSample object, including RawValue and BaseValue (used to determine the value returned by NextValue()), TimeStamp, etc.

Print | posted on Wednesday, June 03, 2009 10:29 AM

Feedback

No comments posted yet.

Your comment:





 
 

Copyright © Lance Robinson

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski