Difference between revisions of "Script Extracts and Examples (PowerCLI)"

Jump to navigation Jump to search
m
m (→‎Getting Started: Minor correction)
Line 166: Line 166:


The easiest way to ascertain what metric is available for what object is to use Get-StatType...
The easiest way to ascertain what metric is available for what object is to use Get-StatType...
<source lang="powershell">[vSphere PowerCLI] E:\> Get-vm "winstg" | Get-StatType
<source lang="powershell">[vSphere PowerCLI] E:\> Get-VM "vm-server" | Get-StatType
cpu.usage.average
cpu.usage.average
cpu.usagemhz.average
cpu.usagemhz.average
Line 187: Line 187:
mem.consumed.average
mem.consumed.average


[vSphere PowerCLI] E:\> Get-vmHost "uklonesxt1*" | Get-StatType
[vSphere PowerCLI] E:\> Get-VMHost "esx-server*" | Get-StatType
cpu.usage.average
cpu.usage.average
cpu.usagemhz.average
cpu.usagemhz.average
Line 214: Line 214:
mem.consumed.average
mem.consumed.average
mem.sysUsage.average</source>
mem.sysUsage.average</source>
However, just because a metric is available, doesn't make it available in the interval you'd like.  I find the most informative method is to see what sampling intervals are available by using <code>Get-StatInterval</code>, and then query for 5 samples of each metric...
<source lang="powershell">
[vSphere PowerCLI] E:\> Get-StatInterval
Name                          SamplingPeriodSecs          StorageTimeSecs Client
----                          ------------------          --------------- ------
Past Day                                      300                    86400 VMware.VimAutomation....
Past Week                                    1800                  604800 VMware.VimAutomation....
Past Month                                  7200                  2592000 VMware.VimAutomation....
Past Year                                  86400                31536000 VMware.VimAutomation....
[vSphere PowerCLI] E:\> Get-VMHost "esx-server*" | Get-Stat -MaxSamples 5 -IntervalSecs 300
MetricId                  Timestamp                                Value Unit
---------                ----------                              ----- ----
cpu.usage.average        19/01/2010 09:15:00                      7.64 %
cpu.usage.average        19/01/2010 09:10:00                        6.5 %
cpu.usage.average        19/01/2010 09:05:00                      6.37 %
cpu.usage.average        19/01/2010 09:00:00                      6.39 %
cpu.usage.average        19/01/2010 08:55:00                      6.35 %
cpu.usagemhz.average      19/01/2010 09:15:00                        813 MHz
cpu.usagemhz.average      19/01/2010 09:10:00                        692 MHz
cpu.usagemhz.average      19/01/2010 09:05:00                        678 MHz
cpu.usagemhz.average      19/01/2010 09:00:00                        680 MHz
cpu.usagemhz.average      19/01/2010 08:55:00                        676 MHz
mem.usage.average        19/01/2010 09:15:00                      24.89 %
mem.usage.average        19/01/2010 09:10:00                      24.88 %
mem.usage.average        19/01/2010 09:05:00                      24.89 %
mem.usage.average        19/01/2010 09:00:00                      24.9 %
mem.usage.average        19/01/2010 08:55:00                      24.91 %
disk.usage.average        19/01/2010 09:15:00                        156 KBps
disk.usage.average        19/01/2010 09:10:00                        124 KBps
disk.usage.average        19/01/2010 09:05:00                        131 KBps
disk.usage.average        19/01/2010 09:00:00                        126 KBps
disk.usage.average        19/01/2010 08:55:00                        136 KBps
net.usage.average        19/01/2010 09:15:00                          7 KBps
net.usage.average        19/01/2010 09:10:00                          8 KBps
net.usage.average        19/01/2010 09:05:00                          7 KBps
net.usage.average        19/01/2010 09:00:00                          7 KBps
net.usage.average        19/01/2010 08:55:00                          7 KBps
sys.uptime.latest        19/01/2010 09:15:00                    5173577 second
sys.uptime.latest        19/01/2010 09:10:00                    5173277 second
sys.uptime.latest        19/01/2010 09:05:00                    5172977 second
sys.uptime.latest        19/01/2010 09:00:00                    5172677 second
sys.uptime.latest        19/01/2010 08:55:00                    5172376 second
</source>
A couple of final points to note
* To retrieve data for the Realtime interval, use the <code> -Realtime </code> option, not <code> -IntervalSecs 20 </code>
** All metrics at this interval are averages
* Virtual Centre generally drops metrics during roll-ups etc (subject to configuration), therefore for the fullest range of metrics, check with the ESX direct (though only 20sec and 300sec intervals are available).
** I'd suggest always trying to go via the Virtual Centre, but the data you're after isn't available, check with the ESX direct.


== Script Extracts ==
== Script Extracts ==

Navigation menu