Use Command Line To Monitor Server Performance

Overview

For IT Pros, knowing how a server is behaving or performing is critical. Ideally, you want your servers to be performing optimally to keep your boss and end users happy. Or you may need to peek at what is going on to solve a problem. There are a number of 3rd party performance monitoring tools, not to mention the Performance Monitor management console that comes with every version of Windows, but sometimes you only need a “quick and dirty” solution. For those situations, you can turn to your command prompt and TYPEPERF.EXE.

TYPEPERF.EXE

As with most performance monitoring, the best approach is to remotely monitor the system in question. So we’ll use typeperf from a Windows 7 desktop. Open a command prompt. If you don’t have a shortcut handy to CMD.EXE click on the Start orb and type cmd.exe in the Search box. Click on the link. To see how to use this tool at the prompt type: typeperf /?.
TypePerf Figure1
Figure 1 TypePerf help

There are two types of performance counters: those with instances and those without. The former are counters that apply for each instance of an object, such as a logical disk or processor. For example there is a counter with no instances that will return the % processor time. Or you can get a counter that is instance specific, say for the first processor. To get the list of counters I would suggest these commands:

​C:\> typeperf –q > c:\work\counters-noinstance.txt
C:\> typeperf –qx –c:\work\counters.txt

These commands will run against your Windows 7 box. If you are interested in application counters that might exist on a remote server, then incluse the –s parameter.

​C:\> typeperf –q c:\work\server1-counters-noinstance.txt –s server1

Once you’ve identified the counter or counters, at the prompt run a command like this:

​C:\> typeperf "\processor(*)\% Processor Time" –s server1

TypePerf Figure2
Figure 2 TypePerf with a remote computer
 
This will create CSV ouput every second until you press Ctrl+C. This is very handy when you want to watch in real time. But if you only want to capture data for later analysis you most likely will run a command like this:

​C:\>typeperf "\processor(*)\% Processor Time" -s server1 -sc 60 -si 2 -o c:\work\procdata.csv

Now we’ll get a CSV file with 60 samples taken every 2 seconds. But more than likely you will want to capture several counters. This is where the text files we created earlier come in handy.

Copy and paste the counters you want to watch in a new text file. You can include counters from multiple remote computers. Make sure the computer name is part of the counter name. Once you have the list, run a command like this:

​C:\>typeperf -cf c:\work\mycounters.txt -o c:\work\moredata.csv -si 2 -sc 90
You might create pre-defined counter sets based on likely issues or some other business requirement.
Finally, you could further plan ahead and build a config file. This file is like an INI file where you set the parameter values. Here’s an example:
counterfile=c:\work\counters.txt
format=BIN
interval=5
samples=600
out=c:\work\perfdata.bin

To use this config file run a command like this:

​C:\> typeperf -config c:\work\config.tx

Conclusion

It really is that simple. Personally, I find I can run typed commands faster than I can navigate through a GUI and if this is something you find yourself needing on a regular basis, I think you’ll find this much easier, once you compete your initial setup.