VMware Cloud Community
Sulrich
Contributor
Contributor

ESXi 7 server (no vCenter) usage reports

Community,

Currently I have an ESXi 7 Server with only a handful of VM's about to go to a system performance test over a period of 21 days.

I am trying to write a PS1 script to capture

TimeStamp
VmName,
vCPU_Count,
Vm_vCPU_%,
Vm_Alloc_RAM(MB),
Vm_RAM_Usage

at 30 second intervals in a CSV file. My boss wants a report at the end of the test that they can graph.

I found some examples on the googles, but all seem to perform an average with min and max... even the values returned don't seem correct.. since they are the same in multiple fields.
Also, the CPU values returned, are they Mhz, Ghz or %?

 

This is what I found online. I believe @LucD provided input to the original poster on this script

$report = @()
$metrics = "cpu.usage.average","mem.active.average"
$vms = Get-Vm | where {$_.PowerState -eq "PoweredOn"}
$start = (get-date).AddDays(-1)

Get-Stat -Entity ($vms) -start $start -stat $metrics | `
Group-Object -Property EntityId | %{
$row = ""| Select VmName, Timestamp, vCPU, MinCpu,AvgCpu,MaxCpu,MemAlloc,MinMem,AvgMem,MaxMem
$row.VmName = $_.Group[0].Entity.Name
$row.Timestamp = ($_.Group | Sort-Object -Property Timestamp)[0].Timestamp
$row.vCPU = $_.Group[0].Entity.NumCpu
$cpuStat = $_.Group | where {$_.MetricId -eq "cpu.usage.average"} | Measure-Object -Property Value -Minimum -Maximum -Average
$row.MinCpu = "{0:f2}" -f ($cpuStat.Minimum)
$row.AvgCpu = "{0:f2}" -f ($cpuStat.Average)
$row.MaxCpu = "{0:f2}" -f ($cpuStat.Maximum)
$row.MemAlloc = $_.Group[0].Entity.MemoryMB
$memStat = $_.Group | where {$_.MetricId -eq "mem.active.average"} | Measure-Object -Property Value -Minimum -Maximum -Average
$row.MinMem = "{0:f2}" -f ($memStat.Minimum)
$row.AvgMem = "{0:f2}" -f ($memStat.Average)
$row.MaxMem = "{0:f2}" -f ($memStat.Maximum)
$report += $row
}
$report | Export-Csv "/home/sulrich/Desktop/VM-statistics.csv" -NoTypeInformation -UseCulture

 

Output is:

VmNameTimestampvCPUMinCpuAvgCpuMaxCpuMemAllocMinMemAvgMemMaxMem
S2SFP_v44/3/2023 10:17:40 AM20.360.450.5516384167772167772167772
S2SFP_v54/3/2023 10:17:40 AM292.4593.5794.716384167772167772167772

 

Any input or advice is greatly appreciated,

 

Thanks,

Steve

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership

There are a couple of peculiarities you have to be aware of.

On an ESXi node the statistical data is kept for the better part of 1 hour.
Normally a vCenter picks up this data and stores it in its database.
You would need a script to retrieve the statistical data every hour.

Statistical data is collected by the PerformanceManager over a 20 second interval.
The data that you get is an average over that interval.

See my PowerCLI & vSphere statistics – Part 1 – The basics post for some details about performance data.

The Get-Stat cmdlet returns an object that also has a property named Unit, which tells you in what unit the Value is expressed.

When running Get-Stat against an ESXi node, you should use the Realtime switch.
Extracting the performance data directly from an ESXi node has the advantage the you have access to all performance metrics.
The Statistics Level only plays on the vCenter level.

To see which metrics are available use the Get-StatType cmdlet, use the VM for the Entity.



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

Reply
0 Kudos
Sulrich
Contributor
Contributor

If I had a vCenter server could I do what I'm looking to do?

 

thanks

steve

Reply
0 Kudos
LucD
Leadership
Leadership

Not really.

As I explained in that blog post the performance data on the vCenter is aggregated, meaning the data will be over longer intervals the further you go back in time.
Historical Interval I already aggregates the "Realtime" data from the ESXi nodes  to 5 minute intervals.
Only the "Realtime" data, with a 20 second interval, would allow you to get the data over a 30 seconds interval as you mentioned.

So you would still need to collect that Realtime data directly the ESXi nodes on an hourly basis, store it, and then after 21 days run the report against that stored data.
That is in fact what a commercial product (think Aria) is doing.

Also, on the vCenter the Statistics Levels come into play, meaning that not all metrics will be kept when the performance data is aggregated. Only with the Realtime data you will have access to all metrics, independent from the Statistics Level.



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

Reply
0 Kudos
Sulrich
Contributor
Contributor

@LucD @Thanks for all the insight. I will run my script against the ESXi server, not vCenter. I can set a task to run every hour and capture the output to a csv file. 
can it append I the csv file the next time it runs?

ultimately it would start at midnight, run every hour and append the the same csv for that day. I will place a date variable in the csv file name and then tomorrow it will generate a new csv file starting at midnight.

 

thoughts, insight and opinions are welcome

 

steve

Reply
0 Kudos
LucD
Leadership
Leadership

Yes, the Export-Csv cmdlet has an Append switch.

And yes, that is how I would do it.
You can schedule that script via a Windows Task Scheduler, just make sure that the station is powered on all the time.

To determine which metrics to collect have a look at the PerformanceManager, which lists all available metrics.

Don't forget the Realtime switch on the Get-Stat cmdlet.


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

Reply
0 Kudos