Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
  /** @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);
  }