static PerfQuerySpec createPerfQuerySpec(ManagedEntity me, PerfMetricId[] metricIds, int maxSample, int interval) { PerfQuerySpec qSpec = new PerfQuerySpec(); qSpec.setEntity(me.getMOR()); // set the maximum of metrics to be return // only appropriate in real-time performance collecting qSpec.setMaxSample(new Integer(maxSample)); // qSpec.setMetricId(metricIds); // optionally you can set format as "normal" qSpec.setFormat("csv"); // set the interval to the refresh rate for the entity qSpec.setIntervalId(new Integer(interval)); return qSpec; }
private static PerfQuerySpec createPerfQuerySpec(ManagedEntity me, PerfMetricId[] metricIds, int maxSample, int interval) { PerfQuerySpec qSpec = new PerfQuerySpec(); qSpec.setEntity(me.getMOR()); // set the maximum of metrics to be return // only appropriate in real-time performance collecting qSpec.setMaxSample(new Integer(maxSample)); // qSpec.setMetricId(metricIds); // optionally you can set format as "normal" qSpec.setFormat("normal"); // set the interval to the refresh rate for the entity qSpec.setIntervalId(new Integer(interval)); return qSpec; }
public StatCollectionContext(ManagedObjectReference ref) { this.spec = new PerfQuerySpec(); this.spec.setEntity(ref); this.aggregatorsByPerfCounterId = new HashMap<>(); }
public PerfQuerySpec getSpec() { return this.spec; }
public static void main(String[] args) throws Exception { if(args.length != 4) { System.out.println("Usage: java RealtimePerfMonitor " + "<url> <username> <password> <vmname>"); return; } ServiceInstance si = new ServiceInstance( new URL(args[0]), args[1], args[2], true); String vmname = args[3]; ManagedEntity vm = new InventoryNavigator( si.getRootFolder()).searchManagedEntity( "VirtualMachine", vmname); if(vm == null) { System.out.println("Virtual Machine " + vmname + " cannot be found."); si.getServerConnection().logout(); return; } PerformanceManager perfMgr = si.getPerformanceManager(); // find out the refresh rate for the virtual machine PerfProviderSummary pps = perfMgr.queryPerfProviderSummary(vm); int refreshRate = pps.getRefreshRate().intValue(); // retrieve all the available perf metrics for vm PerfMetricId[] pmis = perfMgr.queryAvailablePerfMetric( vm, null, null, refreshRate); PerfQuerySpec qSpec = createPerfQuerySpec( vm, pmis, 3, refreshRate); while(true) { PerfEntityMetricBase[] pValues = perfMgr.queryPerf( new PerfQuerySpec[] {qSpec}); if(pValues != null) { displayValues(pValues); } System.out.println("Sleeping 60 seconds..."); Thread.sleep(refreshRate*3*1000); } }
public static void main(String[] args) throws Exception { if(args.length != 4) { System.out.println("Usage: java GetMultiPerf " + "<url> <username> <password> <vmname>"); return; } ServiceInstance si = new ServiceInstance( new URL(args[0]), args[1], args[2], true); String vmname = args[3]; VirtualMachine vm = (VirtualMachine) new InventoryNavigator( si.getRootFolder()).searchManagedEntity( "VirtualMachine", vmname); if(vm == null) { System.out.println("Virtual Machine " + vmname + " cannot be found."); si.getServerConnection().logout(); return; } PerformanceManager perfMgr = si.getPerformanceManager(); int perfInterval = 1800; // 30 minutes for PastWeek // retrieve all the available perf metrics for vm PerfMetricId[] pmis = perfMgr.queryAvailablePerfMetric( vm, null, null, perfInterval); Calendar curTime = si.currentTime(); PerfQuerySpec qSpec = new PerfQuerySpec(); qSpec.setEntity(vm.getRuntime().getHost()); //metricIDs must be provided, or InvalidArgumentFault qSpec.setMetricId(pmis); qSpec.setFormat("normal"); //optional since it's default qSpec.setIntervalId(perfInterval); Calendar startTime = (Calendar) curTime.clone(); startTime.roll(Calendar.DATE, -4); System.out.println("start:" + startTime.getTime()); qSpec.setStartTime(startTime); Calendar endTime = (Calendar) curTime.clone(); endTime.roll(Calendar.DATE, -3); System.out.println("end:" + endTime.getTime()); qSpec.setEndTime(endTime); PerfCompositeMetric pv = perfMgr.queryPerfComposite(qSpec); if(pv != null) { printPerfMetric(pv.getEntity()); PerfEntityMetricBase[] pembs = pv.getChildEntity(); for(int i=0; pembs!=null && i< pembs.length; i++) { printPerfMetric(pembs[i]); } } si.getServerConnection().logout(); }
/** * This method queries performance values for a given managed entity. * * @param managedEntity the managed entity to query * @return the perfomance values * @throws RemoteException */ public VmwarePerformanceValues queryPerformanceValues(ManagedEntity managedEntity) throws RemoteException { VmwarePerformanceValues vmwarePerformanceValues = new VmwarePerformanceValues(); int refreshRate = getPerformanceManager().queryPerfProviderSummary(managedEntity).getRefreshRate(); PerfQuerySpec perfQuerySpec = new PerfQuerySpec(); perfQuerySpec.setEntity(managedEntity.getMOR()); perfQuerySpec.setMaxSample(Integer.valueOf(1)); perfQuerySpec.setIntervalId(refreshRate); PerfEntityMetricBase[] perfEntityMetricBases = getPerformanceManager().queryPerf(new PerfQuerySpec[]{perfQuerySpec}); if (perfEntityMetricBases != null) { for (int i = 0; i < perfEntityMetricBases.length; i++) { PerfMetricSeries[] perfMetricSeries = ((PerfEntityMetric) perfEntityMetricBases[i]).getValue(); for (int j = 0; perfMetricSeries != null && j < perfMetricSeries.length; j++) { if (perfMetricSeries[j] instanceof PerfMetricIntSeries) { long[] longs = ((PerfMetricIntSeries) perfMetricSeries[j]).getValue(); if (longs.length == 1) { PerfCounterInfo perfCounterInfo = getPerfCounterInfoMap().get(perfMetricSeries[j].getId().getCounterId()); String instance = perfMetricSeries[j].getId().getInstance(); String name = getHumanReadableName(perfCounterInfo); if (instance != null && !"".equals(instance)) { vmwarePerformanceValues.addValue(name, instance, longs[0]); } else { vmwarePerformanceValues.addValue(name, longs[0]); } } } } } } return vmwarePerformanceValues; }
public PerfCompositeMetric queryPerfComposite(PerfQuerySpec spec) throws Exception { return _context.getService().queryPerfComposite(_mor, spec); }
public List<PerfEntityMetricBase> queryPerf(PerfQuerySpec[] specs) throws Exception { return _context.getService().queryPerf(_mor, Arrays.asList(specs)); }
List<PerfEntityMetricBase> queryPerf(List<PerfQuerySpec> querySpec) throws RuntimeFault, RemoteException;
PerfCompositeMetric queryPerfComposite(PerfQuerySpec querySpec) throws RuntimeFault, RemoteException;