In my previous post, I’ve shown how to get performance counters using the VI Java API. I used there PerformanceManager.queryPerfProviderSummary(host).getRefreshRate() to get a performance interval for queryAvailablePerfMetric and queryPerf. This returns refreshRate for real-time performance statistics (20 seconds). Instead of the real-time performance, you might be interested in historical performance counters.
To retrieve available metrics for historical performance statistics, you have to use existing historical intervals. In order to query for acceptable historical intervals, you can use the getHistoricalInterval method of the PerformanceManager:
package com.benohead.esx; import java.net.MalformedURLException; import java.net.URL; import java.rmi.RemoteException; import com.vmware.vim25.InvalidProperty; import com.vmware.vim25.PerfInterval; import com.vmware.vim25.RuntimeFault; import com.vmware.vim25.mo.PerformanceManager; import com.vmware.vim25.mo.ServiceInstance; public class PerformanceIntervals { static final String SERVER_NAME = "192.168.190.87"; static final String USER_NAME = "Administrator"; static final String PASSWORD = "xxxxxx"; public static void main(String[] args) { String url = "https://" + SERVER_NAME + "/sdk/vimService"; try { ServiceInstance si = new ServiceInstance(new URL(url), USER_NAME, PASSWORD, true); PerformanceManager perfMgr = si.getPerformanceManager(); PerfInterval[] perfIntervals = perfMgr.getHistoricalInterval(); for (PerfInterval perfInterval : perfIntervals) { System.out.println("key = " + perfInterval.getKey()); System.out.println("length = " + perfInterval.getLength()); System.out.println("samplingPeriod = " + perfInterval.getSamplingPeriod()); System.out.println("level = " + perfInterval.getLevel()); System.out.println("name = " + perfInterval.getName()); System.out.println(); } si.getServerConnection().logout(); } catch (InvalidProperty e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (RuntimeFault e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
The sampling period can then be used in your queries.
By default a vCenter Server will save collection data for the following time periods:
- 5-minute samples for the past day
- 30-minute samples for the past week
- 2-hour samples for the past month
- 1-day samples for the past year
You can change the sampling rate for an interval using the updatePerfInterval method of the PerformanceManager.
I´m very glad with you because your tutorials about how to use the vmware api are very clear and provide me one way to understand how to code with the library.
Can you help me reading a basic information about a Virtual Machine, items like memory and cpu that is consumed actually.
Ruben Espinosa
Hola Ruben,
You can see how to get information regarding a virtual machine in this post.
Saludos,
Henri
hello benoit
i need to calculate the size of snapshot of virtual machine how to do this
please help me as soon as possibel
This is good stuff!
Thank you for your time posting this useful information!
Great tutorial, thanks for this!