PowerCLI

 View Only
Expand all | Collapse all

How can we check ESX Host Resource utilization through PowerCLI ?

  • 1.  How can we check ESX Host Resource utilization through PowerCLI ?

    Posted Apr 23, 2014 01:24 PM

    Helo Team,

    How can we check ESX Host Resource utilization through PowerCLI ?

    Means CPU , Disk, Memory, Network utilization . So we able to monitor and make decision on right time.

    I have Two ESX server 5.

    I tried some command but not succeed need your help.

    Thanks and Regards,

    Ganesh Pal



  • 2.  RE: How can we check ESX Host Resource utilization through PowerCLI ?

    Posted Apr 23, 2014 01:46 PM

    here are two fab links from LucD

    PowerCLI & vSphere statistics - Part 1 - The basics - LucD notes

    PowerCLI & vSphere statistics – Part 2 – Come together - LucD notes

    I think this will help you a lot, (it did help me)

    this is for reference , just a pointer. may be he has better script now



  • 3.  RE: How can we check ESX Host Resource utilization through PowerCLI ?

    Posted Apr 25, 2014 05:48 AM

    Helo Team,

    I am getting below error.

    ==============================================================================================

    PowerCLI C:\> Get-Stat -Entity (Get-VMHost $esxName) -Stat cpu.usage.average -Ma

    xSamples 1 -IntervalMins 5

    Get-VMHost : Cannot validate argument on parameter 'Name'. The argument is null

    or empty. Supply an argument that is not null or empty and then try the comman

    d again.

    At line:1 char:29

    + Get-Stat -Entity (Get-VMHost <<<<  $esxName) -Stat cpu.usage.average -MaxSamp

    les 1 -IntervalMins 5

        + CategoryInfo          : InvalidData: (:smileyhappy: https://communities.vmware.com/Get-VMHost, ParameterBindingV

      alidationException

        + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom

      ation.ViCore.Cmdlets.Commands.GetVMHost

    PowerCLI C:\>

    Regards,

    Ganesh Pal 8451000743



  • 4.  RE: How can we check ESX Host Resource utilization through PowerCLI ?

    Posted Apr 25, 2014 05:52 AM

    What is in the variable $esxName, and how did you get the value in there ?

    Does

    Get-VMHost -Name $esxName

    return anything ?



  • 5.  RE: How can we check ESX Host Resource utilization through PowerCLI ?

    Posted Apr 25, 2014 07:02 AM

    Helo LucD,

    no its giving error.

    ===============================

    PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>
    PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-VMHo
    st -Name $esxName
    Get-VMHost : Cannot validate argument on parameter 'Name'. The argument is null
    or empty. Supply an argument that is not null or empty and then try the comman
    d again.
    At line:1 char:17
    + Get-VMHost -Name <<<<  $esxName
        + CategoryInfo          : InvalidData: (:) [Get-VMHost], ParameterBindingV
       alidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom
       ation.ViCore.Cmdlets.Commands.GetVMHost

    PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

    =========================================================================

    -------



  • 6.  RE: How can we check ESX Host Resource utilization through PowerCLI ?

    Posted Apr 25, 2014 07:04 AM

    There doesn't seem to be any value in the variable $esxName.

    Can you put the hostname of one of your ESXi servers in there ?



  • 7.  RE: How can we check ESX Host Resource utilization through PowerCLI ?

    Posted Apr 25, 2014 07:44 AM

    Dear LucD,

    Now its works, I don't Know how ?

    Please find output.

    ======================================

    PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-VMHo
    st -Name $esxName

    WARNING: 3 columns do not fit into the display and were removed.

    Name                 ConnectionState PowerState NumCpu CpuUsageMhz CpuTotalMhz
    ----                 --------------- ---------- ------ ----------- -----------
    10.7.1.232           Connected       PoweredOn       8        7672       19200


    PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

    ============================================================================================

    Thanks,

    Ganesh Pal



  • 8.  RE: How can we check ESX Host Resource utilization through PowerCLI ?

    Posted Apr 25, 2014 06:57 AM

    Try below script.

    $vmhosts =  get-vmhost

    Foreach ($esxname in $vmhosts) {

        $CPUstat = Get-Stat -Entity $esxname -Stat cpu.usage.average -IntervalMins 5 | Measure-Object value -Average | select-object -ExpandProperty Average

        $memstat = Get-Stat -Entity $esxname -Stat mem.usage.average -IntervalMins 5 | Measure-Object value -Average | select-object -ExpandProperty Average

        $obj =  New-Object PSobject

        $obj | Add-Member -MemberType NoteProperty -Name EsxiName -Value $esxname.Name

        $obj | Add-Member -MemberType NoteProperty -Name cpuaverage -Value $([math]::round($CPUstat))

        $obj | Add-Member -MemberType NoteProperty -Name Memaverage -Value $([math]::round($memstat))

        $obj

    }



  • 9.  RE: How can we check ESX Host Resource utilization through PowerCLI ?

    Posted Apr 25, 2014 07:33 AM

    Helo Kunaludapi,

    Its works, but hoe can I export it in *.CSV format, ands also want to mail with thrash hold.

    ==============================================================

    PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> $vmhosts
    =  get-vmhost
    PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>
    PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Foreach
    ($esxname in $vmhosts) {
    >>
    >>     $CPUstat = Get-Stat -Entity $esxname -Stat cpu.usage.average -IntervalMin
    s 5 | Measure-Object value -Average | select-object -ExpandProperty Average
    >>
    >>     $memstat = Get-Stat -Entity $esxname -Stat mem.usage.average -IntervalMin
    s 5 | Measure-Object value -Average | select-object -ExpandProperty Average
    >>
    >>     $obj =  New-Object PSobject
    >>
    >>     $obj | Add-Member -MemberType NoteProperty -Name EsxiName -Value $esxname
    .Name
    >>
    >>     $obj | Add-Member -MemberType NoteProperty -Name cpuaverage -Value $([mat
    h]::round($CPUstat))
    >>
    >>     $obj | Add-Member -MemberType NoteProperty -Name Memaverage -Value $([mat
    h]::round($memstat))
    >>
    >>     $obj
    >>
    >> }
    >>

    EsxiName                                   cpuaverage                Memaverage
    --------                                   ----------                ----------
    10.7.1.232                                         26                        85


    PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

    =============================================================================

    Thanks,

    Ganesh Pal



  • 10.  RE: How can we check ESX Host Resource utilization through PowerCLI ?

    Posted Apr 25, 2014 08:25 AM

    $report = @()

    $vmhosts =  get-vmhost

    Foreach ($esxname in $vmhosts) {

        $CPUstat = Get-Stat -Entity $esxname -Stat cpu.usage.average -IntervalMins 5 | Measure-Object value -Average | select-object -ExpandProperty Average

        $memstat = Get-Stat -Entity $esxname -Stat mem.usage.average -IntervalMins 5 | Measure-Object value -Average | select-object -ExpandProperty Average

        $obj =  New-Object PSobject

        $obj | Add-Member -MemberType NoteProperty -Name EsxiName -Value $esxname.Name

        $obj | Add-Member -MemberType NoteProperty -Name cpuaverage -Value $([math]::round($CPUstat))

        $obj | Add-Member -MemberType NoteProperty -Name Memaverage -Value $([math]::round($memstat))

        $report += $obj

    }

    $report | export-csv -NoTypeInformation c:\statsreport.csv



  • 11.  RE: How can we check ESX Host Resource utilization through PowerCLI ?

    Posted Apr 25, 2014 08:54 AM

    After the same script include below script, and modify your exchange server address and emial ids, it will send email for treshold.

    $EmailBody = @()

    foreach ($stat in $report) {

        if ($stat.cpuaverage -gt 80 -or $stat.memaverage -gt 80) {

            $emailbody += $stat

        }

    }

    $emailbody | export-csv -NoTypeInformation c:\temp\Statswithalerts.csv

    Send-MailMessage -SmtpServer smtp.domain.com -From vCenteralerts-noreply@domain.com -To Youremail@domain.com -Subject "Attachement for vCenter threshold" -Attachments c:\temp\Statswithalerts.csv



  • 12.  RE: How can we check ESX Host Resource utilization through PowerCLI ?

    Posted Apr 25, 2014 12:05 PM

    Hi Kunaludapi,

    Thanks, its works fine now. I have some more query.

    1) Could I use this script run every 15 minutes, how can I do this ?

    2) In my Environment there is 5 Vsphere  server , I want to set if 1 server having CPU utilization above 80 % or Memory Utilization above 90%, then VM's should move from Overloaded to available Vsphere server which utilizing less resource on that time.

    3) Please help me where I get best documents to learn more this command or script its interesting . I can manage lots of thins with PowerCLI.

    Thanks a lot for guiding.




  • 13.  RE: How can we check ESX Host Resource utilization through PowerCLI ?

    Posted Apr 25, 2014 01:35 PM

    1) Could I use this script run every 15 minutes, how can I do this ?

    ---- use below link to schedule a task

    http://www.virtu-al.net/2009/07/10/running-a-powercli-scheduled-task/

    2) In my Environment there is 5 Vsphere  server , I want to set if 1 server having CPU utilization above 80 % or Memory Utilization above 90%, then VM's should move from Overloaded to available Vsphere server which utilizing less resource on that time.

    ---- Use vcenter DRS feature to auto load balance

    3) Please help me where I get best documents to learn more this command or script its interesting . I can manage lots of thins with PowerCLI.

    ---- To learn a powercli, I would suggest you to get little hands on and foundation on Microsoft Powershell, for Powershell good book and blogs are available on the the internet,

    Below are the some of the good books to learn powercli

         Learning Powercli - Pact Publishing -- by authers Robert van den Nieuwendijk

         VMware vSphere Powercli Reference: Automating vSphere Administration -- by 5 authors -- including LucD :smileyhappy:



  • 14.  RE: How can we check ESX Host Resource utilization through PowerCLI ?

    Posted Apr 27, 2014 12:02 PM

    2) In my Environment there is 5 Vsphere  server , I want to set if 1 server having CPU utilization above 80 % or Memory Utilization above 90%, then VM's should move from Overloaded to available Vsphere server which utilizing less resource on that time.

    ---- Use vcenter DRS feature to auto load balance

    Q:- is it possible through PowerCLI ?Myself looking to do vi power CLI script.



  • 15.  RE: How can we check ESX Host Resource utilization through PowerCLI ?

    Posted Apr 27, 2014 12:38 PM

    Check out below link may be helpful, DRS is always 100% best practice and best way.


    http://ryanmangansitblog.com/2013/03/08/vmware-host-cluster-vm-memory-balancing-script-implementation/



  • 16.  RE: How can we check ESX Host Resource utilization through PowerCLI ?

    Posted Apr 28, 2014 12:39 PM


    Dear Kunaludapi,

    Thanks for your support, myself convert in to the script and output is coming  but giving some problem.

    =====================error======================


    Name                           Port  User
    ----                           ----  ----
    vsa.ganesh.com                 443   root
    Property 'Count' cannot be found on this object. Make sure that it exists.
    At C:\Scheduled tasks\Vmware DRS Script.ps1:87 char:39
    +        $strDest = $objHosts[$objHosts. <<<< Count-1].Name;
        + CategoryInfo          : InvalidOperation: (.:OperatorToken) [], RuntimeE
       xception
        + FullyQualifiedErrorId : PropertyNotFoundStrict


    ==================================================================

    PFA:- both script and output.



  • 17.  RE: How can we check ESX Host Resource utilization through PowerCLI ?

    Posted Apr 30, 2014 09:24 AM

    Dear Kunaludapi and Team,

    I run the script on my production environment and its try to moving but facing some error regarding destination. We had not configured cluster.

    ==========================Error Output==========================

    Move-VM : Cannot convert 'System.Object[]' to the type 'VMware.VimAutomation.Vi
    Core.Types.V1.Inventory.VIContainer' required by parameter 'Destination'. Speci
    fied method is not supported.
    At C:\Scheduled tasks\Vmware DRS Script.ps1:103 char:53
    +                        $objVM | move-vm -destination <<<<  (get-vmhost $strDe
    st);
        + CategoryInfo          : InvalidArgument: (:) [Move-VM], ParameterBinding
       Exception
        + FullyQualifiedErrorId : CannotConvertArgument,VMware.VimAutomation.ViCor
       e.Cmdlets.Commands.MoveVM

    Move-VM : Cannot convert 'System.Object[]' to the type 'VMware.VimAutomation.Vi
    Core.Types.V1.Inventory.VIContainer' required by parameter 'Destination'. Speci
    fied method is not supported.
    At C:\Scheduled tasks\Vmware DRS Script.ps1:103 char:53
    +                        $objVM | move-vm -destination <<<<  (get-vmhost $strDe
    st);
        + CategoryInfo          : InvalidArgument: (:) [Move-VM], ParameterBinding
       Exception
        + FullyQualifiedErrorId : CannotConvertArgument,VMware.VimAutomation.ViCor
       e.Cmdlets.Commands.MoveVM

    Move-VM : Cannot convert 'System.Object[]' to the type 'VMware.VimAutomation.Vi
    Core.Types.V1.Inventory.VIContainer' required by parameter 'Destination'. Speci
    fied method is not supported.
    At C:\Scheduled tasks\Vmware DRS Script.ps1:103 char:53
    +                        $objVM | move-vm -destination <<<<  (get-vmhost $strDe
    st);
        + CategoryInfo          : InvalidArgument: (:) [Move-VM], ParameterBinding
       Exception
        + FullyQualifiedErrorId : CannotConvertArgument,VMware.VimAutomation.ViCor
       e.Cmdlets.Commands.MoveVM

    Move-VM : Cannot convert 'System.Object[]' to the type 'VMware.VimAutomation.Vi
    Core.Types.V1.Inventory.VIContainer' required by parameter 'Destination'. Speci
    fied method is not supported.
    At C:\Scheduled tasks\Vmware DRS Script.ps1:103 char:53
    +                        $objVM | move-vm -destination <<<<  (get-vmhost $strDe
    st);
        + CategoryInfo          : InvalidArgument: (:) [Move-VM], ParameterBinding
       Exception
        + FullyQualifiedErrorId : CannotConvertArgument,VMware.VimAutomation.ViCor
       e.Cmdlets.Commands.MoveVM

    ======================================================================



  • 18.  RE: How can we check ESX Host Resource utilization through PowerCLI ?

    Posted Apr 25, 2014 08:55 AM

    Hi Kunaldapi,

    Thanks its works, I have some query.

    1) is it output in percentage ?

    2) we can sent alert mail to System Admin ? Purpose of this, If HOST have Overload then System Admin can move its VMs to available Host.



  • 19.  RE: How can we check ESX Host Resource utilization through PowerCLI ?

    Posted Apr 25, 2014 09:16 AM

    1) Yes, Output is in %.

    2) Yes, You can send email to System admin, you will need to specify system admin email in the -to.