/** * 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(); }
private static PerfCounterInfo getCounterInfo( List<PerfCounterInfo> counterInfo, String groupName, String counterName) { for (PerfCounterInfo info : counterInfo) { if (info.getGroupInfo().getKey().equals(groupName) && info.getNameInfo().getKey().equals(counterName)) { return info; } } return null; }
/** * 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; }
/** @throws Exception */ private static void displayStats() throws Exception { String[][] statsList = getCounters(); ManagedObjectReference hostmor = getHostByHostName(hostname); if (hostmor == null) { System.out.println("Host Not Found"); return; } Object property; ArrayList props = (ArrayList) getDynamicProperty(perfManager, "perfCounter"); if (props != null && props.size() > 0) { property = props.get(0); } else { property = null; } // ArrayOfPerfCounterInfo arrayCounter = (ArrayOfPerfCounterInfo) property; ArrayList counterInfoList = new ArrayList(); counterInfoList.add(property); List<PerfMetricId> midVector = new ArrayList<PerfMetricId>(); List<String> statNames = new ArrayList<String>(); for (int i = 0; i < statsList.length; i++) { PerfCounterInfo counterInfo = getCounterInfo(counterInfoList, statsList[i][0], statsList[i][1]); if (counterInfo == null) { System.out.println( "Warning: Unable to find stat " + statsList[i][0] + " " + statsList[i][1]); continue; } String counterName = counterInfo.getNameInfo().getLabel(); statNames.add(counterName); PerfMetricId pmid = new PerfMetricId(); pmid.setCounterId(counterInfo.getKey()); pmid.setInstance(""); midVector.add(pmid); } List<PerfMetricId> midList = new ArrayList<PerfMetricId>(midVector); Collections.copy(midList, midVector); PerfQuerySpec spec = new PerfQuerySpec(); spec.setEntity(hostmor); GregorianCalendar startTime = new GregorianCalendar(); startTime.add(Calendar.SECOND, -60); XMLGregorianCalendar starttimexmlgc = DatatypeFactory.newInstance().newXMLGregorianCalendar(startTime); // spec.setStartTime(starttimexmlgc); spec.getMetricId().addAll(midList); spec.setIntervalId(new Integer(20)); querySpec = spec; final List<String> statNames2 = statNames; javax.swing.SwingUtilities.invokeLater( new Runnable() { public void run() { createAndShowGUI("VM Name", statNames2); } }); Timer timer = new Timer(true); timer.schedule( new TimerTask() { public void run() { refreshStats(); } }, 1000, 21000); }