VMware Cloud Community
MrVmware9423
Expert
Expert

How to capture CPU Memory DISk and Network utilzation for Specific set of VMs

Dear Team,

I want PCLI script which will capture current CPU , Memory DISk and Network utilization for all Production VMs.

with the help of custom attributes(Annotations) I have defined different category such as production / staging / UAT / Exclude . PFA below snap

Annotations.JPG

my pruprose is I will run this script on daily basis to capture production VMs utilization.

need ur help to achieve this.

regards

Mr VMware

0 Kudos
9 Replies
LucD
Leadership
Leadership

The statistics report would in fact be the same as the one I gave in your other thread, but the selection of the VMs would be different.

Something like this

$vm = Get-VM  |

    where {(Get-Annotation -Entity $_ -Name Project | Select -ExpandProperty Value) -eq "Exclude"}


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

MrVmware9423
Expert
Expert

Thanks LUCD,

I have added the above line in existing script. PFA script and confirm will it work or not

and

I have also told in output it capture stats after every 20sec , I want to stats after every 3 hour

0 Kudos
LucD
Leadership
Leadership

I showed in Re: How to capture CPU, Mem , Disk , Network performance

how to group the results in 3 hour intervals.


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

0 Kudos
MrVmware9423
Expert
Expert

Dear LUCD.


I have ran the below script but it also capture other VMs details  as we want only EXCLUDE VMs details.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

$start = (Get-Date).AddDays(-1)

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

$vms = Get-VM
where {(Get-Annotation -Entity $_ -Name Project | Select -ExpandProperty Value) -eq "Exclude"}

&{Get-Stat -Entity $vms -Start $start -Stat $stat |

Group-Object -Property EntityId,{[math]::Floor($_.Timestamp.Hour/3)} | %{

    New-Object PSObject -Property @{

        Time = $_.Group[0].Timestamp

        VM = $_.Group[0].Entity.Name

        CPU = $_.Group | where {$_.MetricId -eq "cpu.usage.average" -and $_.Instance -eq ""} |

            Measure-Object -Property Value -Average | Select -ExpandProperty Average

        Mem = $_.Group | where {$_.MetricId -eq "mem.usage.average" -and $_.Instance -eq ""} |

            Measure-Object -Property Value -Average | Select -ExpandProperty Average

        Disk = $_.Group | where {$_.MetricId -eq "disk.usage.average" -and $_.Instance -eq ""} |

            Measure-Object -Property Value -Average | Select -ExpandProperty Average

        Net = $_.Group | where {$_.MetricId -eq "net.usage.average" -and $_.Instance -eq ""} |

            Measure-Object -Property Value -Average | Select -ExpandProperty Average

    }

}} | Select Time,VM,CPU,Mem,Disk,Net | Export-Csv vm-report.csv -NoTypeInformation -UseCulture

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

What wrong I m doing here ??? plz help

0 Kudos
LucD
Leadership
Leadership

You seem to have forgotten the pipe symbol (|) at the end of the 1st line

$vms = Get-VM |

where {(Get-Annotation -Entity $_ -Name Project | Select -ExpandProperty Value) -eq "Exclude"}


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

0 Kudos
MrVmware9423
Expert
Expert

after adding the pipe scripts works it throws below error.

annotation error.JPG

need ur assistance to resolve

0 Kudos
LucD
Leadership
Leadership

It looks as if the annotation "Project" is not available on all VMs.

Is that the case ?


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

0 Kudos
MrVmware9423
Expert
Expert

Project Annotation is visible on all VMs....

0 Kudos
LucD
Leadership
Leadership

Can you check with the following

foreach($vm in Get-VM){

    Try{

        Get-Annotation -Entity $vm -Name 'Project' -ErrorAction Stop

    }

    Catch{

        Write-Warning "No Project annotation on $($vm.Name)"

    }

}


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

0 Kudos