I am writing a script to get performance data on our VM's regarding in depth measures for CPU and Memory. Its a big project task I have to do for our mgt and so I am writing a hugely important and vital script for our company. I am using the get-stat command and from feedback from posts I posted regarding get-stat in particular from lucd and lebouf which have been mighty useful. But I have gathered their replies and written the script below. It currently has to be used with an argument but I can change that later. It also uses many counters for cpu and memory thats why it is a long script. But I have many questions regarding the script before I run it, as I need to be clear with the data I am getting back. The script is below:
$vm = $args
$vmguest = @{ N = "operating System" ; E = { ( get-vmguest -VM $_ ).osfullname}}
Get-VM $args | where {$_.PowerState -eq "PoweredOn"} | `
Select name,NumCpu, MemoryMB,
@{N="Mem.Usage.Average";E={(get-stat -entity $_ -Start ((Get-Date).AddDays(-7)) -Finish (Get-Date) -stat mem.usage.average | Measure-Object -Property Value -Average).Average}},
@{N="Maxiumn Memory Usage Percentage";E={(get-stat -entity $_ -Start ((Get-Date).AddDays(-7)) -Finish (Get-Date) -stat mem.usage.maximum | Measure-Object -Property Value -Average).Average}},
@{N="Memory Usage KBytes";E={(get-stat -entity $_ -Start ((Get-Date).AddDays(-7)) -Finish (Get-Date) -stat mem.consumed.average | Measure-Object -Property Value -Average).Average}},
@{N="Memory State";E={(get-stat -entity $_ -Start ((Get-Date).AddDays(-7)) -Finish (Get-Date) -stat mem.state.latest | Measure-Object -Property Value -Average).Average}},
@{N="Memory Swapin Average KBytes";E={(get-stat -entity $_ -Start ((Get-Date).AddDays(-7)) -Finish (Get-Date) -stat mem.swapin.average | Measure-Object -Property Value -Average).Average}},
@{N="Memory Swapout Average KBytes";E={(get-stat -entity $_ -Start ((Get-Date).AddDays(-7)) -Finish (Get-Date) -stat mem.swapout.average | Measure-Object -Property Value -Average).Average}},
@{N="Memory Reserved Capacity MBytes";E={(get-stat -entity $_ -Start ((Get-Date).AddDays(-7)) -Finish (Get-Date) -stat mem.reservedCapacity.average | Measure-Object -Property Value -Average).Average}},
@{N="Average CPU Usage Percentage";E={(get-stat -entity $_ -Start ((Get-Date).AddDays(-7)) -Finish (Get-Date) -stat cpu.usage.average | Measure-Object -Property Value -Average).Average}},
@{N="CPU REady";E={(get-stat -entity $_ -Start ((Get-Date).AddDays(-7)) -Finish (Get-Date) -stat cpu.ready.summation | Measure-Object -Property Value -Average).Average}},
@{N="Maximum CPU Usage Percentage";E={(get-stat -entity $_ -Start ((Get-Date).AddDays(-7)) -Finish (Get-Date) -stat cpu.usage.maximum | Measure-Object -Property Value -Average).Average}},
@{N="Average CPU Usage MHZ";E={(get-stat -entity $_ -Start ((Get-Date).AddDays(-7)) -Finish (Get-Date) -stat cpu.usagemhz.average | Measure-Object -Property Value -Average).Average}},
@{N="Maximum CPU Usage MHZ";E={(get-stat -entity $_ -Start ((Get-Date).AddDays(-7)) -Finish (Get-Date) -stat cpu.usagemhz.maximum| Measure-Object -Property Value -Average).Average}},
@{N="Reserved CPU MHZ";E={(get-stat -entity $_ -Start ((Get-Date).AddDays(-7)) -Finish (Get-Date) -stat cpu.reservedCapacity.average| Measure-Object -Property Value -Average).Average}},| `
Export-Csv c:\stats5.csv
The questions I have are:
The first question is that I want the stats to be based on the last 7 days, so I have used the .adddays (-7). Would this give me the last 7 day stats?
In my virtual centre statistics settings I have all the interval durations checked. So if I want the last 7 days stats, I would be using the samples for the interval duration 30 mins. Also I have not used any interval parameters in the get-stat, so my samples will bases on the 30 min interval. Is this correct ?
Also I have not used the maxsample interval, so by default I will be getting to use all the sample values, and the measure-object will give me the average of all the samples values (30 min duration) in the last 7 days. Is this correct.?
Another key question is that is it possible to get sample readings for only Mon- Fri, from 6am - 6pm, as thats when the VM's are used. I dont know how this can be done and how it can be incorporated in the script above. Is this possible to do ?
Also regarding the measure object cmdlet, I have used for all the counters, such as for the average cpu and memory usage values. I am also using counters for max cpu and memory usage. Would I need to use the measure-object average value for this, as this counter will give me the max value for the cpu/memory for all the 7 days, which will be only one value, as I want to find out the max value it reaches, so I dont know if I should use measure-object with these counters, do I need to use it ?
Also regarding the cpu ready counter I am using, gives the value in millseconds. Is it possible to get the cpu ready value in percentage like you see in ESXTop as this is a more easier to understand for cpuready. I cannot see any counter for cpu ready in percentages. Is there a way to get a value for this.