Quick and Dirty Scripting

A blog that focuses on automating system administration tasks for Linux, Windows, and VMware ESX

Monday, November 26, 2007

 

VMware's Very Cool Get-Stat Command

 

Today I want to briefly show  you the power of the VMware's Get-State command.  With it you can grab statistics on any VI entity - ESX Host, Virtual Machine, or Resource Pool.  To use it, all you need to do is supply the entity you want to monitor and which statistics do you want to grab (common, CPU, memory, disk, or network). So let's get some stats on an ESX host.

 $vc = Get-VIServer "vc1.example.com"

$esx = Get-VIHost "esx1.example.com"

Get-Stat $esx -Memory -maxsamples 3 -realtime

MetricId             Timestamp                                     Value Unit
---------            ----------                                    ----- ----
mem.vmmemctl.average 11/26/2007 1:52:2...                              0 KB
mem.vmmemctl.average 11/26/2007 1:52:0...                              0 KB
mem.vmmemctl.average 11/26/2007 1:51:4...                              0 KB

Value       : 21.49
Timestamp   : 11/26/2007 1:52:20 PM
MetricId    : mem.usage.average
Unit        : %
Description : Memory usage as percentage of total configured or available memory
Entity      : VMware.VimAutomation.Client20.VMHostImpl

Value       : 21.49
Timestamp   : 11/26/2007 1:52:00 PM
MetricId    : mem.usage.average
Unit        : %
Description : Memory usage as percentage of total configured or available memory
Entity      : VMware.VimAutomation.Client20.VMHostImpl

Value       : 21.49
Timestamp   : 11/26/2007 1:51:40 PM
MetricId    : mem.usage.average
Unit        : %
Description : Memory usage as percentage of total configured or available memory
Entity      : VMware.VimAutomation.Client20.VMHostImpl

mem.active.average   11/26/2007 1:52:2...                          78988 KB
mem.active.average   11/26/2007 1:52:0...                          78988 KB
mem.active.average   11/26/2007 1:51:4...                          78988 KB
mem.granted.average  11/26/2007 1:52:2...                        2097504 KB
mem.granted.average  11/26/2007 1:52:0...                        2097504 KB
mem.granted.average  11/26/2007 1:51:4...                        2097504 KB

Get-Stat $esx -common -maxsamples 1 -realtime

MetricId             Timestamp                                     Value Unit
---------            ----------                                    ----- ----
cpu.usage.average    11/26/2007 2:05:4...                           4.86 %

Value       : 297
Timestamp   : 11/26/2007 2:05:40 PM
MetricId    : cpu.usagemhz.average
Unit        : MHz
Description : CPU usage in MHz over the collected interval. For hosts this can be represented on a per Virtual Machine
              basis as a stacked graph
Entity      : VMware.VimAutomation.Client20.VMHostImpl

mem.usage.average    11/26/2007 2:05:4...                          21.48 %

Value       : 105
Timestamp   : 11/26/2007 2:05:40 PM
MetricId    : disk.usage.average
Unit        : KBps
Description : Aggregated storage performance statistics. For hosts this can be represented on a per Virtual Machine bas
              is as a stacked graph
Entity      : VMware.VimAutomation.Client20.VMHostImpl

And finally,

$stats = Get-Stat $esx -common -maxsamples 1 -realtime

$stats. GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Object[]                                 System.Array

Since the object returned to you is an array,this allows you to store and manipulate the return results - like

$stats[2]

MetricId             Timestamp                                     Value Unit
---------            ----------                                    ----- ----
mem.usage.average    11/26/2007 2:07:0...                          21.48 %

or $stats[2].Value

21.48

These values can then be piped into a table or graph to display the results.

Next week, I want to go back to something basic in Powershell - XML configuration. Powershell makes parsing XML documents very easy and I want to show how you can use this to create XML configuration files.

Labels: , ,


Comments:
Hi,

sorry, but how I may install this(and other VMware specific ) cmdlet to my machine with standard PowerShell installation?
 
You can get the VMware Powershell Snap-in by emailing VI_TK_4Win-Admin@vmware.com and requesting to be a part of their beta program. After you install their code, to add the Snapin to Powershell, just do:
ADD-PSSnapin VMware.VimAutomation.Core
 
Post a Comment





<< Home

Archives

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]