VMware Cloud Community
pamiller21
Enthusiast
Enthusiast

% RAM Used Report

Hey everyone,
I am having issues with trying to figure out how to calculate and display the %%% RAM used on my vHosts in a cluster, this is what I have so far:

$reportRDCWH = Get-Cluster 'RDC-Production-Windows' | Get-VMHost | Select-Object @{e={$_.name};L="vHost"},

    @{e={$_.NumCpu};L="vCPU's"},
    @{e={$_.MemoryTotalGB};L="RAM(GB)"},
    @{e={$_.MemoryUsageGB};L="RAM(Used)"}

$reportRDCWH = $reportRDCWH | Sort-Object -Property vHost

$reportRDCWH += "" | Select @{L='vHost';E={'Total'}},
@{N="vCPU's";E={$reportRDCWH | Measure-Object -Property "vCPU's" -Sum | select -ExpandProperty Sum}},
@{N="RAM(GB)";E={$reportRDCWH | Measure-Object -Property "RAM(GB)" -Sum | select -ExpandProperty Sum}},
@{N="RAM(Used)";E={$reportRDCWH | Measure-Object -Property "RAM(Used)" -Sum | select -ExpandProperty Sum}}

Get-Stat -Entity $reportRDCWH -Stat 'RAM(Used)' -Realtime -MaxSamples 1 -Instance '' |
  ForEach-Object -Process {
  New-Object PSObject -Property @{
   PercentofTotalRAM = [math]::Round(($_.Value / 1MB) / $reportRDCWinVMs.MemoryGB * 100, 1)
  }
#} | Sort-Object -Property Datastore | Select Datastore, PercentofTotalSpaceGB
}

$reportRDCWH | ConvertTo-Html –title "Cloud Report" –body "<H1>RDC Windows vHosts</H1>" | Out-File $filelocation
0 Kudos
5 Replies
LucD
Leadership
Leadership

And what issues do you have?


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

Tags (1)
0 Kudos
pamiller21
Enthusiast
Enthusiast

I am trying to take the Total RAM and Total Used and find the %%% in another column. 

0 Kudos
LucD
Leadership
Leadership

And where is this $reportRDCWinVMs variable coming from?

I'm afraid I don't see the logic behind your code.


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

0 Kudos
pamiller21
Enthusiast
Enthusiast

Sorry that was a mistake in my variable, it should look like this:

$reportRDCWH = Get-Cluster 'RDC-Production-Windows' | Get-VMHost | Select-Object @{e={$_.name};L="vHost"},
    @{e={$_.NumCpu};L="vCPU's"},
    @{e={$_.MemoryTotalGB};L="RAM(GB)"},
    @{e={$_.MemoryUsageGB};L="RAM(Used)"}

$reportRDCWH = $reportRDCWH | Sort-Object -Property vHost

$reportRDCWH += "" | Select @{L='vHost';E={'Total'}},
@{N="vCPU's";E={$reportRDCWH | Measure-Object -Property "vCPU's" -Sum | select -ExpandProperty Sum}},
@{N="RAM(GB)";E={$reportRDCWH | Measure-Object -Property "RAM(GB)" -Sum | select -ExpandProperty Sum}},
@{N="RAM(Used)";E={$reportRDCWH | Measure-Object -Property "RAM(Used)" -Sum | select -ExpandProperty Sum}}

Get-Stat -Entity $reportRDCWH -Stat 'RAM(Used)' -Realtime -MaxSamples 1 -Instance '' |
  ForEach-Object -Process {
  New-Object PSObject -Property @{
   PercentofTotalRAM = [math]::Round(($_.Value / 1MB) / $reportRDCWH.MemoryGB * 100, 1)
  }
}
0 Kudos
LucD
Leadership
Leadership

I assume you want to do something like this.
But I'm not sure why you are calculating the percentage with Get-Stat, you can just derive it from the Total and Usage.
In any case I included both options, pick the one you want

$reportRDCWH = @()

$reportRDCWH += Get-Cluster 'RDC-Production-Windows' | Get-VMHost | Select-Object @{e = { $_.name }; L = "vHost" },
@{e = { $_.NumCpu }; L = "vCPU's" },
@{e = { [math]::Round($_.MemoryTotalGB,1) }; L = "RAM(GB)" },
@{e = { [math]::Round($_.MemoryUsageGB,1) }; L = "RAM(Used)" },
@{N = 'RAM_USed(%)'; E = {[math]::Round($_.MemoryUsageGB / $_.MemoryTotalGB * 100,1) }},
@{N = 'RAM_used_stat(%)'; E = {[math]::Round((Get-Stat -Entity $_ -Stat 'mem.usage.average' -Realtime -MaxSamples 1).Value,1) } } |
Sort-Object -Property vHost

$reportRDCWH += "" | Select-Object @{L = 'vHost'; E = { 'Total' } },
@{N = "vCPU's"; E = { $reportRDCWH | Measure-Object -Property "vCPU's" -Sum | Select-Object -ExpandProperty Sum } },
@{N = "RAM(GB)"; E = { $reportRDCWH | Measure-Object -Property "RAM(GB)" -Sum | Select-Object -ExpandProperty Sum } },
@{N = "RAM(Used)"; E = { $reportRDCWH | Measure-Object -Property "RAM(Used)" -Sum | Select-Object -ExpandProperty Sum } },
@{N = "RAM_USed(%)"; E = { $reportRDCWH | Measure-Object -Property "RAM_USed(%)" -Average | Select-Object -ExpandProperty Average } },
@{N = "RAM_used_stat(%)"; E = { $reportRDCWH | Measure-Object -Property "RAM_used_stat(%)" -Average | Select-Object -ExpandProperty Average } }


$reportRDCWH


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

0 Kudos