VMware Cloud Community
prashantpote
Contributor
Contributor

PowerCLI script to get Server utilization report in JPEG format from Webclient

PowerCLI script for fetching utilization report from wbclient JPEG format specific date to date.

CPU : Usage%

Disk: highest Latency

Memory : Active

Network: Data recieve rate  

Reply
0 Kudos
14 Replies
LucD
Leadership
Leadership

You seem to have deleted your original thread.

Is that for ESXi nodes or VMs?


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

Reply
0 Kudos
prashantpote
Contributor
Contributor

This is for VMs and ESXi both. Graphical JPEG format if possible or normal script
Reply
0 Kudos
LucD
Leadership
Leadership

Not sure what you mean by "Graphical JPEG format"?
You want to produce a graph?


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

Reply
0 Kudos
prashantpote
Contributor
Contributor

Yes, Webclient Graph as shown in attachment. or if that is not possible then normal script to pull utilization report from date to date custom report
Reply
0 Kudos
LucD
Leadership
Leadership

Have you looked at Re: Automate CSV output to performance chart view powercli ?


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

Reply
0 Kudos
prashantpote
Contributor
Contributor

Thanks, I checked that scripts. I have below questions  :

1) I am using vCenter 6.5 and getting only error for fetching data for 90 Days disk.usage.average

error : 

Get-Stat : 14-03-2019 16:35:18  Get-Stat                The metric counter "disk.usage.average" doesn't exist for entity "xxxxxxxxxxx".
At C:\Users\xxx\xxx\PS\VM_Utilization_Report.ps1:19 char:23
+ ... sageaverage=Get-Stat -entity $vm -MaxSamples 168 -Start (Get-Date).Ad ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (disk.usage.average:String) [Get-Stat], VimException
    + FullyQualifiedErrorId : Client20_RuntimeDataServiceImpl_CheckUserMetrics_MetricDoesntExist,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetViStats

 

2)How to add multiple server in input file C:\Temp\ESB\servers.txt in below script(using which saperator)

$servers=Get-Content C:\Temp\ESB\servers.txt

foreach ($server in $servers)

{

    $vm=Get-VM $server

    if($? -eq $false)

    {

        continue

    }

    $fileName="C:\Temp\ESB\$server.csv"

    $diskusageaverage=Get-Stat -entity $vm -MaxSamples 168 -Start (Get-Date).AddDays(-7) -IntervalMins 120 -stat ‘disk.usage.average’ | ? { $_.instance -eq "" } | select Entity,Timestamp,Value |Sort-Object Timestamp

    $memusageaverage=Get-Stat -entity $vm -MaxSamples 168 -Start (Get-Date).AddDays(-7) -IntervalMins 120 -stat ‘mem.usage.average’ | ? { $_.instance -eq "" } | select Entity,Timestamp,Value |Sort-Object Timestamp

    $cpuusageaverage=Get-Stat -entity $vm -MaxSamples 168 -Start (Get-Date).AddDays(-7) -IntervalMins 120 -stat ‘cpu.usage.average’ | ? { $_.instance -eq "" } | select Entity,Timestamp,Value |Sort-Object Timestamp

    $netusageaverage=Get-Stat -entity $vm -MaxSamples 168 -Start (Get-Date).AddDays(-7) -IntervalMins 120 -stat ‘net.usage.average’ | ? { $_.instance -eq "" } | select Entity,Timestamp,Value |Sort-Object Timestamp

    Set-Content -Value "ServerName,AVG_CPU_Time,AVG_CPU,AVG_MEM,AVG_disk,AVG_Net" -Path $fileName

    $diskus=0

    for ($i=0;$i -lt $cpuusageaverage.Count ; $i++)

    {

        if (($diskus -lt $diskusageaverage.count) -and ($cpuusageaverage[$i].Timestamp -eq $diskusageaverage[$diskus].Timestamp))

        {

            Add-Content -Value "$($cpuusageaverage[$i].Entity.Name),$($cpuusageaverage[$i].Timestamp),$($cpuusageaverage[$i].Value),$($memusageaverage[$i].Value),$($diskusageaverage[$diskus].Value),$($netusageaverage[$i].value)" -Path $fileName

            $diskus++

        }

        else

        {

                Add-Content -Value "$($cpuusageaverage[$i].Entity.Name),$($cpuusageaverage[$i].Timestamp),$($cpuusageaverage[$i].Value),$($memusageaverage[$i].Value),0,$($netusageaverage[$i].value)" -Path $fileName

        }

    }

}

return(0)

 

 

Output :

                                                                          
ServerNameAVG_CPU_TimeAVG_CPUAVG_MEMAVG_diskAVG_Net
xxxxxxx12/15/2018 05:30:000.63871850277
Reply
0 Kudos
LucD
Leadership
Leadership

1) That depends on what Statistics Levels you have defined.

Check on the vCenter under Configure - General

2) The file has 1 name of a VM per line.


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

