VMware Cloud Community
MrTaylor2
Contributor
Contributor
Jump to solution

Powercli Script to Capture ESXi Cluster CPU & Memory Usage

Hello All,

I'm having the hardest time creating a script that will give me Cluster CPU and Memory Usage. I just need something simple if there is such a thing?

Example of what I'm looking for:

Cluster nameCPU GHz CapacityCPU GHz UsedCPU % Free

 

Cluster nameMemory CapacityMemory UsedMemory % Free

I need to present these in graphical format but I could look to do something with a pivot table afterwards.

Any help would be greatly appreciated.


Thanks

32 Replies
MrTaylor2
Contributor
Contributor
Jump to solution

Something has gone a bit wrong. When running the original script I get

  

01/07/2016 01:0086415257641228
02/07/2016 01:0086336257641628
03/07/2016 01:0086326357641628
04/07/2016 01:008699057612379
05/07/2016 01:0086336257636337
06/07/2016 01:0086316457637235
07/07/2016 01:0086316457637435
08/07/2016 01:0086306557637934
09/07/2016 01:0086316457638334
10/07/2016 01:0086326357638433
11/07/2016 01:0086296657638533
12/07/2016 01:0086296657638633
13/07/2016 01:0086316457638433
14/07/2016 01:0086296657638533
15/07/2016 01:0086316457638633
16/07/2016 01:0086326357638733
17/07/2016 01:0086316457638932
18/07/2016 01:0086306557639032
21/06/2016 01:0086326357641428
22/06/2016 01:0086316457641528
23/06/2016 01:0086296657641528
24/06/2016 01:0086296657641528
25/06/2016 01:0086306557641628
26/06/2016 01:0086346057641628
27/06/2016 01:0086336257641628
28/06/2016 01:0086316457641628
29/06/2016 01:0086326357641628
30/06/2016 01:00863263576416

28

With the new script it returns

     

01/07/2016 01:0086010057613177
02/07/2016 01:0086010057613177
03/07/2016 01:0086010057613177
04/07/2016 01:0086010057613177
05/07/2016 01:0086010057613177
06/07/2016 01:0086010057613177
07/07/2016 01:0086010057613177
08/07/2016 01:0086010057613177
09/07/2016 01:0086010057613177
10/07/2016 01:0086010057613177
11/07/2016 01:0086010057613177
12/07/2016 01:0086010057613177
13/07/2016 01:0086010057613177
14/07/2016 01:0086010057613177
15/07/2016 01:0086010057613177
16/07/2016 01:0086010057613177
17/07/2016 01:0086010057613177
18/07/2016 01:0086010057613177
19/07/2016 01:0086010057613177
22/06/2016 01:0086010057612578
23/06/2016 01:0086010057612578
24/06/2016 01:0086010057612578
25/06/2016 01:0086010057612578
26/06/2016 01:0086010057612578
27/06/2016 01:0086010057612578
28/06/2016 01:0086010057612578
29/06/2016 01:0086010057612578
30/06/2016 01:0086010057612578
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Seems I forgot to replace some $entity by $cluster.

I updated the script above


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

0 Kudos
MrTaylor2
Contributor
Contributor
Jump to solution

Brilliant.

Thanks a lot for your help

0 Kudos
panhvr
Contributor
Contributor
Jump to solution

Hello Luc,

I do see performance chart in webclient but no results when I run below coomand

Webclient > clutserts > select cluster name > performance > advanced > CPU I do see values available from Feb

PowerCLI C:\> Get-Cluster -Name Clustername | Get-Stat -start (get-date).AddDays(-40) -Finish (Get-Date).AddDays(-10) -MaxSamples 10000 -stat cpu.usage.average | Measure-Object -Property value -Average -Maximum -Minimum | select Average

PowerCLI C:\>

0 Kudos
panhvr
Contributor
Contributor
Jump to solution

Hello LucD

I opened a support case with VMware on this . They pointing the problem with latest version of PCLI interacion with vSpehre6.

The same set of command works fine when I run against my other VC which is VCSA.

0 Kudos
ehsanijavad
Enthusiast
Enthusiast
Jump to solution

Hi, Thank you for your script. But I do not know why in last 30 Min result is wrong.

When I used -Realtime and -MaxSamples.

Time               CPU GHz Capacity CPU GHz Used CPU % Free Mem Capacity GB Mem Used GB Mem % Free

----                ---------------- ------------ ---------- --------------- ----------- ----------

14/02/2020 10:10:00              441          211         52            5342        4038         24

14/02/2020 10:15:00              441          216         51            5342        4037         24

14/02/2020 10:20:00              441          218         51            5342        4037         24

14/02/2020 10:25:00              441          209         53            5342        4037         24

14/02/2020 10:30:00              441          208         53            5342        4037         24

14/02/2020 10:35:00              441          213         52            5342        4037         24

14/02/2020 10:40:00              441          206         53            5342        4037         24

14/02/2020 10:45:00              441          197         55            5342        4037         24

14/02/2020 10:50:00              441          210         52            5342        4037         24

14/02/2020 10:55:00              441          203         54            5342        4037         24

14/02/2020 11:00:00              441          210         52            5342        4037         24

14/02/2020 11:05:00              441          240         46            5342        4037         24

14/02/2020 11:10:00              441          226         49            5342        4037         24

14/02/2020 11:15:00              441          222         50            5342        4037         24

14/02/2020 11:20:00              441          238         46            5342        4037         24

14/02/2020 11:25:00              441            0        100            5342        3575         33

14/02/2020 11:30:00              441            0        100            5342        2881         46

14/02/2020 11:35:00              441            0        100            5342        2881         46

14/02/2020 11:40:00              441            0        100            5342        2297         57

14/02/2020 11:45:00              441            0        100            5342        1283         76

Thank you  for your answer.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Cluster performance data is created by one of the rollup processes running on the vCenter.

This rollup job runs every 30 minutes.

So for cluster data, the Realtime data is not really 'realtime', and you should not take the last 30 minutes into account.


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

ehsanijavad
Enthusiast
Enthusiast
Jump to solution

Thank you so much for your answer.

0 Kudos
ehsanijavad
Enthusiast
Enthusiast
Jump to solution

This script works for some Cluster, but it does not work for some Cluster (in same datacenter).

Get-Stat : 18/02/2020 08:32:02 Get-Stat This operation is restricted by the administrator - 'vpxd.stats.maxQueryMetrics'. Contact your

system administrator.

At line:7 char:16

+ $clusterName | Get-Stat -Stat $stat -MaxSamples 20  |

+                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Get-Stat], RestrictedByAdministrator

    + FullyQualifiedErrorId : Client20_RuntimeDataServiceImpl_GetStats_ErrorRetreivingPerfMetrics,VMware.VimAutomation.ViCore.Cmdlets.Com

   mands.GetViStats

Thank you for your answer.

0 Kudos
ehsanijavad
Enthusiast
Enthusiast
Jump to solution

Thank you so much for your answer.

0 Kudos
Juliancre
Contributor
Contributor
Jump to solution

How to change the date:

$start = (Get-Date).AddDays(-30)

By interval Date example:

$start = 2022-09-01

$finish= 2022-09-30

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can't with the Get-Stat cmdlet.
You will have to use a Where-clause after the Get-Stat, like I showed in PowerCLI & vSphere statistics – Part 2 – Come together


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