VMware Cloud Community
cwb2000
Contributor
Contributor
Jump to solution

How to access ESXi host's CPU/Memory totally & usage, and CPU's temp with PowerCLI.

Dear All,

I am struggling with read host's CPU/Memory totally & usage information from PowerCLI, and the CPU's temp is also quite useful to me. I used "Get-VMHost -Name" to get VMHost object but can't get his Properties such as CpuTotalMhz, CpuUsageMhz, MemoryTotalMB, MemoryUsageMB.

And also don't know which object has the CPU's temp information. Thanks!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You are definitely using a rather old PowerCLI version (4.0).

Let's see if the upgrade solves a number of these problems.


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

View solution in original post

0 Kudos
9 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

If you execute the PowerCLI command:

Get-VMHost | Get-Member

you will see all the properties and methods that a VMHostImpl object has. With:

Get-VMHost | Select-Object -Property Name,CpuTotalMhz,CpuUsageMhz,MemoryTotalMB,MemoryUsageMB


you will select the Name, CpuTotalMhz, CpuUsageMhz, MemoryTotalMB and MemoryUsageMB properties.

I don't know what you mean with CPU's temp information. Maybe you can try to explain that in a different way.

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
LucD
Leadership
Leadership
Jump to solution

The CPU temperature is available, when the sensors in the HW you are using, are supported.

For example, on IBM x36 HW, you can read the temperature at the front panel like this.

Get-VMHost | Select Name,
    @{N="Temp";E={
        $sensor = $_.Extensiondata.Runtime.HealthSystemRuntime.SystemHealthInfo.NumericSensorInfo | 
            where {$_.Name -like "Front Panel Board 1 Ambient Temp*"}
        "{0} {1}" -f ($sensor.CurrentReading * [Math]::Pow(10,$sensor.UnitModifier)),$sensor.BaseUnits
    }
}

First check via the vSphere client which sensor you want to read, and then adapt the Where-clause

temp.png


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

cwb2000
Contributor
Contributor
Jump to solution

Thanks Robert/LucD ,

I am quite fresh with ESXi, actually I am looking into one solution to integrate the status of ESXi host & cluster, SAN Cluster & other live system into our SCADA system, then means we have a common Human-Machine interface to display the critical information of each systems.

Few interesting things happens in my case/test, and don't know why. For the Get-VMHost | Get-Member or Get-VMHost | Select-Object -Property XXX, actually I can't get  "CpuTotalMhz,CpuUsageMhz,MemoryTotalMB,MemoryUsageMB", what I got is display within the pictures. Then I have to get those information from "$esxi.Summary.Hardware.CpuMhz", "$esxi.Summary.QuickStats.OverallCpuUsage", "$esxi.Summary.QuickStats.OverallMemoryUsage" & "$esxi.Summary.QuickStats.OverallMemoryUsage" etc. Here "$esxi = Get-VMHost | Get-View".

The second thing about the CPU's temperature, I must go with "$esxi.Runtime.HealthSystemRuntime.SystemHealthInfo.NumericSensorInfo" without "Extensiondata".

The third thing about the Datastore, we have two ESXi hosts which are in a same cluster with two common Datastores. But one same Datastore, Datastore2, has different FreeSpace feedback when I quote from different host, the CapacityMB is same. What I used here is $Datastores = Get-Datastore, then used $Datastores.FreeSpaceMB. And what I got is follows:

Datastore   UsedGB  FreeGB  PercFree
Datastore2   417.58    282.17      40        from Host1


Datastore2   413.08    286.67      41        from Host2


What I have here is

Script editor/debug: PowerGUI.3.0.0.2015
PowerCLI:            VMware-Vim4PS-4.0.0-162509
ESXi:                4.1.0, 348481

And the next thing what I would like to do is display Alarm state & alarm information into SCADA, any comments for which object I can browse for when there is alarm within host/cluster, and what kind of alarm there is. Thanks a lot for the kind help.

0 Kudos
cwb2000
Contributor
Contributor
Jump to solution

Hi Robert,

Thanks for the help, I got more questions follows, could you be able to help me out? Thanks a lot!

0 Kudos
cwb2000
Contributor
Contributor
Jump to solution

Hi LucD,

Thanks for the help, I got more questions follows, could you be able to help me out? Thanks a lot!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is indeed a funny phenomena you see there.

Let's first check that this is not something in PowerGui.

Start the PowerCLI prompt, do a Connect-VIServer to your vCenter.

Then execute both lines from this prompt

Get-VMHost | Get-Member

Get-VMHost | Select Name,CpuTotalMhz,CpuUsageMhz,MemoryTotalMB,MemoryUsageMB

If you don't need the Extensiondata property in the path, that would mean you are working with a HostSystem object instead of a VMHostImpl object.

The first one is a copy of  a Server-SIde object that you get through a Get-View cmdlet.

The 2nd one is the object that Get-VMHost returns.

Perhaps it would be usefull to attach your complete script you are using.

Try adding the -Refresh switch on the Get-Datastore cmdlet.

Perhaps the difference is due to stale data.

I would suggest you update your PowerCLI version.

You are not using the latest version.

You can add an action to an Alarm that fires a script when the alarm is triggered. See the New-AlarmAction cmdlet and the Managing vSphere Alarms with PowerCLI post.

In that script you have access to information about the alarm (which entity fired it, the alarm state, the timestamp...).

If you can interface with your SCADA from PowerShell, you can pass the required information.

See


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

0 Kudos
cwb2000
Contributor
Contributor
Jump to solution

Hi LucD,

More interesting things.

I tried with PowerCLI prompt to connect to vCenter server, please refer to first picture, seems similar as within PowerGui.

For  the Get-Datastore, I can't use -Refresh, please refer to picture 2&3. It will display error with "-Refresh" within both PowerGui/Run with Powershell.

But I will get accurate result althrough there is error, and I will get the wrong information without "-Refresh".

Here I attached the module within PowerGui as well picture 4, and maybe "Initialize-VIToolkitEnvironment.ps1" affect something. I am not sure.

I attached my script as well. You are right, now this script is connecting to ESXi host directly.

I will try to download the latest PowerCLI & try. Will update later.

Thanks again!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You are definitely using a rather old PowerCLI version (4.0).

Let's see if the upgrade solves a number of these problems.


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

0 Kudos
cwb2000
Contributor
Contributor
Jump to solution

Hi LucD,

I updated to PowerCLI 5.0.0-435426, seems most of the interested issue never happen again. Thanks a lot!

0 Kudos