VMware Cloud Community
xdg
Contributor
Contributor

Can powercli call host script or command?

Hi, Dear all,

I defined an alarm rule of "host cpu usage" under virtual center console, I have received the alert several times till now.

I want to write a powercli script to capture such performance metrics like cpu, memory, processes at the same time alert happens, so i wonder how can i call host command like "esxtop, ps" or call one host script?

Thanks.

0 Kudos
11 Replies
LucD
Leadership
Leadership

First, no there is no direct way to start a COS command from within PowerCLI.

You can use the plink.exe command from the PuTTY Suite.

There are several samples available of plink.exe in the community.

On the other hand why would you start esxtop ?

With the Get-Stat cmdlet and the -Realtime parameter you can get performance data as well. The only difference is that the values will be over a 20-second interval while esxtop uses a 5-second interval.

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
xdg
Contributor
Contributor

Hi, LucD

Thanks.

I have thought using COS command of "ps aux" to get the top 5 CPU usage processes. But after further study, i found "ps aux" can't reflect the real CPU usage status and so is the top command.

Now it seems virtual machine cpu usage is high, my esx host is 2.4GHZx8( 4 cores per CPU), it is hard to believe only 4 virtual machines consume over 80% cpu resources. Is there some advice to investigate further more?

Regards

xdg

0 Kudos
LucD
Leadership
Leadership

You can start by finding out which guest is using the CPU resources.

This script will list the top-5 CPU consumers

$esxName = <hostname>
$esx = Get-VMHost -Name $esxName
$vms = Get-VM -Location $esx
$stats = Get-Stat -Stat "cpu.usage.average" -Entity $vms -Realtime -MaxSamples 1
$stats | Sort-Object -Descending -Property "Value" | `
	select -First 5 -Property @{N="Instance";E={$_.Entity.Name}},"Value" 

Note that -Realtime returns values calculated over 20 second intervals.

So there is no need to run this more frequently than every 20 seconds.

Once you have the culprit, you will have to look inside the guest to find the process(es) that are monopolsing the CPU.

____________

Blog: LucD notes

Twitter: lucd22


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

xdg
Contributor
Contributor

Hi, LucD

How to add vm name into the result, the script result is as below:

MetricId Timestamp Value Unit Insta

nce

-


-


-


-


-


cpu.usage.average 11/13/2010 1:40:40 PM 3.01 %

cpu.usage.average 11/13/2010 1:40:20 PM 6.51 %

cpu.usage.average 11/13/2010 1:40:00 PM 2.76 %

cpu.usage.average 11/13/2010 1:39:40 PM 3.01 %

I set the script as a triggered script in the virtual center alarm configuration console, but when the host report cpu high usage, the virtual center told me time out to execute the script, is there any other way to capture the host state?

By the way, do you know how long the host will keep performance metrics at memory?

Thanks.

xdg

0 Kudos
LucD
Leadership
Leadership

The name should there, it's in the Entity property.

Did you include the Select line and the back-tick on the preceding line ?

From your output it looks as if you only execute the Get-Stat cmdlet.

The Realtime performance data is kept for 1 to 2 hours, depends a bit on how busy your ESX(i) servers are.

When you want to execute a PowerCLI script from an Alarm there are a few things to look out for.

Could you perhaps show how you call the script from the alarm ?

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
xdg
Contributor
Contributor

Hi, LucD

Yes, the script is right.

Please look at following image for how I configured the script at vc console:

Thanks

0 Kudos
LucD
Leadership
Leadership

That "run script" action looks correct.

If you still don't get the guest's name in the output, can you attach the .bat and .ps1 file as well ?

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
xdg
Contributor
Contributor

Hi, LucD

You are right, the script is ok.

Do you know the theory of how virtual center trigger alarm?

Though the virtual center report CPU usage higher than 70%, but i can't find history performance data prove that.

The condition length i defined at virtual center alarm configuration console is 5 minutes and the interval duration for 1 days defined at vcenter server statistics settings is also 5 minutes.

Why exist the disagreement of VC alarm and history performance data?

Thanks

0 Kudos
LucD
Leadership
Leadership

The metric alarms use, afaik, realtime performance values to determine if a threshold was exceeded or not.

See my PowerCLI & vSphere statistics – Part 1 – The basics for an intro on realtime and historical intervals.

You should see the value exceeding the threshold in the vSphere client Performance tab, provided you selected the realtime option and the correct metric..

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
xdg
Contributor
Contributor

Hi, LucD

It is strange i can't find any evidence of cpu usage high at the real-time performance graph, below image is the combination of real-time performance,host events and alarm configuration.

Is there possible one cpu core usage exceeding the alarm point

Thanks

0 Kudos
LucD
Leadership
Leadership

Afaik, the alarm uses the aggregate value for the instance.

You could check by selecting the indiviidual cores as well on the Performance chart.

Perhaps you should raise this in the Performance Community

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos