Hi,
I have a script found on ict-freak.
Connect-VIServer $args[0] | Out-Null
$myCol = @()
foreach($vm in (Get-View -ViewType VirtualMachine | Where-Object `
{$_.Summary.QuickStats.BalloonedMemory -ne "0" -or $_.Summary.QuickStats.SwappedMemory -ne "0"})){
$Details = "" | Select-Object VM, `
SwappedMemory ,BalloonedMemory
$Details.VM = $vm.Name
$Details.SwappedMemory = $vm.Summary.QuickStats.SwappedMemory
$Details.BalloonedMemory = $vm.Summary.QuickStats.BalloonedMemory
$myCol += $Details
}
$myCol
Is there a way to get the same info but not in real time and for the last 24 hours?
I would run it in scheduled tasks.
Thanks
You can get the data with the Get-Stat cmdlet.
Something like this
$vm = Get-VM MyVM
Get-Stat -Entity $vm -Stat mem.vmmemctl.average,mem.swapped.average -Start (Get-Date).AddDays(-1)
Let me know how you want to display the data returned ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
OK, it seems to get me the good data.
Is there a way to have it for all the vm in a vcenter in the same report?
if I do
foreach($vm in (get-vm *)){
Get-Stat -Entity $vm -Stat mem.vmmemctl.average,mem.swapped.average -Start (Get-Date).AddDays(-1)
I don't see the vmname in the report. Is there a Select Name?
To get the name of the virtual machine also you have to select the Entity property. You can do it like this:
$Yesterday = (Get-Date).AddDays(-1) Get-VM | Get-Stat -Stat mem.vmmemctl.average,mem.swapped.average -Start $Yesterday | ` Select-Object -Property Entity,MetricId,Timestamp,Value,Unit,Instance
This will return the output in a list view. If you want a table view you can do:
$Yesterday = (Get-Date).AddDays(-1) Get-VM | Get-Stat -Stat mem.vmmemctl.average,mem.swapped.average -Start $Yesterday | ` Select-Object -Property Entity,MetricId,Timestamp,Value,Unit,Instance | ` Format-Table
I moved the (Get-Date).AddDays(-1) to the first line of the script so it has to be calculated only once.
Regards, Robert
You can do something like this, one call to Get-Stat and then use the Group-Object to order the data per VM.
Get-Stat -Entity (Get-VM) -Stat mem.vmmemctl.average,mem.swapped.average -Start (Get-Date).AddDays(-1) | `
Group-Object -Property Entity | %{
$vmName = $_.Name
$_.Group | %{
$_ | Select @{N="VM";E={$_.Entity.Name}},Timestamp,MetricId,Value
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks,
I did the following and it works
Connect-VIServer $args[0] | Out-Null
$allvms = @()
$vms = Get-Vm
foreach($vm in $vms){
$vmstat = "" | Select VmName, SwpMax, SwpAvg, SwpMin, BalMax, BalAvg, BalMin
$vmstat.VmName = $vm.name
$statswp = Get-Stat -Entity ($vm)-start (get-date).AddDays(-1) -Finish (Get-Date) -stat mem.swapped.average
$statbal = Get-Stat -Entity ($vm)-start (get-date).AddDays(-1) -Finish (Get-Date) -stat mem.vmmemctl.average
$swp = $statswp | Measure-Object -Property value -Average -Maximum -Minimum
$bal = $statbal | Measure-Object -Property value -Average -Maximum -Minimum
#Get-Stat -Entity $vm -Stat mem.vmmemctl.average,mem.swapped.average -Start (Get-Date).AddDays(-1)
$vmstat.SwpMax = $swp.Maximum
$vmstat.SwpAvg = $swp.Average
$vmstat.SwpMin = $swp.Minimum
$vmstat.BalMax = $bal.Maximum
$vmstat.BalAvg = $bal.Average
$vmstat.BalMin = $bal.Minimum
$allvms += $vmstat
}
$allvms | Select VmName, SwpMax, SwpAvg, SwpMin, BalMax, BalAvg, BalMin | Export-Csv "Performance3.csv" -noTypeInformation
thanks to the two of you.