VMware Cloud Community
vmk2014
Expert
Expert

Host utilization report

Hi , All

I'm trying to retrieve the Host utilization report with PowerCLI script to find out average CPU and Memory hosts utilization during period of time and push the data to BI tool, but it fails with an error for all the hosts. Looking for help.

pastedImage_0.png

Thanks

Import-Module VMware.VimAutomation.Core

Connect-VIServer -Server Domain.com -user "Domain\user"

$now = Get-Date

$start = $now.AddDays(-1)

$finish = $now

$SStat = @{

   Entity = Get-VMHost

   Stat = 'cpu.usage.average', 'mem.usage.average'

   Start = $start

   Finish = $finish

   Instance = '*'

   ErrorAction = 'SilentlyContinue'

}

Get-Stat @sStat |

Group-Object -Property { $_.Entity.Name } |

ForEach-Object -Process {

   New-Object -TypeName PSObject -Property ([ordered]@{

   Host = $_.Name

   Start = $start

   Finish = $finish

   CpuAvgPerc = [math]::Round(($_.Group | where { $_.MetricId -eq 'cpu.usage.average' } | Measure-Object -Property Value -Average).Average, 1)

   MemAvgPerc = [math]::Round(($_.Group | where { $_.MetricId -eq 'mem.usage.average' } | Measure-Object -Property Value -Average).Average, 1)

   })

$payload = @{

        "Date" = $Date

        "Host" = $Host.Name

        "CpuAvgPerc" = $CpuAvgPerc

        "MemAvgPerc" = $MemAvgPerc

    }

    Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($payload))

}

Disconnect-VIServer * -Confirm:$false

$endpoint = "https://api.powerbi.com/beta/a1f1e214-7ded-45b6-81a1-9e8ae3459641/datasets/fa0310ec-1f92-4050-9b14-d..."

$payload = @{

"Date" = $Date

"Host" = $Host.Name

"CpuAvgPerc" = $CpuAvgPerc

"MemAvgPerc" = $MemAvgPerc

}

Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($payload))

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership

Afaik PowerBI has moved some time ago (2015) from beta to GA.

I suspect your URI should start with https://api.powerbi.com/v1.0/ instead of https://api.powerbi.com/beta/


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

Reply
0 Kudos
vmk2014
Expert
Expert

LucD,

You might be correct, but in other similar thread you helped me with correction and it executed without fail. I guess it is not related to PowerBI and the data will move to cloud BI.

i tried, but it didn't not make any difference as said in the earlier mail thread it worked with similar version i.e. Beta. I appreciate your help. I believe it is variable declared is wrong or bracket missing i.e } in the script.

Thanks

V

Reply
0 Kudos
LucD
Leadership
Leadership

I would suggest you raise the question in a PowerBI forum.
I don't expect there to be a lot of PowerBI specialists in this community.


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

LucD
Leadership
Leadership

In a thread on the PowerBI forum they talk about an issue that looks similar to what you are seeing.
Have a look at Power BI Rest API Error

Btw, you can perhaps post your issue in that forum.


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

Reply
0 Kudos