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 KBValue : 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.VMHostImplValue : 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.VMHostImplValue : 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.VMHostImplmem.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 KBGet-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.VMHostImplmem.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.VMHostImplAnd finally,
$stats = Get-Stat $esx -common -maxsamples 1 -realtime
$stats. GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.ArraySince 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: powershell, vmware, vmware powershell
Subscribe to Posts [Atom]