longp3
Contributor
Contributor

Can I get the memory usage of each process on ESX through powercli?

Hi,

Can I get the memory usage of process on ESX?

Like what "esxtop" command can do:

      ID      GID NAME                                MEMSZ   GRANT     CNSM    SZTGT     TCHD   TCHD_W %ACTV %ACTVS %ACTVF %ACTVN    SWCUR    SWTGT   SWR/s   SWW/s

6022074  6022074 CFT_DS_NFS_U64_  2048.00  1858.00  1858.00  2056.28  1658.88  1638.40    67     64     68     22     0.00     0.00    0.00    0.00

6025086  6025086 CFT_DS_NFS_U64_  2048.00  1866.00  1866.00  2060.53  1617.92  1617.92    78     70     74     47     0.00     0.00    0.00    0.00

    9793     9793 hostd.34366        72.07    48.12    48.12    52.93    19.33    19.33     0      0      0      0     0.00     0.00    0.00    0.00

4747375  4747375 sfcb-ProviderMa    28.48    18.68    18.68    20.55    11.20    11.20     0      0      0      0     0.00     0.00    0.00    0.00

4741823  4741823 vpxa.791587        27.03    17.82    17.82    19.60     5.80     5.80     0      0      0      0     0.00     0.00    0.00    0.00

Tags (1)
0 Kudos
4 Replies
LucD
Leadership
Leadership

You can use the Get-EsxTop cmdlet for that.

See some examples in my Hitchhiker’s Guide to Get-EsxTop – Part 1 post.

Let me know if it works for what you want to do.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
longp3
Contributor
Contributor

Hi LucD,

Thank you for your quick answer Smiley Happy

Your example is for cpu usage of each process right?

If I want to get the memory usage of process, should I use VMem counter?

But I see there are many fields of VMem, I am not sure which  field I should map to ID and MEMSZ.

Name                 Type

----                 ---

MemClientID          U32

IsValid              B

CurrentSwapInKB      U32

ToBeSwappedInKB      U32

SwapReadInKB         U32

SwapWriteInKB        U32

LlswapReadInKB       U32

LlswapWriteInKB      U32

ClientTouchedInKB    U32

ClientTouchedWrit... U32

ClientSizeInKB       U32

ClientTargetInKB     U32

MappedInKB           U32

SharedInKB           U32

ZeroInKB             U32

SavedBySharingInKB   U32

CurrentOverheadInKB  U32

MaxOverheadInKB      U32

MinCommitTargetInKB  U32

CommitTargetInKB     U32

CommitChargedInKB    U32

PagesPerShare        U64

EstimateActiveInPct  U32

EstimateSlowInPct    U32

EstimateFastInPct    U32

EstimateNextAvgInPct U32

CacheSizeInKB        U32

UsedCacheInKB        U32

CompressedInKB       U64

DecompressedInKB     U64

UWOverheadInKB       U32

IsBalloonActive      B

BalloonSizeInKB      U32

BalloonTargetInKB    U32

BalloonMaxInKB       U32

CheckpointReadInKB   U32

CheckpointTargetInKB U32

COWHintInKB          U32

0 Kudos
LucD
Leadership
Leadership

That is correct, you need to fetch the VMem counters.

The link between the columns in esxtop and the properties you get is documented (somewhat) in an un-official document.

See my Hitchhiker’s Guide to Get-EsxTop – Part 2 – The wrapper post.

There you will find that the esxtop column MEMSZ maps to the ClientSizeInKB property.

memsz.png

We also need the SchedGroup, that is where we can make the link to the GID and Name, via the MemClientID property.

Notice that I used a ' Sort-Object -Unique'  on the VMem counters, this to avoid duplicate identical entries.

Still trying to find out why they are there?!?

$esxName = 'MyESX'

$esxUser = 'root'

$esxPswd = 'password'

$esx = Connect-VIServer -Server $esxName -User $esxUser -Password $esxPswd

$gTab = @{}

(Get-EsxTop –TopologyInfo –Topology SchedGroup).Entries | where{$_.MemClientID} | %{

    if(!$gTab.ContainsKey([uint32]$_.MemClientID)){

        $gTab.Add([uint32]$_.MemClientID,$_)

    }

}

Get-EsxTop –CounterName VMem |

Sort-Object -Property {[int]$_.MemClientID} -Unique |

Select @{N='GID';E={$gTab[[uint32]$_.MemClientID].GroupID}},

    @{N='Name';E={$gTab[[uint32]$_.MemClientID].GroupName}},

    @{N='MEMSZ';E={[math]::Round($_.ClientSizeInKB/1KB,2)}} |

Sort-Object -Property {[int]$_.GID} | ft -AutoSize

Placing the output next to esxtop, shows we now can get the MEMSZ value

esxtop.png


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
longp3
Contributor
Contributor

Hi LucD,

Thank you very much, that is exactly what I want Smiley Happy

Pauline.

0 Kudos