PowerShell and Performance Counters

Sometimes we need monitor, CPU, Memory, Network utilization of a server or servers for a  certain period of time. Maybe you want to know what happens when users hit your servers at 9:00 am, 12:00 pm and 2:00 pm, then you want to correlate the impact on the servers based on the amount of users.

With PowerShell you can create counters and monitor what you need during that period and everything done though the command line. If you want to know what counter make the most sense to monitor you can check this article TechNet article.

You can also explore perfmon counter from the command line

Get-Counter -ListSet *

get-counter.jpg

As you can see you get a lot of counters that are difficult to read. To make it easier we can use out-gridview

Get-Counter -ListSet * | Out-GridView

get-counter2.jpg

Now you can search for a counter, look at the description and the path that  can  be used on the script to monitor performance data.

When creating daily counters we need to make sure to append the date and time to the .blg file.  The easiest way is to accomplish this is using get-date like such

$TimeStamp = get-date -Format MMddyy’T’HHmm

get-counter3

To start collecting some counters in a continuous  manner run this.get-counter6

If you run this,the PowerShell ISE window will be lock running that task, so we can run this script as a job using the following code

get-counter7

 

Now the job is running under the name counter with ID  number 5

get-counter8

To check if the job is running run Get-Job -State Running and you can also check the .blg file

get-counter9.jpg

get-counter10.jpg

When you are done collecting logs you can stop the job with stop-job and make sure to remove the job afterwards with remove-job

get-counter11.jpg

If you open the file, you will see all the performance metrics on it

get-counter12get-counter13

You can use invoke-command to run this across multiple servers or use a schedule task to call the script and run it as a background job. You can also specify a maximum number of samples instead of being continuous

 

 

 

 

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s