VMware Cloud Community
system_noida
Enthusiast
Enthusiast

Need a script to collect the performance report of multiple VMs

Hi All,

 

Please could you help me with a request. I need to collect the performance report of CPU, memory, Disk and network for some multiple VMs like VM1, VM2, VM3........from a specific date and time to a specific date and time. I need to the report to be exported into CSV after collecting the report.

 

Please can some one help me with that.

0 Kudos
10 Replies
LucD
Leadership
Leadership

What do you already have?
Where do you get stuck?
Did you do a search in this community, there are many threads with similar questions in here?


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

0 Kudos
system_noida
Enthusiast
Enthusiast

Hi Lucd,

I am trying with the below scripts I found in this community. but its not giving the data as I need. I added the network and disk also in this code. I am trying to collect the logs for 24th Feb from 15:05 Hrs to 24th Feb 16:00 Hrs, but it is showing only single logs for each VM during this period of time. Also the date and time is not showing there in the export report csv file. I am attaching the screen shot of the export data for easy understand. 🙂

system_noida_0-1616567974598.png

 

 

Connect-VIServer my-vc

$vm = Get-VM VM1,VM2,VM3

Write-Output "VMs found $($vm.Count)"

$dayStart = Get-Date -Hour 15 -Minute 05 -Second 0 -Month 02 -Day 24 -Year 2021

$dayEnd = Get-Date -Hour 16 -Minute 0 -Second 0 -Month 02 -Day 24 -Year 2021

Write-Output "From $dayStart"

Write-Output "To $dayEnd"

$stat = 'cpu.usage.average','mem.usage.average','disk.usage.average','net.usage.average'

$stats = Get-Stat -Entity $vm -Stat $stat -Start $dayStart -Finish $dayEnd

Write-Output "Stats returned $($stats.Count)"

$report = $stats | Group-Object -Property {$_.Entity.Name} | %{

New-Object PSObject -Property @{

VM = $_.Name

CPUavg = $_.Group | Where {$_.MetricID -eq 'cpu.usage.average'} | Measure-Object -Property Value -Average | Select -ExpandProperty Average

Memavg = $_.Group | Where {$_.MetricID -eq 'mem.usage.average'} | Measure-Object -Property Value -Average | Select -ExpandProperty Average

Diskavg = $_.Group | Where {$_.MetricID -eq 'disk.usage.average'} | Measure-Object -Property Value -Average | Select -ExpandProperty Average

Networkavg= $_.Group | Where {$_.MetricID -eq 'net.usage.average'} | Measure-Object -Property Value -Average | Select -ExpandProperty Average


}

}

$report | Select VM,CPUavg,Memavg,Diskavg,Networkavg |

Export-Csv "F:\JK\Perf\report.csv" -NoTypeInformation -UseCulture

0 Kudos
LucD
Leadership
Leadership

WhHich is normal.
Due to aggregation, there is only one entry per day.

The date is missing in the CSV since you don't have that value on the Select.


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

0 Kudos
system_noida
Enthusiast
Enthusiast

Hi Lucd,

 

So would you be able to help me which code I need to put and where so that I can get the results with date and with more data instead of per day like as below.

system_noida_0-1616570377208.png

 

0 Kudos
LucD
Leadership
Leadership

I'm not sure what you are trying to do there.
You select a time range, then calculate the averages over the metrics from that time range.
So which date do you want in the report, the start or end of that time range?


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

0 Kudos
system_noida
Enthusiast
Enthusiast

My requirement is to just collect the performance logs of multiple VMs for a specific period of time like below I mentioned.

The Start date is 24th Feb 2021 15:00 Hrs to 25th Feb 2021 14:00 Hrs

Tags (1)
0 Kudos
LucD
Leadership
Leadership

That doesn't answer my question on which date you want in the output


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

0 Kudos
system_noida
Enthusiast
Enthusiast

I  want data from below dates:

24th Feb 2021 15:00 Hrs

25th Feb 2021 14:00 Hrs

0 Kudos
LucD
Leadership
Leadership

That is not what I asked.
I asked which date do you want in the CSV.
Since you are averaging over that period, there is 1 value.
Which date of that interval do you want in the output?


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

0 Kudos
system_noida
Enthusiast
Enthusiast

I am sorry for the huddle, I might be not understating your question properly. The requirement here is that there are some multiple VMs on which some issue has happened. Now the user is looking to get the logs from that period of time when the issue occur. The dates are 02/24/2021 from 15:00 Hrs to 02/25/2021 14:00 hrs.

So now I am looking to get the data like below timestamp for example.

system_noida_0-1616575415549.png

 

0 Kudos