VMware {code} Community
lucassrg
Contributor
Contributor

*queryPerf method is returning old data or no data*

Hello everybody,

This is my first project with VMWare API and I'm facing some difficult to work with this API.

My application needs to get the following performance statistics from all virtual machine which I have installed in a ESX server:

- cpu.usage

- cpu.usagemgz

- mem.usage

- net.usage

- disk.usage

Actually, I need to get the current state of each Virtual machine for those metrics.

What I'm doing is the following:

1 - I'm creating a PropertyFilterSpec object, (I created all TransversalSpec objects first) .

2 - Then I'm running the following code to get all virtual machines (ok, there are more code that is not relevant for my question at this moment):

PropertyFilterSpec pfSpec=initializePropertyFilterSpec(); // transversal objects are ok.

ObjectContent]] ocary = service.retrieveProperties(sic.getPropertyCollector(), new PropertyFilterSpec]]);

for (ObjectContent oc : ocary)

{

for (DynamicProperty d : oc.getPropSet())

{

if ("name".equals(d.getName()))

{

//save the virtual machine instance and call as "myHost"

myHost = oc.getObj();

}

}

}

3 - Then, I'm calling the queryAvailablePerfMetric(getPerfManager(), myHost, null, null, null) method in order to retrieve all counterIds associated with my virtual machine.

4 - After that, I'm calling queryPerfCounter(getPerfManager(), counterIds) method in order to apply a filter, because I don't need all statistics. I just need a small set (cpu.usage, net.usage...).

5 - With a set of counterIds and PerfCounterInfo objects, I created a list of PerfMetricId objects:

List<PerfMetricId> myList = new ArrayList<PerfMetricId>();

for (Integer counterId : selectedCtrInfo.keySet()) {

PerfCounterInfo counterInfo = selectedCtrInfo.get(counterId);

PerfMetricId metric = new PerfMetricId();

metric.setCounterId(counterInfo.getKey());

metric.setInstance("");

myList.add(metric);

}

6 - The list of PerfMetricId's is used as a parameter of the setMetricId method, of PerfQuerySpec object.

See how I'm creating PerfQuerySpec object:

PerfQuerySpec querySpec = new PerfQuerySpec();

querySpec.setEntity(myHost);

querySpec.setFormat("normal");

querySpec.setMetricId(myListOfPerfMetricId);

Then I use this object as follow:

PerfEntityMetricBase]] metrics=service.queryPerf(_sic.getPerfManager(), new PerfQuerySpec[])

That is the point which is driving me crazy!!

All returned data of this method is old! I meant, I parse all the data and all returned objects are dated "2007"!!! But the point is, I need to get the current information from virtual machine ! If I set the start date as a current day (or even older), it returns null!

Anybody knows what is going on? Any help is really welcome!

Thanks,

Lucas Gomes

Reply
0 Kudos
3 Replies
admin
Immortal
Immortal

You will notice, the queryAvailablePerfMetric includes a parameter intervalId. If the this is set to the refreshRate returned in QueryProviderSummary, it can be used to retrieve available metrics for real-time performance statistics

Another approach could be set PerfQuerySpec's intervalId to the refreshRate and pass this querysepc to the QueryPerf method.

PerfProviderSummary summary = vimService.QueryPerfProviderSummary(manPerfMOR, aMor);

PerfQuerySpec qSpec = new PerfQuerySpec();

qSpec.maxSample = 1;

qSpec.intervalId = summary.refreshRate;

Reply
0 Kudos
lucassrg
Contributor
Contributor

Hi dkaur,

I tried both ways and I got the same results. All data is returning with the

year of "2007". Would be possible that the vm date is wrong?

Now I am checking the current Virtual Machine time. There is a method called

currentTime. I am passing a ServiceInstance reference as a parameter, but

the returned value is null.

_svcRef = new ManagedObjectReference();

_svcRef.setType("ServiceInstance");

svcRef.setvalue("ServiceInstance");

Calendar currentTime = service.currentTime(svcRef);

Do you have any other idea to help me?

Tks,

Lucas

On Wed, May 14, 2008 at 2:07 AM, dkaur <communities-emailer@vmware.com

Reply
0 Kudos
tmilner
Enthusiast
Enthusiast

Lucas,

I do something similar getting 5-minute data, so if you're still have problems I'd recommend the following:

  1. Get the servers time and determine the delta from your system.

  2. Specify the most recent 5-minute interval in the query (use the result of #1 to adjust it to the esx server's time)

For example, if the current time is 9:11 and the esx server's clock shows 10:11, then request the 10:05 sample.

Tom

Reply
0 Kudos