VMware Cloud Community
deepeshsk14
Contributor
Contributor

Need script to get esxi Average Cpu Memory usage.

Need script to get esxi avg Cpu & Memory usage Average within a Vcenter.

columns must include below:

esxi name / cluster name/ esxi avg cpu usage / esxi avg mem usage / cluster avg cpu usage / Cluster avg Mem usage 

0 Kudos
10 Replies
LucD
Leadership
Leadership

Did you search in this community?
That kind of question has been answered many times.

Btw, are you ever going to reply or give feedback on your other threads?


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

0 Kudos
deepeshsk14
Contributor
Contributor

Hi Lucd,

Thank you...

I checked the community, but didn't get what i needed. Can please help me in getting relevant script as i requested?

 

sure think, i will give feedback on other threads.

0 Kudos
LucD
Leadership
Leadership

I find it hard to believe there is not a single thread in here that doesn't contain part of your requirements.
What do you already have?


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

0 Kudos
deepeshsk14
Contributor
Contributor

Hi Lucd, I have found one script as below, i just need the "Memory Usage Percentage" column of the cluster, can you please add in?

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

$cred = Get-Credential
$vCenters = "lab-vcenter01.lab.local", "lab-vcenter02.lab.local"
Connect-VIServer $vCenters -Credential $cred

foreach($cluster in Get-Cluster){
$esx = $cluster | Get-VMHost

$cluster | Select @{N="VCname";E={$cluster.Uid.Split(':@')[1]}},
@{N="Datacenter";E={(Get-Datacenter -Cluster $cluster).Name}},
@{N="Clustername";E={$cluster.Name}},

@{N="CMemoryTotalGB)";E={($esx | Measure-Object -Property MemoryTotalGB -Sum).Sum}},
@{N="CMemoryUsageGB";E={($esx | Measure-Object -Property MemoryUsageGB -Sum).Sum}},
@{N="CAvailableMemoryGB";E={($esx | Measure-Object -InputObject {$_.MemoryTotalGB - $_.MemoryUsageGB} -Sum).Sum}},

0 Kudos
LucD
Leadership
Leadership

Isn't that just Usage/Total*100?


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

0 Kudos
deepeshsk14
Contributor
Contributor

Hi LUCD, thanks,

however it will be helpful if you provide complete command..

as this calculation is already using sum of esxi resources..so im bit confused

0 Kudos
LucD
Leadership
Leadership

Try this

@{N="CMemoryUsePercentage)";E={($esx | Measure-Object -Property MemoryUsageGB -Sum).Sum/($esx | Measure-Object -Property MemoryTotalGB -Sum).Sum *100}}


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

0 Kudos
deepeshsk14
Contributor
Contributor

Hi LUCD, Thanks that works fine.

However, I have one more query, in below assumed case.

suppose we get 2 values as below using "@{n=v1, e={exp1}}, @{N=V2, e={exp2}}"

V1V2
xy

 

and we need to get Value3 by adding V1&V2 like "@{n=V3,e={V1+V2}}" instead of going with "@{n=V3,e={exp1+exp2}}

V3
V1+V2
0 Kudos
LucD
Leadership
Leadership

No, that doesn't work.
The expression for V3 has no knowledge of the values for V1 and V2


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

deepeshsk14
Contributor
Contributor

Thanks lucd!

0 Kudos