THE SQL Server Blog Spot on the Web

Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | |
in Search

Buck Woody

Carpe Datum!

Performance Counters? There’s a script for that.

It’s not hard to get Performance Monitor counters in PowerShell 1.0, and it’s REALLY easy in 2.0. This is one I used yesterday to monitor network bytes in and out on 2.0 (keep all of the green lines in this post on the same line) :

get-counter -Counter "\Network Interface(*)\Bytes Total/sec" -SampleInterval 1 -MaxSamples 10

 

The –SampleInterval is in seconds, and the –MaxSamples sets how many you want. The –Counter parameter is the object and counter you want to monitor. Don’t know what they are for your system? No problem:

get-counter -ListSet *

 

Need to hit another computer? Easy Peasy – doesn’t even require remoting to be turned on (but you do need to have the rights to hit the perf counters):

get-counter -ComputerName COLLOSSUS -Counter "\Network Interface(*)\Bytes Total/sec" -SampleInterval 1 -MaxSamples 10

 

If your machine happens not to be named “COLLOSSUS”, just change that part J. And yes, you can use whatever counters you like, including SQL Server locks, blocks, etc. The full reference for get-counter is here: http://technet.microsoft.com/en-us/library/dd367892.aspx

 

Script Disclaimer, for people who need to be told this sort of thing:

Never trust any script, including those that you find here, until you understand exactly what it does and how it will act on your systems. Always check the script on a test system or Virtual Machine, not a production system. All scripts on this site are performed by a professional stunt driver on a closed course. Your mileage may vary. Void where prohibited. Offer good for a limited time only. Keep out of reach of small children. Do not operate heavy machinery while using this script. If you experience blurry vision, indigestion or heartburn during the operation of this script, see a physician.

Published Tuesday, January 05, 2010 7:02 AM by BuckWoody

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Uri Dimant said:

Hello Buck

Can you expand a little bit why you perfer or like using PowerShell in that case, I mean , would not it nbe easy to use PerfMonitor, dmv... what is advantages in your opinion?

Thanks

January 6, 2010 2:30 AM
 

ALZDBA said:

Nice disclaimer entrance and finish ;)

January 6, 2010 3:38 AM
 

Buck Woody said:

Uri -

I like having a variety of tools to perform any task. There are times when I use the graphical Performance Monitor, sometimes I use the counters exposed in the DMV's in SQL Server, and other times I use the LOGMAN tool that comes with Windows. But since I do a lot of work in PowerShell not only with SQL Server but with Windows, Exchange and so on, I can stay in PowerShell to talk to all of them.

January 6, 2010 10:18 AM
 

AllenMWhite said:

Uri, I did a presentation at PASS on using PowerShell to gather performance data, and echoed Buck's sentiments here: with other tools I have to gather different bits of information separately, then merge them together somehow to get the full picture.  PowerShell gives me the ability to gather everything using one tool, all at the same time.  (However, my scripts favor gathering the counters using the System.Diagnostics tools rather than the get-counter cmdlet.)

January 6, 2010 1:33 PM

Leave a Comment

(required) 
(required) 
Submit

About BuckWoody

http://buckwoody.com/BResume.html

This Blog

Syndication

Powered by Community Server (Commercial Edition), by Telligent Systems
  Privacy Statement