VMware Cloud Community
alexander19
Contributor
Contributor

Cluster CPU Usage Average

Hello,

After I have read few topic related to this problem I found this script:

$stat = "cpu.usage.average"

$entity = Get-Cluster

$start = (Get-Date).AddDays(-7)

Get-Stat -Entity $entity -Start $start -Stat $stat |

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

Select Name,

    @{N="CPU average";E={$_.Group | Measure-Object -Property Value -Average | Select -ExpandProperty Average}}

The problem is that I'm getting only 1 cluster in results and one of Vcenter have 2 cluster and second one 4 clusters.

Get-Cluster  is showing correct numer and name for clusters.

I've already try to modify this code but nothing seems to work. A littel bit of help please?

20 Replies
LucD
Leadership
Leadership

What do you have in $entity, in other words what does Get-Cluster return?

And you are connected to both vCenters? Check what $global:defaultviservers returns


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

0 Kudos
alexander19
Contributor
Contributor

Let me give you a example:

vcenter1.local

CLUSTER1

CLUSTER2

If i run this code the only info I get is Cpu Usage Avg for  CLUSTER1

If I run Get-Cluster i get both CLUSTER name's

0 Kudos
LucD
Leadership
Leadership

Strange, your code should return all clusters.

What does this return?

Get-Stat -Entity $entity -Start $start -Stat $stat |

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


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

0 Kudos
alexander19
Contributor
Contributor

Count        Name                      Group                                                                                               

----- ----                                           -----                                                                                               

   84          CLUSTER1              {6.05, 6.13, 5.56, 5.37...}

0 Kudos
LucD
Leadership
Leadership

It looks as if your vCenters are only collecting performance data for 1 cluster.

If you look in Web Client at the Performance tab of these clusters, do you see performance data over the 7 day period?

Note that Get-Stat will not return anything if there no data to be found for the Start date.

Did you already try with a shorter interval, for example $start = (Get-Date).AddHours(-8)


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

0 Kudos
alexander19
Contributor
Contributor

$start = (Get-Date).AddHours(-8)

Name                                                                                                                      CPU average

----                                                                                                                      -----------

CLUSTER1                                                                                                         3.0558510435112

yes in web client I can see performance for both clusters (7 days for example)

0 Kudos
LucD
Leadership
Leadership

Not sure what is happening here, I suspected an error in the aggregation jobs on the vCenter, but then the Web CLient shouldn't show data either.

Let's start with the beginning, are all clusters showing Realtime data?

$entity = Get-Cluster

Get-Stat -Entity $cluster -Stat cpu.usage.average -Realtime -MaxSamples 1


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

0 Kudos
alexander19
Contributor
Contributor

Not sure if here are all clusters presented

MetricId                Timestamp                          Value Unit     Instance

--------                ---------                          ----- ----     --------

cpu.usage.average       7/24/2017 10:30:00 PM               3.92 %        *      

0 Kudos
LucD
Leadership
Leadership

No, you should have at least 1 line per cluster.

Which role does the account you are using to connect to the vCenters have?

Could you be missing some permissions on the clusters besides Cluster1?

But that still would not explain why you see the performance data under the Performance tab in the Web Client.


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

0 Kudos
alexander19
Contributor
Contributor

I have full acces on enviroment. All day I've try to find a solution for this problem. I cannot explain why is not working.

I think here can be the problem:

Get-Stat : 7/24/2017 10:45:04 PM    Get-Stat        A specified parameter was not correct.

querySpec.size   

At line:6 char:1

+ Get-Stat -Entity $entity -Start $start -Stat $stat |

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Get-Stat], InvalidArgument

    + FullyQualifiedErrorId : Client20_RuntimeDataServiceImpl_GetStats_ErrorRetreivingPerfMetrics,VMware.VimAutomation.ViCore.Cmdlet

   s.Commands.GetViStats

Can be related to my issue?

0 Kudos
LucD
Leadership
Leadership

Yes, that problem is explained in KB2107096.

It would have helped had you mentioned that error sooner :smileygrin:


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

0 Kudos
alexander19
Contributor
Contributor

Sorry for misunderstanding. I've read the kb but unfortunately our environment is pretty sensible and it is not recommend to change as in kb. I think this is the only way available?

0 Kudos
LucD
Leadership
Leadership

I'm afraid so.

I know of no other way to remove this limit.

If you only want to remove the limit on the API calls (used by Get-Stat), the advanced setting 'config.vpxd.stats.maxQueryMetrics' is sufficient.


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

0 Kudos
mad83
Contributor
Contributor

Hello Luc,

from my experience implementation of KB2107096 is not solving problem with gething cluster statistics when i use Get-Stat cmdlet.

If i understood above KB correctly to solve an issue i should set 64 value for config.vpxd.stats.maxQueryMetrics.

Before implementation i did not get this setting available.

strange think is going on my environment:

1)     when i use this code:   Get-Stat -Entity ($clusters) -start $startdate -Finish $enddate -stat cpu.usagemhz.average - i get below error:

Get-Stat : 28-5-2018 13:55:27    Get-Stat        A specified parameter was not correct.

querySpec.size   

At line:1 char:1

+ Get-Stat -Entity "MY CLUSTER" -start 17/05/2018 -Finish 24/05/2018 -stat cpu.us ...

2) when i use the same code but i put my esx host i get some CPU statistics:

PS D:\Scripts\> Get-Stat -Entity "MY ESX HOST" -start 17/05/2018 -Finish 28/05/2018 -stat cpu.usagemhz.average

MetricId                Timestamp                          Value Unit     Instance

--------                ---------                          ----- ----     --------

cpu.usagemhz.average    28-5-2018 00:00:00                  1511 MHz             

cpu.usagemhz.average    27-5-2018 22:00:00                  1531 MHz             

cpu.usagemhz.average    27-5-2018 20:00:00                  1476 MHz             

cpu.usagemhz.average    27-5-2018 18:00:00                  1448 MHz             

cpu.usagemhz.average    27-5-2018 16:00:00                  1413 MHz             

cpu.usagemhz.average    27-5-2018 14:00:00                  1568 MHz  

Could you please advise?    

and BTW my vCenter server statistics levels are:

5 minutes - 3

30 minutes - 2

2 hours - 1

1 day - 1

0 Kudos
LucD
Leadership
Leadership

64 is the default value in vSPhere 5.5 and 6.0.

You should use a higher value or use -1 to disable the limit.


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

0 Kudos
mad83
Contributor
Contributor

Hello LucD,

thank you for your replay. One small update to this topic.

On my one cluster (contains more than 18 ESXi hosts) statistics are not generated, but my small cluster (3 ESXi hosts) statistics were been shown.

what do you think about this?

I did not have chance to increase value from 64 to higher. I'm consider now to set it up to 128.

0 Kudos
LucD
Leadership
Leadership

I would suggest to first try setting the value to -1 (disabling the limit).
When that fixes the issue (stats for all your clusters), you can start experimenting which value you need (provided you want to enable the limit again).


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

0 Kudos
mad83
Contributor
Contributor

ok. many thanks. :smileygrin:

0 Kudos
gbbhat
Contributor
Contributor

Is is possible to find this information from Python / REST APIs.?
I am interested in the metrics of over 2days,
So far from whatever I tried, Python is able to give a point in time data for utilization (cpu / memory)
but not all the datapoints over two days.

I am trying to integrate this into a web application for internal usage, it runs on a RHEL server,
I wouldn't go as far as to integrate the application with PowerCLI and then parsing the stdout into Python etc.

0 Kudos