VI Java API: Performance historical intervals

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.rmi.RemoteException;

import com.vmware.vim25.InvalidProperty;
import com.vmware.vim25.PerfInterval;
import com.vmware.vim25.RuntimeFault;

public class PerformanceIntervals {

	static final String SERVER_NAME = "";
	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());
		} catch (InvalidProperty e) {
			// TODO Auto-generated catch block
		} catch (RuntimeFault e) {
			// TODO Auto-generated catch block
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block

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.

5 thoughts on “VI Java API: Performance historical intervals

  1. 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

  2. hello benoit
    i need to calculate the size of snapshot of virtual machine how to do this
    please help me as soon as possibel

Leave a Reply

Your email address will not be published. Required fields are marked *