Automation

 View Only
  • 1.  how to export the top 10 VMs with issues?

    Posted Jun 22, 2012 09:04 AM

    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!!



  • 2.  RE: how to export the top 10 VMs with issues?

    Posted Jun 22, 2012 09:07 AM

    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 ?



  • 3.  RE: how to export the top 10 VMs with issues?

    Posted Jun 22, 2012 09:16 AM

    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.



  • 4.  RE: how to export the top 10 VMs with issues?

    Posted Jun 22, 2012 09:32 AM

    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.



  • 5.  RE: how to export the top 10 VMs with issues?

    Posted Jun 22, 2012 09:59 AM

    I am getting the same machine 10 times :-[

    what do i need to change there?

    thanks.



  • 6.  RE: how to export the top 10 VMs with issues?

    Posted Jun 22, 2012 10:38 AM

    With the same timestamp ?



  • 7.  RE: how to export the top 10 VMs with issues?

    Posted Jun 22, 2012 12:34 PM

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



  • 8.  RE: how to export the top 10 VMs with issues?
    Best Answer

    Posted Jun 22, 2012 02:12 PM

    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.



  • 9.  RE: how to export the top 10 VMs with issues?

    Posted Jun 22, 2012 03:13 PM

    thanks a lot!!!



  • 10.  RE: how to export the top 10 VMs with issues?

    Posted Jun 22, 2012 03:35 PM

    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"

    ??



  • 11.  RE: how to export the top 10 VMs with issues?

    Posted Jun 22, 2012 05:54 PM

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

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