PowerCLI

 View Only
  • 1.  Network data transfer for a VM

    Posted Jul 20, 2017 10:11 AM

    Hi all, I need to establish some figures for a VM running under vCenter 5.5 in preparation for moving to AWS. I gather there is a tool called Stats Toolbox which I have downloaded. However I'm have a few problems getting it to work so I thought I'd better check that it will provide the information I need before spending any more time on it.

    Will Stats Toolbox give me a a figure for the amount of data transferred in or out of a VM over its network interface? A monthly or weekly figure would be perfect.

    Thanks



  • 2.  RE: Network data transfer for a VM

    Posted Jul 20, 2017 10:41 AM

    I'm assuming you are referring to my Stats Toolbox?

    If yes, that will only allow you to discover which metrics are available for which reporting period and for which entities.

    As you see, there quite a few network related metrics.

    What exactly do you want to get data about?

    Realtime data or historical data?



  • 3.  RE: Network data transfer for a VM

    Posted Jul 21, 2017 09:14 AM

    Hi, yes I was referring to your toolbox. I need to work out how much data has been written to and read from a VM via it's network interface. As Amazon will charge us for data in and out of a server instance, we need to estimate the running costs.

    Cheers



  • 4.  RE: Network data transfer for a VM

    Posted Jul 21, 2017 10:29 AM

    To calculate the amount of data transmitted and received over the last day for a specific VM, you could do

    $vmName = 'MyVM'

    $stat = 'net.bytesRX.average','net.bytesTx.average'

    $finish = Get-Date

    $start = $finish.AddDays(-1)

    $vm = Get-VM -Name $vmName

    Get-Stat -Instance '' -Entity $vm -Stat $stat -Start $start |

    Group-Object -Property MetricId | %{

        if($_.Name -match 'bytesrx'){

            $receivedKB = ($_.Group | Measure-Object -Property Value -Sum |

                select -ExpandProperty Sum) * $_.Group[0].IntervalSecs

        }

        if($_.Name -match 'bytestx'){

            $transmitKB = ($_.Group | Measure-Object -Property Value -Sum |

                select -ExpandProperty Sum) * $_.Group[0].IntervalSecs

        }

    }

    [ordered]@{

        VM = $vmName

        Start = $start

        Finish = $finish

        ReceivedKB = $receivedKB

        TransmitKB = $transmitKB

    }



  • 5.  RE: Network data transfer for a VM

    Posted Jul 21, 2017 11:32 AM

    Hi Luc, thank you very much for helping me with this. Please forgive my woeful ignorance here, as I have no experience of Powershell and little Windows knowledge being a Mac/Linux guy. Is that a Powershell script? Di I type it into a Powershell window?

    Thanks



  • 6.  RE: Network data transfer for a VM

    Posted Jul 21, 2017 01:37 PM

    Yes, that is a PowerShell script that uses PowerCLI cmdlets.

    In short:

    • save the script in a .ps1 file. For example netstat.ps1 in a folder C:\Temp
    • start the PowerShell (or the PowerShell ISE). You should get a prompt: PS C:\Users\YourUser>
    • load the PowerCLI modules (if you have installed PowerCLI 6.5.1, you can do 'Get-Module -Name VMware* -ListAvailable | Import-Module'
    • connect to your vCenter with Connect-VIserver -Server MyVC. Depending on the setup you might be prompted for a user/password
    • from the PowerShell prompt, run the .ps1 file you created earlier. Do that with C:/Temp/netstat.ps1
    • the result will of the script will be displayed on screen