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

Jump to navigation Jump to search
m
m (Added additional note to "Available Metrics")
Line 159: Line 159:


=== Available Metrics ===
=== Available Metrics ===
Metrics are available for each of the following types of object
Metrics are available for all objects you'd expect (and probably more), not limited to the following...
* Virtual Machines
* Virtual Machines
* Virtual machines Hosts (ESX's)
* Virtual machines Hosts (ESX's)
* Resource Pools
* Resource Pools
* Datastores
* Datastores
For a full list of what objects have what performance counters, and what those counters mean see http://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.PerformanceManager.html. 


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...
Line 172: Line 174:
mem.granted.average
mem.granted.average
mem.active.average
mem.active.average
mem.shared.average
...
mem.zero.average
mem.swapped.average
mem.swaptarget.average
mem.swapin.average
mem.swapout.average
mem.vmmemctl.average
mem.vmmemctltarget.average
mem.overhead.average
disk.usage.average
net.usage.average
sys.uptime.latest
sys.heartbeat.summation
mem.consumed.average


[vSphere PowerCLI] E:\> Get-VMHost "esx-server*" | Get-StatType
[vSphere PowerCLI] E:\> Get-VMHost "esx-server*" | Get-StatType
Line 196: Line 185:
mem.zero.average
mem.zero.average
mem.unreserved.average
mem.unreserved.average
mem.swapused.average
...</source>
mem.sharedcommon.average
mem.heap.average
mem.heapfree.average
mem.state.latest
mem.swapin.average
mem.swapout.average
mem.vmmemctl.average
mem.overhead.average
disk.usage.average
net.usage.average
sys.uptime.latest
clusterServices.cpufairness.latest
clusterServices.memfairness.latest
cpu.reservedCapacity.average
mem.reservedCapacity.average
mem.consumed.average
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...
'''In order to determine which sampling periods are available''', you need to use the '''<code> Get-StatInterval </code>''' command.  Remember that there is also the '''Realtime''' interval, at which all metrics are available.  The results depend on whether you're connected to a Virtual Centre (and how its configured) or an ESX (and whether that's being managed by a VC)...
<source lang="powershell">
<source lang="powershell">
[vSphere PowerCLI] E:\> Get-StatInterval
[vSphere PowerCLI] E:\> Get-StatInterval
Line 225: Line 197:
Past Month                                  7200                  2592000 VMware.VimAutomation....
Past Month                                  7200                  2592000 VMware.VimAutomation....
Past Year                                  86400                31536000 VMware.VimAutomation....
Past Year                                  86400                31536000 VMware.VimAutomation....
</source>


However, just because a metric is available, doesn't make it available in the interval you'd like.  '''In order to find out whether a statistic is available in the interval you'd like''', you need to use the '''<code> Get-StatType -Interval <secs/name> </code>'''...
<source lang="powershell">
[vSphere PowerCLI] E:\> Get-VMHost "esx-server*" | Get-Stat -MaxSamples 5 -IntervalSecs 300
[vSphere PowerCLI] E:\> Get-VMHost "esx-server*" | Get-Stat -MaxSamples 5 -IntervalSecs 300


Line 265: Line 241:
A couple of final points to note
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>
* 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
** All Realtime metrics are averages (as they're an average over the sampling period)
* 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).
* 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.
** 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.
* Be careful when retriving metrics that might have multiple instances (eg CPU), filter so as to see only the aggregate instance
* Be careful when retrieving metrics that might have multiple instances (eg CPU), this is relatively obvious in vSphere as it'll show an instance column, not so in VI3.  You can filter so as to see, for example, only the aggregate instance
** <source lang="powershell">get-vmhost "esx-server*" | get-stat -Stat cpu.usage.average -MaxSamples 1 -Realtime | Where{$_.Instance -eq ""}</source>
** <source lang="powershell">get-vmhost "esx-server*" | get-stat -Stat cpu.usage.average -MaxSamples 1 -Realtime | Where{$_.Instance -eq ""}</source>


Navigation menu