示例#1
0
文件: VITop.java 项目: mikelopez/jvm
 private static void refreshStats() {
   try {
     PerfCompositeMetric metric = vimPort.queryPerfComposite(perfManager, querySpec);
     XMLGregorianCalendar latestTs = displayStats(querySpec.getMetricId(), metric);
     if (latestTs != null) {
       querySpec.setStartTime(latestTs);
     }
   } catch (SOAPFaultException sfe) {
     printSoapFaultException(sfe);
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
示例#2
0
文件: VITop.java 项目: mikelopez/jvm
  /** @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);
  }