Home > Powershell, VMWare > Script of the Day – new(ish) Powercli cmdlets Get-ESXTop – part 1

Script of the Day – new(ish) Powercli cmdlets Get-ESXTop – part 1

Ignore this post – found it written up far better than I could ever manage:


When I have some time, I’ll write a wrapper for get-ESXTOP and get-esxcli to make these easier to use. In the mean time, head over to LucD.info for a decent guide!

Yes I know, some of you noticed these a while ago, but I have not been paying attention.

Back in December, the PowerCli guys released a new version of the Cli for us : http://communities.vmware.com/community/vmtn/vsphere/automationtools/powercli?view=overview Of course, I installed straight away, but did not go through the release notes.

Anyway, long story short, I noticed 2 particularly useful little cmdlets have appeared:

Get-Esxtop (no more SSH access required) – http://www.vmware.com/support/developer/PowerCLI/PowerCLI41U1/html/Get-EsxTop.html

and Get-ESXCli -http://www.vmware.com/support/developer/PowerCLI/PowerCLI41U1/html/Get-EsxCli.html

Of course, this is very exciting news. As a rule, I try user PowerCli as my first port of call for everything – SSH / Console access is a distant second as far as I am concerned (call me lazy)

Anyway, generally, when I need to view counters for a VM, I go to http://communities.vmware.com/docs/DOC-5240 and use those values as a guide as to what I should be tracking.

We run (we have to connect direct to an ESX host to use these tools – so connect using the normalsyntax first)

 connect-viserver <hostname>

Well first things first, using get-esxtop we may not know what exactly we’d like to query, so to return the set of cuonters available to us,

PS:6 >get-esxtop -Counter
Name                 Fields
----                 ------
Server               {MinFetchIntervalInUsec:U64, IsVMVisor:B, TimeStampInUsec:U64, Time:S64}
COS                  {UserTimeInUsec:U32, NiceTimeInUsec:U32, SysTimeInUsec:U32, IdleTimeInUsec:U3...
PCPU                 {NumOfLCPUs:U32, NumOfCores:U32, NumOfPackages:U32}
LCPU                 {LCPUID:U32, CPUHz:U64, UsedTimeInUsec:U64, HaltTimeInUsec:U64...}
PMem                 {PhysicalMemInKB:U32, COSMemInKB:U32, KernelManagedInKB:U32, NonkernelUsedInK...
NUMANode             {NodeID:U32, TotalInPages:U32, FreeInPages:U32}
Sched                {HostCPUInPct1Min:U32, HostCPUInPct5Min:U32, HostCPUInPct15Min:U32, NumOfSche...
SchedGroup           {GroupID:U32, GroupName:STR, IsValid:B, IsVM:B...}
CPUClient            {CPUClientID:U32, IsValid:B, NumOfVCPUs:U32}
HiddenWorld          {HiddenWorldID:U32, HiddenWorldName:STR}
VCPU                 {VCPUID:U32, WorldName:STR, IsValid:B, Affinity:U64...}
VMem                 {MemClientID:U32, IsValid:B, CurrentSwapInKB:U32, ToBeSwappedInKB:U32...}
VMNUMANodeMem        {NodeID:U32, IsValid:B, GuestMemInKB:U32, OverheadMemInKB:U32}
SCSI                 {NumOfReservations:U64, DurationInUsec:U64, NumOfConflicts:U64, ConfigNumOfOu...
Adapter              {AdapterName:STR, IsValid:B, QueueDepth:U32, NumOfChannels:U32}
Channel              {ChannelID:U32, IsValid:B, NumOfTargets:U32}
Target               {TargetID:U32, IsValid:B, NumOfLuns:U32}
Lun                  {LunID:U32, IsValid:B}
Path                 {PathName:STR, DeviceName:STR, IsValid:B, NumOfCommands:U64...}
WorldPerDev          {WorldID:U32, IsValid:B, NumOfActiveCmds:U32, NumOfQueuedCmds:U32...}
Partition            {PartitionID:U32, IsValid:B, NumOfCommands:U64, NumOfBlocksRead:U64...}
SCSIDevice           {DeviceName:STR, IsValid:B, QueueDepth:U32, BlockSizeInBytes:U32...}
Nfs                  {NumOfNfsClients:U32}
NfsClient            {MountName:STR, NumOfReads:U64, ReadByte:U64, ReadTimeInUsec:U64...}
Net                  {NumOfPortsets:U32, NumOfPNICs:U32}
NetPortset           {PortsetName:STR, IsValid:B, NumOfPorts:U32}
NetPort              {PortID:U32, IsValid:B, IsUplink:B, ClientName:STR...}
PNIC                 {PNICName:STR, UplinkPort:U32, IsValid:B, IsLinkUp:B...}
Interrupt            {NumOfInterruptVectors:U32}
InterruptVector      {VectorID:S64, Devices:STR, NumOfCPUs:U32}
InterruptPerCPU      {CPUID:U32, Count:U64, SysTimeInUsec:S64}
Power                {NumOfLCPUs:U32}
CStateInfo           {StateID:S32}
PStateInfo           {StateID:S32}
TStateInfo           {StateID:S32}
LCPUPower            {LCPUID:U32, NumOfCStates:U32, NumOfPStates:U32, NumOfTStates:U32}
CState               {StateID:S32, ResidentTimeInUsec:S64}
PState               {StateID:S32, ResidentTimeInUsec:S64}
TState               {StateID:S32, ResidentTimeInUsec:S64}

hmm, seems to provide a long list (more than 200 once you go into each of the branches) – but most importantly, they are nicely distributed by what they monitor.

to get a slightly easier to read output of this, we can run

$out = @()
foreach($counter in (Get-EsxTop -Counter)){
 foreach($field in $counter.Fields){
 $row = "" | Select Counter,Field,Type
 $row.Counter = $counter.Name
 $row.Field = $field.Name
 $row.Type = $field.Type
 $out += $row
$out | Export-Csv "C:\counters.csv" -NoTypeInformation -UseCulture

OK, so now we have a list of counters – and looking at ESXTOp these seem to align directly with the normal column headers. We know what we have, we have a list of counters in the doc above from VMware, to help us know what to view . . so how do we view these counters?

Well pretty simple really – let’s say we want to read all VCPU related counters, it is as simple as

Get-EsxTop -CounterName  VCPU | select * | ft -AutoSize

Right, this is about where I started scratching my head – no number of select statements or cleverness seems toreturn info for just the one VM, so what do we do?

well….with a little help from our other new cmdlet we’ll soon be churning out pretty live stats. …. Watch this space….I’ll post the rest of the solution early next week.

Categories: Powershell, VMWare Tags: ,
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.