Reply
0 Kudos
prashantpote
Contributor
Contributor

1) is there any alternate parameter for disk.usage.average in vCenter6.5

2)The file has 1 name of a VM per line but giving output for only very last VM in last line.

Reply
0 Kudos
LucD
Leadership
Leadership

1) You should look at the PerformanceManager table.

Per metric is shows which statistics level is required to capture the metric.

Another point to verify are the Historical Intervals, you define Statistics Levels per historical interval.

And that defines what metrics are kept when aggregation takes place.

Have a look at my PowerCLI & VSphere Statistics – Part 1 – The Basics post for more info on the concept.

2) The script generates a CSV file per server.

Did it only produce 1 CSV file?


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

Reply
0 Kudos
prashantpote
Contributor
Contributor

I am not able to get per VM new csv file.

Also below line giving output 0 for all VMs Please cofirm if anything wrong.

 

$diskusage=Get-Stat -entity $vm -MaxSamples 168 -Start (Get-Date).AddDays(-90) -IntervalMins 15 -stat ‘virtualdisk.throughput.usage.average’ | ? { $_.instance -eq "" } | select Entity,Timestamp,Value |Sort-Object Timestamp

Reply
0 Kudos
LucD
Leadership
Leadership

If you don't bother to answer my questions, or do not even give any feedback on my replies (as you did with your previous threads), I'm afraid I'm going to stop answering you.

This is a community with voluntary contributions from other users, but it assumes at least some cooperation from all to work.


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

Reply
0 Kudos
prashantpote
Contributor
Contributor

I missed your reply for this thread, I was out of station for few days.

Sure, I will give you feedback once all issues get fixed.

I am using below code for 90 days utilisation of 10 VMs for output server name Time | AVG_CPU | AVG_MEM | AVG_disk | AVG_Net

VM1- servers.csv in below script contents below format vm names

VM2

VM3

 

issues :

1) Unable to get all VMs output, getting on csv file for last VM name listed in servers list

2) Maximum row output is only 168 Rows

3) Disk Output for all VMs showing 0

################################################################################################################################################

$servers=Get-Content C:\Users\servers.csv

foreach ($server in $servers)

{

    $vm=Get-VM $server

    if($? -eq $false)

    {

        continue

    }

    $fileName="C:\Users\VM_Utilization_Report.csv"

    $memusageaverage=Get-Stat -entity $vm -MaxSamples 168 -Start (Get-Date).AddDays(-90) -IntervalMins 1440 -stat ‘mem.active.average’ | ? { $_.instance -eq "" } | select Entity,Timestamp,Value |Sort-Object Timestamp

    $cpuusageaverage=Get-Stat -entity $vm -MaxSamples 168 -Start (Get-Date).AddDays(-90) -IntervalMins 1440 -stat ‘cpu.usage.average’ | ? { $_.instance -eq "" } | select Entity,Timestamp,Value |Sort-Object Timestamp

    $diskusage=Get-Stat -entity $vm -MaxSamples 168 -Start (Get-Date).AddDays(-90) -IntervalMins 1440 -stat ‘virtualdisk.throughput.usage.average’ | ? { $_.instance -eq "" } | select Entity,Timestamp,Value |Sort-Object Timestamp

    $netusageaverage=Get-Stat -entity $vm -MaxSamples 168 -Start (Get-Date).AddDays(-90) -IntervalMins 1440 -stat ‘net.usage.average’ | ? { $_.instance -eq "" } | select Entity,Timestamp,Value |Sort-Object Timestamp


    Set-Content -Value "ServerName,AVG_CPU_Time,AVG_CPU,AVG_MEM,AVG_disk,AVG_Net" -Path $fileName

    $diskus=0

    for ($i=0;$i -lt $cpuusageaverage.Count ; $i++)

    {

        if (($diskus -lt $diskusage.count) -and ($cpuusageaverage[$i].Timestamp -eq $diskusage[$diskus].Timestamp))

        {

            Add-Content -Value "$($cpuusageaverage[$i].Entity.Name),$($cpuusageaverage[$i].Timestamp),$($cpuusageaverage[$i].Value),$($memusageaverage[$i].Value),$($diskusage[$diskus].Value),$($netusageaverage[$i].value)" -Path $fileName

            $diskus++

        }

        else

        {

                Add-Content -Value "$($cpuusageaverage[$i].Entity.Name),$($cpuusageaverage[$i].Timestamp),$($cpuusageaverage[$i].Value),$($memusageaverage[$i].Value),0,$($netusageaverage[$i].value)" -Path $fileName

        }

    }

}

return(0)

 

##############################################################################################################################################

Reply
0 Kudos
prashantpote
Contributor
Contributor

I am new to PowerCLI and having trouble to create codes....

Can anybody help on this ????

Reply
0 Kudos
William_Garcia
Contributor
Contributor

Where can I download this script for VM utilization?

Reply
0 Kudos