/** * Makes a PerfMetricId by looking up the counterId for the given group/name/rollupType/... params. * * https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.PerformanceManager.MetricId.html * * See <a href="https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/cpu_counters.html">cpu counters</a> * See <a href="https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/memory_counters.html>memory counters</a> * See <a href="https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/network_counters.html">network counters</a> * * @param group * @param name * @param rollupType * @return null if a PerfCoutner cannot be found for the given params */ private PerfMetricId findMetricId(String group, String name, PerfStatsType type, PerformanceManagerUnit unit, PerfSummaryType rollupType) { PerfMetricId res = new PerfMetricId(); PerfCounterInfo counter = this.perfCounterLookup .getCounter(name, group, type, rollupType, unit); if (counter == null) { String msg = String .format("Cannot find metric for %s/%s/%s/%s/%s", group, name, type, rollupType.value(), unit.value()); logger.warning(msg); throw new IllegalArgumentException(msg); } res.setCounterId(counter.getKey()); res.setInstance(""); return res; }
public PerfCounterInfo[] lookup(String groupName, String counterName, PerfSummaryType rollupType) { assert (groupName != null); assert (counterName != null); Map<String, List<PerfCounterInfo>> groupMap = _mapCounterInfos.get(groupName); if (groupMap == null) return null; List<PerfCounterInfo> counterInfoList = groupMap.get(counterName); if (counterInfoList == null) return null; if (rollupType == null) { return counterInfoList.toArray(new PerfCounterInfo[0]); } for (PerfCounterInfo info : counterInfoList) { if (info.getRollupType() == rollupType) return new PerfCounterInfo[] {info}; } return null; }
@Override public ServiceStat createStat(PerfCounterInfo pc, List<PerfSampleInfo> infos, List<Long> values) { if (infos == null || infos.isEmpty()) { return null; } ServiceStat res = new ServiceStat(); res.name = this.name; res.unit = this.unit; PerfSampleInfo info = null; double converted = 0; int intervalLengthMinutes = 5; res.timeSeriesStats = new TimeSeriesStats(24 * 60 / intervalLengthMinutes, intervalLengthMinutes * 60 * 1000, EnumSet.allOf(AggregationType.class)); for (int i = 0; i < infos.size(); i++) { info = infos.get(i); Long value = values.get(i); converted = convertValue(value); res.timeSeriesStats.add(getSampleTimestampMicros(info), converted, converted); } res.sourceTimeMicrosUtc = res.lastUpdateMicrosUtc = getSampleTimestampMicros(info); res.latestValue = converted; return res; }
/** * See <a href="https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.PerformanceManager.html#queryStats">queryStats method</a> * @param ctx * @return * @throws RuntimeFaultFaultMsg */ private List<ServiceStat> querySingleEntity(StatCollectionContext ctx) throws RuntimeFaultFaultMsg { List<PerfEntityMetricBase> metrics = getVimPort().queryPerf(PERF_MGR_MOREF, Collections.singletonList(ctx.getSpec())); List<ServiceStat> res = new ArrayList<>(); if (metrics.isEmpty()) { // nothing fetched return Collections.emptyList(); } // the metrics for the single entity PerfEntityMetric m = (PerfEntityMetric) metrics.get(0); for (PerfMetricSeries pms : m.getValue()) { PerfMetricId metricId = pms.getId(); PerfMetricIntSeries series = (PerfMetricIntSeries) pms; SamplesAggregator factory = ctx.getFactory(metricId.getCounterId()); PerfCounterInfo counter = this.perfCounterLookup .getCounterByKey(metricId.getCounterId()); ServiceStat stat = factory.createStat(counter, m.getSampleInfo(), series.getValue()); if (stat != null) { res.add(stat); } } return res; }
public PerfCounterInfo getCounter(String name, String groupName, PerfStatsType type, PerfSummaryType rollupType, PerformanceManagerUnit unit) { for (PerfCounterInfo pci : this.counters) { if (pci.getNameInfo().getKey().equals(name) && pci.getGroupInfo().getKey().equals(groupName) && pci.getRollupType().equals(rollupType) && pci.getStatsType().equals(type) && pci.getUnitInfo().getKey().equals(unit.value())) { return pci; } } return null; }
public PerfCounterInfo getCounterByKey(int key) { for (PerfCounterInfo pci : this.counters) { if (pci.getKey() == key) { return pci; } } return null; }
public static void main(String[] args) throws Exception { if(args.length != 3) { System.out.println("Usage: java PrintPerfMgr " + "<url> <username> <password>"); return; } ServiceInstance si = new ServiceInstance( new URL(args[0]), args[1], args[2], true); PerformanceManager perfMgr = si.getPerformanceManager(); System.out.println("***Print All Descriptions:"); PerformanceDescription pd = perfMgr.getDescription(); printPerfDescription(pd); System.out.println("\n***Print All Historical Intervals:"); PerfInterval[] pis = perfMgr.getHistoricalInterval(); printPerfIntervals(pis); System.out.println("\n***Print All Perf Counters:"); PerfCounterInfo[] pcis = perfMgr.getPerfCounter(); printPerfCounters(pcis); si.getServerConnection().logout(); }
static void printPerfCounters(PerfCounterInfo[] pcis) { for(int i=0; pcis!=null && i<pcis.length; i++) { System.out.println("\nKey:" + pcis[i].getKey()); String perfCounter = pcis[i].getGroupInfo().getKey() + "." + pcis[i].getNameInfo().getKey() + "." + pcis[i].getRollupType(); System.out.println("PerfCounter:" + perfCounter); System.out.println("Level:" + pcis[i].getLevel()); System.out.println("StatsType:" + pcis[i].getStatsType()); System.out.println("UnitInfo:" + pcis[i].getUnitInfo().getKey()); } }
/** * This method retrieves the performance counters available. * * @return a map of performance counters */ public Map<Integer, PerfCounterInfo> getPerfCounterInfoMap() { if (m_perfCounterInfoMap == null) { m_perfCounterInfoMap = new HashMap<Integer, PerfCounterInfo>(); PerfCounterInfo[] perfCounterInfos = getPerformanceManager().getPerfCounter(); for (PerfCounterInfo perfCounterInfo : perfCounterInfos) { m_perfCounterInfoMap.put(perfCounterInfo.getKey(), perfCounterInfo); } } return m_perfCounterInfoMap; }
public PerfCounterInfoMapper(PerfCounterInfo[] counterInfos) { if (counterInfos != null) { for (PerfCounterInfo counterInfo : counterInfos) { List<PerfCounterInfo> counterInfoList = getSafeCounterInfoList(counterInfo.getGroupInfo().getKey(), counterInfo.getNameInfo().getKey()); counterInfoList.add(counterInfo); } } }
public PerfCounterInfo lookupOne(String groupName, String counterName, PerfSummaryType rollupType) { PerfCounterInfo[] infos = lookup(groupName, counterName, rollupType); if (infos != null && infos.length > 0) return infos[0]; return null; }
private Map<String, List<PerfCounterInfo>> getSafeGroupMap(String groupName) { Map<String, List<PerfCounterInfo>> groupMap = _mapCounterInfos.get(groupName); if (groupMap == null) { groupMap = new HashMap<String, List<PerfCounterInfo>>(); _mapCounterInfos.put(groupName, groupMap); } return groupMap; }
private List<PerfCounterInfo> getSafeCounterInfoList(String groupName, String counterName) { Map<String, List<PerfCounterInfo>> groupMap = getSafeGroupMap(groupName); assert (groupMap != null); List<PerfCounterInfo> counterInfoList = groupMap.get(counterName); if (counterInfoList == null) { counterInfoList = new ArrayList<PerfCounterInfo>(); groupMap.put(counterName, counterInfoList); } return counterInfoList; }
public List<PerfCounterInfo> queryPerfCounter(int[] counterId) throws Exception { List<Integer> counterArr = new ArrayList<Integer>(); if (counterId != null) { for (int i = 0; i < counterId.length; i++) { counterArr.add(counterId[i]); } } return _context.getService().queryPerfCounter(_mor, counterArr); }
public PerfCounterLookup(List<PerfCounterInfo> counters) { this.counters = counters; }
/** * 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 List<PerfCounterInfo> queryPerfCounterByLevel(int level) throws Exception { return _context.getService().queryPerfCounterByLevel(_mor, level); }
public List<PerfCounterInfo> getCounterInfo() throws Exception { return _context.getVimClient().getDynamicProperty(_mor, "perfCounter"); }
/** * Generates a human-readable name for a performance counter. * * @param perfCounterInfo the perfomance counter info object * @return a string-representation of the performance counter's name */ private String getHumanReadableName(PerfCounterInfo perfCounterInfo) { return perfCounterInfo.getGroupInfo().getKey() + "." + perfCounterInfo.getNameInfo().getKey() + "." + perfCounterInfo.getRollupType().toString(); }
ServiceStat createStat(PerfCounterInfo counter, List<PerfSampleInfo> infos, List<Long> data);
List<PerfCounterInfo> getPerfCounter();
List<PerfCounterInfo> queryPerfCounter(List<Integer> counterIds) throws RuntimeFault, RemoteException;
List<PerfCounterInfo> queryPerfCounterByLevel(int level) throws RuntimeFault, RemoteException;