Average use of memory to Get Stat

I am running this report and you want to add average use of memory in GB.  I want to take into account all the memory that a VM has been demanding of ESXi, including overhead.

Get - vm | Select name, memoryGB

How can I add the average demand of memory to this report?

Thank you!

You can do

Get-StatType -Interval "Past Week" -Entity AnyVM | where {$_ -match "mem"}

Just replace AnyVM with the name of a virtual machine in your environment

Tags: VMware

Similar Questions

  • Average use of memory

    How can I get the use of the average memory of a group of virtual machines?  I have a current report that uses get - vm to create a group of objects of virtual machine.  I would like to integrate a custom property that goes and gets the average memory of this group of VMS usage and adds it as a custom property.  I would like to use Get-stat but I'm at the level of statistics 1 so I can only use what is available there.

    Get-vm-place somecluster1, anothercluster2 | Select name, memorygb, numcpu, aMillionOtherProperties,

    @{N = "AverageRAMUsage"; E = {ABrilliantget-statSnippet}}

    Ideas?

    Thank you!

    When you want to obtain this use?

    In all cases, you could do something like that, don't forget to adapt the content of the variable $start

    $clusterName = "mycluster.

    $start = (get-Date). AddHours(-1)

    $stat = "mem.usage.average".

    $vms = get-VM-location (Get-Cluster-name $clusterName)

    Get-Stat - $vms - Stat $stat entity - start $start - ErrorAction SilentlyContinue |

    Group-object - property {$_.} Enity.Name} |

    Select Name,

    @{N = "MemoryGB"; E={$_. Group [0]. Entity.MemoryGB}},

    @{N = "NumCpu"; E={$_. Group [0]. Entity.NumCpu}},

    @{N = "AverageRAMUsage"; E = {}

    [math]: Round (($_.)) Group [0] | Measure-object-property - average value. Select average - ExpandProperty), 2)

    }}

  • Average use of memory in MB? Not %

    I have the following code that uses get-stat to gather cluster statistics and exports the timestamp and the memory usage average percentage in the csv format:

    # In-memory cluster statistics

    foreach ($cluster in $xml. Settings.Setting.Clusters.Cluster)

    {

    $metrics = "mem.usage.average".

    $stats = get-stat-entity (get-cluster $cluster) - Stat $metrics - start $start - finishing $finish - interval 86400

    $groups = $stats | Group-object - property {$_.} TimeStamp, $_. @entity.name} $report = $groups | % {

    New-object PSObject-property @ {}

    'TimeStamp' = $_. Group [0]. TimeStamp

    '%' = $_. Group | where {$_.} MetricId - eq "mem.usage.average"} | Select value - ExpandProperty

    }

    }

    $csv_clustermem = ($ScriptPath + $cluster) + '_mem.csv '.

    $report | Select the TimeStamp, '% '. Export-Csv $csv_clustermem - NoTypeInformation

    Mem_Chart # launch Excel and generate the graph

    I do not know how to retrieve the memory in MB with her average? I tried to simply add Mo as an additional property to retrieve and then expand but I don't think that's true.

    Thanks in advance

    Try something like this

    $finish = Get-Date$start = ($finish).AddDays(-7)$metrics = "mem.usage.average"$cluster = Get-Cluster
    
    $stats = get-stat -Entity $cluster -Stat $metrics -Start $start -Finish $finish -Interval 86400$groups = $stats | Group-Object -Property {$_.TimeStamp, $_.Entity.Name} $report = $groups | % {  $totMem = $_.Group[0].Entity.ExtensionData.Summary.TotalMemory  $memAvgPerc = $_.Group | where {$_.MetricId -eq "mem.usage.average"} | Select -ExpandProperty Value  New-Object PSObject -Property @{    Cluster = $_.Group[0].Entity.Name    TimeStamp = $_.Group[0].TimeStamp    '%' = $memAvgPerc    'Avg MB' = [math]::Round(($totMem * $memAvgPerc / 1MB / 100),0)  }}$report
    
  • Generate the CSV file to the virtual machine by using get-stat statistics

    Hi all

    I put my VC for taking samples every 5 minutes for 3 days.

    I would create a PowerCLI script that I can then run on an ad hoc basis to connect to my VC and to get the details for ALL of the virtual machines that are managed by this CR and fill in a CSV (c:\foo.csv):

    • Name of the virtual machine

    • The ESX VM host is currently sitting

    • total number of virtual processors assigned to VM

    • total memory allocated to the VM

    • memory active average used by the virtual machine in the 3 days using samples of 5 minutes

    • average mhz CPU used by VM spent 3 days using samples of 5 minutes

    I have attached a sample file XLS of CSV output should look like.

    If anyone can give me a code to achieve or get on well on my way, I would appreciate it a lot.

    Kind regards

    Alex

    OK, so what you want is something like this then?

    Get-VM | Where {$_.PowerState -eq "PoweredOn"} |
     Select Name, Host, NumCpu, MemoryMB,
               @{N="Cpu.UsageMhz.Average";E={[Math]::Round((($_ | Get-Stat -Stat cpu.usagemhz.average -Start (Get-Date).AddHours(-72) -IntervalMins 5 -MaxSamples (12) | Measure-Object Value -Average).Average),2)}},
               @{N="Mem.Usage.Average";E={[Math]::Round((($_ | Get-Stat -Stat mem.usage.average -Start (Get-Date).AddHours(-72) -IntervalMins 5 -MaxSamples (12) | Measure-Object Value -Average).Average),2)}}
    

    I think that the issue that you have with the missing stat might be to do with your logging levels in VC, if these are not set correctly it will not save these stats for this period of time.

    What do you get if you do a simple:

    get-vm "SingleVM" | Get-Stat -Stat cpu.usagemhz.average
    

    If you found this information useful, please consider the allocation of points for correct or helpful.

    Alan Renouf

    http://Virtu-al.NET

  • Script Get-stat for VM Perfomance - Questions

    I am writing a script to get data on our virtual machine performance of the measures of depth for CPU and memory.  Its a great project task I have to do for our mgt and so I am writing a script extremely important and vital for our company.  I use the command get-stats and feedback from the messages I posted about get-stat in particular lucd and lebouf who have been very helpful.  But I have collected their answers and writes the script below.  Currently, it must be used with an argument, but I can change it later.  It also uses many counters of cpu and memory that is why it is a long script.  But I have a lot of questions on the script before I run it, I need to be clear with the data I receive in return.  The script is below:

    $vm = $args

    $vmguest = @{N = 'operating System'; {E = {.osfullname (get-vmguest - VM $_)}}

    Get - VM $args | where {$_.} PowerState - eq "Receptor"} | `

    Select name, NumCpu MemoryMB,

    @{N = "Mem.Usage.Average"; E = {(get-stat - entity $_ - Start ((Get-Date).))} AddDays(-7)) - finishing (Get-Date) - stat mem.usage.average | Measure-object-propriete value - average). Average}},

    @{N = "Percentage of use memory Maxiumn"; E = {(get-stat - entity $_ - Start ((Get-Date).))} AddDays(-7)) - finishing (Get-Date) - stat mem.usage.maximum | Measure-object-propriete value - average). Average}},

    @{N = "Memory use Ko"; E = {(get-stat - entity $_ - Start ((Get-Date).))} AddDays(-7)) - finishing (Get-Date) - stat mem.consumed.average | Measure-object-propriete value - average). Average}},

    @{N = "Memory status"; E = {(get-stat - entity $_ - Start ((Get-Date).))} AddDays(-7)) - finishing (Get-Date) - stat mem.state.latest | Measure-object-propriete value - average). Average}},

    @{N = "Memory Swapin average ko"; E = {(get-stat - entity $_ - Start ((Get-Date).))} AddDays(-7)) - finishing (Get-Date) - stat mem.swapin.average | Measure-object-propriete value - average). Average}},

    @{N = "Memory Swapout average ko"; E = {(get-stat - entity $_ - Start ((Get-Date).))} AddDays(-7)) - finishing (Get-Date) - stat mem.swapout.average | Measure-object-propriete value - average). Average}},

    @{N = 'Memory reserved MB capacity'; E = {(get-stat - entity $_ - Start ((Get-Date).))} AddDays(-7)) - finishing (Get-Date) - stat mem.reservedCapacity.average | Measure-object-propriete value - average). Average}},

    @{N = 'Average CPU usage percentage'; E = {(get-stat - entity $_ - Start ((Get-Date).))} AddDays(-7)) - finishing (Get-Date) - stat cpu.usage.average | Measure-object-propriete value - average). Average}},

    @{N = "CPU REady"; E = {(get-stat - entity $_ - Start ((Get-Date).))} AddDays(-7)) - finishing (Get-Date) - stat cpu.ready.summation | Measure-object-propriete value - average). Average}},

    @{N = "Maximum percentage of CPU usage"; E = {(get-stat - entity $_ - Start ((Get-Date).))} AddDays(-7)) - finishing (Get-Date) - stat cpu.usage.maximum | Measure-object-propriete value - average). Average}},

    @{N = "Use CPU MHZ on average"; E = {(get-stat - entity $_ - Start ((Get-Date).))} AddDays(-7)) - finishing (Get-Date) - stat cpu.usagemhz.average | Measure-object-propriete value - average). Average}},

    @{N = "Maximum MHZ CPU utilization"; E = {(get-stat - entity $_ - Start ((Get-Date).))} AddDays(-7)) - finishing (Get-Date) - stat cpu.usagemhz.maximum | Measure-object-propriete value - average). Average}},

    @{N = "MHZ CPU reserved"; E = {(get-stat - entity $_ - Start ((Get-Date).))} AddDays(-7)) - finishing (Get-Date) - stat cpu.reservedCapacity.average | Measure-object-propriete value - average). Average}} | `

    Export-Csv c:\stats5.csv

    The questions I have are:

    The first question is I want the stats to be based on the last 7 days, so I used the .adddays (-7).  It would give me the last 7 days stats?

    In my settings of virtual center statistics, I have all interval times checked.  So if I want last 7 days stats, I would use the samples for the interval of 30 minutes duration.  Also I have not used all interval parameter in the get-stat, so my samples will be based on the interval of 30 minutes.  Is this correct?

    Also, I have not used the maxsample interval, so by default I get to use all the values in the sample, and measures will give me the average of all samples (duration 30 min) values in the last 7 days.  Is that correct. ?

    Another key question is that is it possible to get readings of samples for only Monday to Friday, from 06:00-18:00, as this is when the virtual machine is used.  I don't know how this can be done and how it can be incorporated in the above script.  Is this possible to do?

    Also about the measure-object cmdlet, I used to all counters, as for the average values of use of cpu and memory.  I also use counters for cpu and memory max.  Would I need to use the average value of the object of measures to this end, as this counter will give me the max value for cpu/memory for all 7 days, which will be a single value, because I want to know the max value, it achieved, so I don't know if I have to use measure-object with these counters, do I need to use?

    About the ready CPU meter I use, also gives the value in millseconds.  Is it possible to get loan from cpu percentage value as we see in ESXTop because it is easier to understand for the cpuready.  I don't see any counter loan as a percentage of the CPU.  Is it possible to get a value for it.

    With the - equal Start parameter to specify that you want the values from 1 day back.

    This means that you will get the values historical interval 1 and the period interval 5 minutes ago.

    It is the HI1 interval in the scheme of part 1.

    When you specify not one - Start parameter and - finishing you will in effect of the values of historical interval 4, which has a period of 1-day interval.

    In a next blog post, I will talk about default values in the cmdlet Get-Stat.

  • (Mem.usage.Average & Mem.Active.Average meter with get-stats

    I try to put together a weekly statistics using get-Stats... his works all well but if I use Mem.usage.Average, I have the memory percentage. using mem.active.average would give me the use of memory in KB, I understand.

    However, I get an entry using mem.active.average null.

    On the study, I noticed through the chart options to real a meter (attached document) only the section of memory in time performance?

    The mem.active counter can be added to the other section? or y at - it a config I need to do?

    See you soon

    The metrics are collected for different intervals depend on what you are configuring in

    .

    In this form, you will see the 4 historical intervals and for each, there is a "level of statistics" (being the metric 4, 1 being the least metric).

    You can check what you have there?

    If the level is 1 for all the intervals that could be the reason why you can not get the mem.active meter.

    Note the data in real time, see you in the VI Client comes from the real time hard coded interval (20 seconds) which is collected on the ESX servers themselves and is kept only for a limited period of time.

  • Using the cmdlet Get-stats for the problems of performance of ESXi

    I need to detect the bottlenecks (if any) causing poor performance with a (free) 5.5 ESXi host.

    I see that if I use the cmdlet Get - stat PowerCLI I get dozens of meters, such as "mem.usage.average" or "'rescpu.maxlimited1.latest ', just to give two samples. "

    Can I identify a subset of the counters I should follow to identify possible bottlenecks in the fastest way possible?

    Concerning

    Marius

    Everything depends of course.

    There are several positions which list a number of key counters to watch.

    The Hosts of ESXi monitoring - a deeper on the what and the why look , you will find a good starting set.

  • Get-Stat for use of the power of the ESXi Server

    Hi all

    Need your help to get a script to capture power consumption/use of an esxi host. I checked the command get-stat, I don't see any special argument as energy consumption in check for the host entity. The time interval can be anything, I'd like to see the same values that manifest slot for power under the tables of performance of an esxi host.

    Any help would be appreciated.

    Thanks in advance

    Try like this

    10 P
    002
    003
    004
    005

    $entity = get-VMHost-name MyEsx
    $stat = "power.power.average".

    Get-stats - $entity - $stat - Realtime - MaxSamples 1 Stat entity

  • Average usage of the CPU with get-stat

    With get-stat, I can get average use of the processor in MHz using the metric usagemhz.

    However, by default the maximum and minimum values in MHz is not in data points from 2 months ago.  That's fine if I want to just average, but I also need average peak values.  The average maximum CPU usage is possible with powerCLI?

    The thing is that when you have found these averages and you do that a day or a week of a data value is not enough to really give you a true picture - you need 2 - 3 months.  Can Haw I achieve this with PowerCLI?

    1. you can easily adapt the cmdlet Get - VM to produce the result for 1 or a limited set of the virtual machine

    For example:

    Get-VM-name MyVM | Select...

    Returns the result for 1 computer virtual called MyVM

    If you do

    Get-VM-name my * | Select...

    It returns results for all virtual machines whose name begins with "My".

    2. that's because Select-Object generates a hash table, and by default PowerShell displays like that hash tables.

    To get only the value real exchange the last select like this

    ...

    } | Select AvgCPUMhz - ExpandProperty

    ...

  • Average use of CPU and memory of the ESX host

    Dear team

    script of powercli necessary to fetch the last 2 month avg cpu and memory utilzaition for all ESX hosts that are managed by vcenter server.

    concerning

    Mr. Vmware

    Try something like this

    $esx = Get-VMHost
    $start = (Get-Date).AddMonths(-2)
    $metric = "cpu.usage.average","mem.usage.average"
    Get-Stat -Entity $esx -Start $start -Stat $metric | Group-Object -Property {$_.Entity.Name} |
    Select @{N="VMHost";E={$_.Name}},  @{N="Avg CPU %";E={$_.Group | where {$_.MetricId -eq "cpu.usage.average"} |
        Measure-Object -Property Value -Average | Select -ExpandProperty Average}},  @{N="Avg Memory %";E={$_.Group | where {$_.MetricId -eq "mem.usage.average"} |
        Measure-Object -Property Value -Average | Select -ExpandProperty Average}}
    
  • Average read get-stat - virtualdisk.read.average stat?

    Hi all

    I want to use the metric virtualdisk.read.average to calculate the average read speeds per virtual disk to a virtual computer in the last 24 hours (using the 5 min interval)

    [1]

    I want to calculate the average in * every * instance and then add these individual averages until you get the desired amount.

    For example (using real-time output just for example only, I want 24 hours actually):

    MetricId unit Insta timestamp value
    NCE
    --------                ---------                          ----- ----     -----
    VirtualDisk.Read.Ave... 13/05/2011 19:39 6 Kbps scsi0:0
    VirtualDisk.Read.Ave... 13/05/2011 19:38:40 Kbps 11 scsi0:0
    VirtualDisk.Read.Ave... 13/05/2011 19:38:20 KBps 39 scsi0:0
    VirtualDisk.Read.Ave... 13/05/2011 19:38 431 Kbps scsi0:0
    VirtualDisk.Read.Ave... 13/05/2011 19:39 10 Kbps scsi0:1
    VirtualDisk.Read.Ave... 13/05/2011 19:38:40 Kbps 0 scsi0:1
    VirtualDisk.Read.Ave... 13/05/2011 19:38:20 5 kbps scsi0:1
    VirtualDisk.Read.Ave... 13/05/2011 19:38 0 Kbps scsi0:1

    Average (6 + 11 + 39 + 431) = 121.75

    average (10 + 0 + 5 + 0) = 3.75

    Total liked: 121.75 + 3.75 = 125,5

    What is the best way to achieve this? (Unfortunately there is no global instance as with the network and cpu.usagemhz parameters)

    [2]

    For the calculation of the IOPS / s, if you use the metric datastore.*, OR as the virtualdisk.*, is the following statement, 100% good:

    (a) virtualDisk.number [Read |] Write] Averaged.Average will calculate the OPS are / s generated by the virtual machine

    (b) disk.number [Read |] Write] .summation will calculate the OPS are / s that hit this particular data store (useful to see how busy is a data store - but will not provide any info on a single virtual machine (unless by chance, there is only a virtual computer on this data store special))

    [3]

    How to use virtualDisk.number [Read |] Write] calculate the IOPS / s for a given virtual machine?  Depending on the issue [1], to each VMDK, PAHO are / s on average individually and then add the averages for overall IOPS generated by this virtual machine in the last 24 hours?

    Concerning

    marc0

    Kind regards

    marc0

    [1] use the Group-Object and Measure-Object cmdlets for this.

    For example

    $vm = Get-VM MyVM $report = @()
    $stats = Get-Stat -Entity $vm -Stat virtualdisk.read.average -Start (Get-Date).AddHours(-12)
    $stats | Group-Object -Property Instance | %{
        $row = "" | Select Instance,Average
        $row.Instance = $_.Group[0].Instance
        $row.Average = ($stats | Measure-Object -Property Value -Average).Average
        $report += $row}
    $report $total = ($report | Measure-Object -Property Average -Sum).Sum
    Write-Host $vm.Name $total
    

    This will calculate the averages per virtual disk and add the averages together

    [2] see my post get PAHO are / s maximum .

    (a) Yes, provided that you add the OPS are / s for each virtual disk total

    (b) No, if you run the Get-Stat for an entity that is a virtual machine, you will get the statistics for this specific VM disk.

    The metric is available for HostSystem and VirtualMachine. See the column of the entity in the drive settings page.

    [3] Yes

  • Using variables in the command 'get-stat"powercli

    Hello

    I try to collect data via powershell and vsphere powercli I would like to pass several stat ID, both using variable that contains my ID stat list.

    (1) when I do this...

    Get-stat - entity (get-vmhost $host_id) - mem.active.average, sys.resourcecpuusage.average real-time stat - maxsamples 1

    ... It works very well

    (2) when I do this...

    $list = "mem.active.average".

    Get-stat - entity (get-vmhost $host_id) - stat $list - realtime - maxsamples 1

    ... It works fine, I can pass variables and so ID stat, one at a time.

    (3) when I do this...

    $list = 'mem.active.average, sys.resourcecpuusage.average '.

    Get-stat - entity (get-vmhost $host_id) - stat $list - realtime - maxsamples 1

    ... It does not work. PowerCLI returns... There is no entity the metric counter 'mem.active.average, sys.resourcecpuusage.average'...

    I do not understand where the problem is during the passage of variables, an idea?

    This should be

    $list = "mem.active.average","sys.resourcecpuusage.average"
    get-stat -entity(get-vmhost $host_id) -stat $list -realtime -maxsamples 1
    

    Must be an array of strings.

  • Get-Stat & weighted average

    When I run

    Get-ResourcePool -name "RSNAME" | Get-Stat -Stat mem.consumed.average
    

    Powercli is a weighted average (weighted average arithmetic - Wikipedia, the free encyclopedia)? Or I have to take into account that a VM can have data for each interval points, IE the VM did not exist at that time?

    It is a weighted average return.

  • The "cost" of get-stat

    A customer using a (free) ESXi host reports serious performance problems.

    My goal is to see if performance issues are due to memory, CPU, disk, or any other component.

    I've created a PowerCLI script to query the ESXi host to collect conters performance.

    Before starting can use, I assess whether the use of get-stat can aggravate the problerms with the performance of the ESXi host?

    My script should begin every 60 senconds, use the "connect-viserver" cmdlet and then cycle delivering approximately 20 times the cmdlet "get-stat' to get the values such as"cpu.usage.average","mem.usage.average"and so on.

    Can it worsen the performance of the target ESXi host issue?

    Should I before statring to use it?

    Will there be a better strategy to collect performance counters?

    Concerning

    Marius

    Performance in real time on an ESXi node are maintained during +/-1 hour, so I would not ask as often as every 60 seconds.

    The cmdlet Get-Stat imposes some overhead on the ESXi node, then Yes, that this can have an effect on the interpretation of the node ESXi.

    A few other tips to lower to load:

    • use only the counters that you absolutely
    • try to locate the source of the problem with a minimal set of counters, then go down by adding several counters
  • New-VIProperty and Get-Stat with Clusters

    I have a function that I used to collect the Min, Max, Avg for CPU and memory.  The service collects data from last month and returns a single value for each item.  After reading the New VIProperty, I thought I would try to adapt the function in the properties of the Cluster. I got the property works except that it returns an array of values instead of a single value.  I would like help to refine the 1st property and then I can create others.  I'll fix the work function and non-functional property.


    Work function


    Function Min_Max_Avg ($E, $C, $S) {
    Get-Stat -Entity $E -Stat $C -Start $S |
    Group-object -Property {$_. @entity.name} | %{
    $stats = $_. Group | Measure-object -property Value -way -up -Minimum
    }
    $Avg = [math]::round(($stats. (On average), 0)
    $Min = [math]::round(($stats. (Minimum), 0)
    $Max = [math]::round(($stats. (Maximum) 0)

    Return $Avg,$Min,$Max }





    Work not property


    # MemoryMinUsageMonth - MB
    New-VIProperty -Name MemoryMinUsageMonth -ObjectType Cluster - value}
    param ($cluster)
    $start = (Get-Date). AddMonths (-1)
    Get-Stat -Entity $cluster -Stat mem.usage.average -Start $start
    Group-object -Property {$cluster.} @entity.name} | %{
    $stats = $cluster. Group | Measure-object -property Value -Minimum
    }
    $Min = [math]::round(($stats. (Minimum), 0)
    $Min
    }



    As far as I know, the New VIProperty you set is called individually for each cluster.

    There is no need to use the group object.

    Can maybe try you it like that

    #MemoryMinUsageMonth - MB
    New-VIProperty-name MemoryMinUsageMonth - ObjectType Cluster - value {}
    Param ($cluster)
    Get-Stat - entity $cluster - Stat mem.usage.average - Start (Get-Date). AddMonths(-1) |
    Measure-object-property - Minimum value.

    Select - ExpandProperty Minimum
    }

Maybe you are looking for