More info? Check the SharePoint Dragons blog at http://sharepointdragons.com/ !
 
You may find that this gallery upload is more than you think (wasn't that the slogan of Office once?). Although, thanks to the power of PowerShell, the amount of code is very small, the research behind it took several days. Choosing the correct set of performance counters for monitoring SharePoint WFE's and back-ends is a daunting task, and this is my attempt.
The performance counters that I provide for WFE's include the basic set that are available for every installation plus InfoPath counters. If you're using specific other features (such as SSRS, BCS and such) I suggest you complement the existing set of counters.
What you need to do is the following:
1) Open a PowerShell command propmpt.
2) Run the following command:
PowerShell
Edit|Remove
get-counter -counter (get-content mycounters.txt) -MaxSamples 100 -sampleinterval 5 | export-clixml test.xml 
 
This makes sure that 100 samples are taken every 5 seconds (of course, it's up to you to vary). If you want to sample indefinitely, use the -Continuous flag. Please note that in my case, I'm building a tool that performs statististcal analysis about these data, because of this I want a data corpus that's sufficiently large, that's why I chose to do 100 samples (a number suitable to determine statistical significance, but that's another discussion). Exporting the results to XML makes it easy for me to process the data. If you want to use the data to take a look at it in perfmon, you're better of using the export-counter cmdlet.
The counters for a WFE are the following (place them in a text file, e.g. mycounters.txt):
PowerShell
Edit|Remove
\ASP.NET\Application Restarts 
\ASP.NET\Request Execution Time 
\ASP.NET\Requests Rejected 
\ASP.NET\Requests Queued 
\ASP.NET\Worker Process Restarts 
\ASP.NET\Request Wait Time 
\ASP.NET Applications(*)\Requests/Sec 
\InfoPath Forms Services 14(_Total)\# Business Logic Assemblies in Memory 
\InfoPath Forms Services 14(_Total)\# of Forms in Memory 
\InfoPath Forms Services 14(_Total)\# of Form Templates in Memory 
\InfoPath Forms Services 14(_Total)\# of Cached Form Templates 
\InfoPath Forms Services 14(_Total)\Data Connection Query Failure Rate 
\InfoPath Forms Services 14(_Total)\Data Connection Query Completed Rate 
\InfoPath Forms Services 14(_Total)\Avg. Data Adapter Query Duration 
\InfoPath Forms Services 14(_Total)\Data Connection Submit Failure Rate 
\InfoPath Forms Services 14(_Total)\Data Connection Submit Completed Rate 
\InfoPath Forms Services 14(_Total)\Data Connection Submit Started Rate 
\InfoPath Forms Services 14(_Total)\Avg. Data Connection Submit Duration 
\InfoPath Forms Services 14(_Total)\Session Completed Rate 
\InfoPath Forms Services 14(_Total)\Session Started Rate 
\InfoPath Forms Services 14(_Total)\Avg. Session Duration 
\InfoPath Forms Services 14(_Total)\Transactions Completed Rate 
\InfoPath Forms Services 14(_Total)\Transactions Started Rate 
\InfoPath Forms Services 14(_Total)\Avg. Transaction Duration 
\LogicalDisk(*)\% Idle Time 
\Memory\Available MBytes 
\Memory\% Committed Bytes In Use 
\Memory\Page Faults/sec 
\Memory\Pages Input/sec 
\Memory\Page Reads/sec 
\Memory\Pages/sec 
\Memory\Pool Nonpaged Bytes 
\Network Interface(*)\Bytes Total/sec 
\Network Interface(*)\Packets/sec 
\Paging File(*)\% Usage 
\PhysicalDisk(*)\Current Disk Queue Length 
\PhysicalDisk(*)\% Disk Time 
\PhysicalDisk(*)\Disk Transfers/sec 
\PhysicalDisk(*)\Avg. Disk sec/Transfer 
\Process(*)\% Processor Time 
\Process(*)\Page Faults/sec 
\Process(*)\Page File Bytes Peak 
\Process(*)\Page File Bytes 
\Process(*)\Private Bytes 
\Process(*)\Virtual Bytes Peak 
\Process(*)\Virtual Bytes 
\Process(*)\Working Set Peak 
\Process(*)\Working Set 
\Processor(*)\% Processor Time 
\Processor(*)\Interrupts/sec 
\Redirector\Server Sessions Hung 
\Server\Work Item Shortages 
\System\Context Switches/sec 
\System\Processor Queue Length 
\Web Service(*)\Bytes Received/sec 
\Web Service(*)\Bytes Sent/sec 
\Web Service(*)\Total Connection Attempts (all instances) 
\Web Service(*)\Current Connections 
\Web Service(*)\Get Requests/sec 
\SharePoint Foundation(*)\Sql Query Executing  time 
\SharePoint Foundation(*)\Executing Sql Queries 
\SharePoint Foundation(*)\Responded Page Requests Rate 
\SharePoint Foundation(*)\Executing Time/Page Request 
\SharePoint Foundation(*)\Current Page Requests 
\SharePoint Foundation(*)\Reject Page Requests Rate 
\SharePoint Foundation(*)\Incoming Page Requests Rate 
\SharePoint Foundation(*)\Active Threads 
 
 You can get them as data collector set XML over here: http://gallery.technet.microsoft.com/Data-Collector-Set-for-a-08c6a39d
The counters for the SQL Server back-end are:
PowerShell
Edit|Remove
\Memory\Available MBytes 
\Memory\% Committed Bytes In Use 
\Memory\Page Faults/sec 
\Memory\Pages Input/sec 
\Memory\Page Reads/sec 
\Memory\Pages/sec 
\Memory\Pool Nonpaged Bytes 
\Network Interface(*)\Bytes Total/sec 
\Network Interface(*)\Packets/sec 
\PhysicalDisk(*)\Current Disk Queue Length 
\PhysicalDisk(*)\% Disk Time 
\PhysicalDisk(*)\Disk Read Bytes/sec 
\PhysicalDisk(*)\Disk Write Bytes/sec 
\PhysicalDisk(*)\Avg. Disk sec/Transfer 
\Process(*)\% Processor Time 
\Process(*)\Page Faults/sec 
\Process(*)\Page File Bytes Peak 
\Process(*)\Page File Bytes 
\Process(*)\Private Bytes 
\Process(*)\Virtual Bytes Peak 
\Process(*)\Virtual Bytes 
\Process(*)\Working Set Peak 
\Process(*)\Working Set 
\Processor(*)\% Processor Time 
\Processor(*)\Interrupts/sec 
\Redirector\Server Sessions Hung 
\Server\Work Item Shortages 
\SQLServer:Buffer Manager\Buffer cache hit ratio 
\SQLServer:Databases(*)\Transactions/sec 
\SQLServer:Databases(*)\Data File(s) Size (KB) 
\SQLServer:Databases(*)\Log File(s) Size (KB) 
\SQLServer:General Statistics\User Connections 
\SQLServer:Locks(*)\Lock Wait Time (ms) 
\SQLServer:Locks(*)\Lock Waits/sec 
\SQLServer:Locks(*)\Number of Deadlocks/sec 
\SQLServer:Transactions\Free Space in tempdb (KB) 
\System\Context Switches/sec 
\System\Processor Queue Length 
\SQLServer:SQL Statistics\Batch Requests/sec 
 
 
You can get them as data set collector XML over here: http://gallery.technet.microsoft.com/Data-Collector-Set-for-6fefef51
 You may find that if you query the performance counters repeatedly that sometimes the values of a specific performance counter is (temporary) not available. You will see an exception that says something like "data in one of the performance counter samples is not valid. View status property..." This is unavoidable when working with performance counters. Instead, you could create a script (.ps1) file that tests the status property, retrieve the performance counters that are available at that time and persist it to an xml file. You can make the xml file unique by using a timestamp. Call the script from a batch (.bat) file and schedule that as a Windows scheduled task so that it creates performance counter dumps repeatedly.
Create a LogCounters.ps1 file and add the following contents:
PowerShell
Edit|Remove
$fileName = "test{0:yyyyMMdd-HHmmss}.xml" -f (Get-Date) 
  
(get-counter -counter (get-content counters.txt) ).countersamples | where { $_.status -eq 0 } | Export-Clixml $fileName 
 Then, create a batch file called LogCounters.bat and add the following contents:
Windows Shell Script
Edit|Remove
powershell -ExecutionPolicy RemoteSigned -File "C:\temp\log\logcounters.ps1" 
 
If you want to prevent a pop-up screen to appear as the result of a scheduled task action, create a LogCounters.vbs file and call that instead in the Windows scheduled task:
Visual Basic
Edit|Remove
Set WinScriptHost = CreateObject("WScript.Shell") 
WinScriptHost.Run Chr(34) & "C:\temp\log\LogCounters.bat" & Chr(34), 0 
Set WinScriptHost = Nothing 
 
  
 
  
If you want to add more performance counters to the list, you can do this via the -listset parameter. The following command shows how to get all path names of the various SharePoint Foundation performance counters:
PowerShell
Edit|Remove
(get-counter -listset "sharepoint foundation").paths