Hi,
I'm triyng create a script which gives output as below :
Timestamp Total Usage
05/12/2016 09:00:00 1874756 49,67
05/12/2016 07:00:00 1874760 49,69
12/05/2016 13:00:00 1874760 50,06
05/12/2016 03:00:00 1874759 50,27
05/12/2016 01:00:00 1874759 50,32
total = memory available in GB for this cluster at this time
usage = memory in use in % at this time
Actually result is :
Name Group
05/12/2016 09:00:00 {1874756, 49,67}
05/12/2016 07:00:00 {1874760, 49,69}
05/12/2016 05:00:00 {1874760, 50,06}
05/12/2016 03:00:00 {1874759, 50,27}
05/12/2016 01:00:00 {1874759, 50,32}
I use following cmd :
Get-Stat -Entity (Get-Cluster Cluster_LINUX_G7) -Stat mem.usage.average,mem.totalmb.average -IntervalSecs 7200 | Group-object Timestamp | select Name, Group
I would like to get ouput in a a csv file (in order to create graph in excel after)
Can you have some ideas ?
Thanks in advance
Try something like this
$report = Get-Stat -Entity (Get-Cluster Cluster_LINUX_G7) -Stat mem.usage.average,mem.totalmb.average -IntervalSecs 7200 |
Group-object Timestamp | %{
New-Object PSObject -Property @{
Time = $_.Name
Total = $_.Group | where{$_.MetricId -eq 'mem.totalmb.average'} | Select -ExpandProperty Value
Used = $_.Group | where{$_.MetricId -eq 'mem.usage.average'} | Select -ExpandProperty Value
}
}
$report | Export-Csv report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this
$report = Get-Stat -Entity (Get-Cluster Cluster_LINUX_G7) -Stat mem.usage.average,mem.totalmb.average -IntervalSecs 7200 |
Group-object Timestamp | %{
New-Object PSObject -Property @{
Time = $_.Name
Total = $_.Group | where{$_.MetricId -eq 'mem.totalmb.average'} | Select -ExpandProperty Value
Used = $_.Group | where{$_.MetricId -eq 'mem.usage.average'} | Select -ExpandProperty Value
}
}
$report | Export-Csv report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
There is the proper way to do it (LucD answer), and the ugly:
I did this by oneliner, of which I'm not proud.
For some reasons I did not get return for mem.totalmb.average, hence the workaround by counting total memory of cluster.
get-stat -entity (get-cluster Cluster_LINUX_G7) -stat mem.usage.average -intervalsecs 7200 | select Timestamp, @{n="Total";e={[math]::round((((100-$_.Value)/100)*(((get-cluster gra-standalonehosts |get-vmhost).memorytotalgb | measure-object -sum).sum)),0)}}, @{n="Usage";e={($_.Value)}}
This would run way faster like this:
$clustertotalmemory = ((get-cluster Cluster_LINUX_G7 |get-vmhost).memorytotalgb | measure-object -sum).sum
get-stat -entity (get-cluster Cluster_LINUX_G7) -stat mem.usage.average -intervalsecs 7200 | select Timestamp, @{n="Total";e={[math]::round((((100-$_.Value)/100)*$clustertotalmemory),0)}}, @{n="Usage";e={($_.Value)}}