VMware Cloud Community
varonis
Enthusiast
Enthusiast
Jump to solution

how to export the top 10 VMs with issues?

hi all,

i am looking for a way to script and export the TOP 10 vms that had issues (cpu/memory/disks)

and if there is a way to export each issue to a diffrent sheet or a diffrent row.

Thanks in advance!!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Slightly different approach, we use the Group-Object to create an object for each VM with the highest CPU usage.

From those we then take the 10 with the highest value.

$cpuWatermak = 90 
$vms = Get-VM
$metric = "cpu.usage.average"
$start = (Get-Date).AddDays(-7) $stats = Get-Stat -Entity $vms -Stat $metric -Start $start -ErrorAction SilentlyContinue
$stats
| where {$_.Instance -eq "" -and $_.Value -ge $cpuWatermark} |
Select
@{N="VM";E={$_.Entity.Name}},Timestamp,Value |
Group-Object
VM | %{   $_.Group | Sort-Object -Property Value -Descending | Select -First 1
} | Sort-Object -Property Value -Descending |
Select
-First 10

Note that we only use the records where the Instance is blank, these are the aggregated averages over all cores.


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

View solution in original post

0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

Which issues exactly would you like to see ?

Do you have rules, something like CPU avg usage above 50% for example ?

Note that a lot of these issues are reported upon by ALan's vCheck v6.

Did you already check that out ?


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

0 Kudos
varonis
Enthusiast
Enthusiast
Jump to solution

I would like to repot all VMs that :

-Cpu usage is higher than 90%

-Memory usage is higher than 90%

and total disk latency is the higher.

yes i have those relues and i get the emails ,

-And yes i have checked the vcheck script is amazing but contains too much information to my bosses.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try something like this

$cpuWatermak = 90
$vms = Get-VM 
$metric = "cpu.usage.average"
$start = (Get-Date).AddDays(-1) $stats = Get-Stat -Entity $vms -Stat $metric -Start $start -ErrorAction SilentlyContinue
$stats | where {$_.Value -ge $cpuWatermark} |
Select @{N="VM";E={$_.Entity.Name}},Timestamp,Value |
Sort
-Descending -Property Value |
Select
-First 10

The sample looks at the average CPU usage of each VM for the last day.

It filters out the entries that are above the 90% watermark and then picks the 10 highest ones.

For the other metrics the principle is the same.

With vCheck 6 you can define yourself which plugins need to be used.

So you can make the resulting report as elaborate as you want.

And in fact you can write your own plugin and produce exactly what you're after.


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

0 Kudos
varonis
Enthusiast
Enthusiast
Jump to solution

I am getting the same machine 10 times :-[

what do i need to change there?

thanks.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

With the same timestamp ?


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

0 Kudos
varonis
Enthusiast
Enthusiast
Jump to solution

no, the top 10 error within a week or a month.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Slightly different approach, we use the Group-Object to create an object for each VM with the highest CPU usage.

From those we then take the 10 with the highest value.

$cpuWatermak = 90 
$vms = Get-VM
$metric = "cpu.usage.average"
$start = (Get-Date).AddDays(-7) $stats = Get-Stat -Entity $vms -Stat $metric -Start $start -ErrorAction SilentlyContinue
$stats
| where {$_.Instance -eq "" -and $_.Value -ge $cpuWatermark} |
Select
@{N="VM";E={$_.Entity.Name}},Timestamp,Value |
Group-Object
VM | %{   $_.Group | Sort-Object -Property Value -Descending | Select -First 1
} | Sort-Object -Property Value -Descending |
Select
-First 10

Note that we only use the records where the Instance is blank, these are the aggregated averages over all cores.


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

0 Kudos
varonis
Enthusiast
Enthusiast
Jump to solution

thanks a lot!!!

0 Kudos
varonis
Enthusiast
Enthusiast
Jump to solution

thanks,

is there a way to export all the data to a nice excel like you did in your blog:

$data = Get-VM | Sort-Object -Property WorkingSet -Descending | `
  Select-Object Name, @{N="WS";E={$_.WorkingSet/1MB}} -First 10
Export-Xls $data c:\amit.xls -AppendWorksheet:$false -WorksheetName "WS" -ChartType "xlColumnClustered"

??

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can use that $data array is input to the Export-Csv cmdlet.

$data | Export-Csv C:\report.csv -NoTypeInformation -UseCulture


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

0 Kudos