private void checkCompatibility() {
      OperatingSystemMXBean osmx = ManagementFactory.getOperatingSystemMXBean();
      if (osmx == null) {
        throw new UnsupportedOperationException("Failed to get OperatingSystemMXBean");
      }
      Class[] interfaces = osmx.getClass().getInterfaces();
      boolean hasInterface = false;
      if (interfaces != null) {
        for (Class i : interfaces) {
          if ("com.sun.management.OperatingSystemMXBean".equals(i.getName())
              || "com.sun.management.UnixOperatingSystemMXBean".equals(i.getName())) {
            hasInterface = true;
            break;
          }
        }
      }

      if (!hasInterface) {
        throw new UnsupportedOperationException(
            "Incompatible OperatingSystemMXBean class: " + osmx.getClass().getName());
      }

      RuntimeMXBean rtmx = ManagementFactory.getRuntimeMXBean();
      if (rtmx == null) {
        throw new UnsupportedOperationException("Failed to get RuntimeMXBean");
      }
    }
 private long getCpuTime() {
   OperatingSystemMXBean osmx = ManagementFactory.getOperatingSystemMXBean();
   try {
     Method getProcessCpuTime = osmx.getClass().getDeclaredMethod("getProcessCpuTime");
     getProcessCpuTime.setAccessible(true);
     Object o = getProcessCpuTime.invoke(osmx);
     if (o instanceof Long) {
       return (Long) o;
     }
   } catch (Throwable e) {
   }
   return 0L;
 }
 private Object invokeMethod(String methodName)
     throws NoSuchMethodException, SecurityException, IllegalAccessException,
         IllegalArgumentException, InvocationTargetException {
   final Method method = mxBean.getClass().getDeclaredMethod(methodName);
   method.setAccessible(true);
   return method.invoke(mxBean);
 }
 private void jvmSummary() {
   OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
   RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
   stdout.format(
       "JVM: %s %s %s\n",
       runtimeBean.getVmVendor(), runtimeBean.getVmName(), runtimeBean.getVmVersion());
   stdout.format("  on %s %s %s\n", "", osBean.getName(), osBean.getVersion(), osBean.getArch());
   try {
     stdout.format(
         "  running as %s on %s\n",
         System.getProperty("user.name"), InetAddress.getLocalHost().getHostName());
   } catch (UnknownHostException e) {
   }
   stdout.format("  cwd  %s\n", path(new File(".").getAbsoluteFile().getParentFile()));
   stdout.format("  site %s\n", path(sitePath));
 }
  /* (non-Javadoc)
   * @see org.epics.pvaccess.server.plugins.BeaconServerStatusProvider#getServerStatusData()
   */
  public PVField getServerStatusData() {

    status
        .getIntField("connections")
        .put(context.getTransportRegistry().numberOfActiveTransports());
    status.getLongField("allocatedMemory").put(Runtime.getRuntime().totalMemory());
    status.getLongField("freeMemory").put(Runtime.getRuntime().freeMemory());

    ThreadMXBean threadMBean = ManagementFactory.getThreadMXBean();
    status.getIntField("threads").put(threadMBean.getThreadCount());

    final long[] deadlocks =
        threadMBean.isSynchronizerUsageSupported()
            ? threadMBean.findDeadlockedThreads()
            : threadMBean.findMonitorDeadlockedThreads();
    status.getIntField("deadlocks").put((deadlocks != null) ? deadlocks.length : 0);

    OperatingSystemMXBean osMBean = ManagementFactory.getOperatingSystemMXBean();
    status.getDoubleField("averageSystemLoad").put(osMBean.getSystemLoadAverage());

    return status;
  }
  @Override
  public Map<String, Metric> getMetrics() {
    final Map<String, Metric> gauges = new HashMap<String, Metric>();

    double loadAverage = mxBean.getSystemLoadAverage();
    if (Double.compare(loadAverage, 0.0d) >= 0) {
      gauges.put(
          "system.load.average",
          new Gauge<Double>() {
            @Override
            public Double getValue() {
              return mxBean.getSystemLoadAverage();
            }
          });
    } else {
      if (logger.isDebugEnabled()) {
        logger.debug("System Load Average is not available as an Operating System Metric");
      }
    }

    Gauge<Long> openFileDescriptorCountGauge = getLongGauge("getOpenFileDescriptorCount");
    if (openFileDescriptorCountGauge != null) {
      gauges.put("file.descriptor.open.count", openFileDescriptorCountGauge);
    }

    Gauge<Long> maxFileDescriptorCountGauge = getLongGauge("getMaxFileDescriptorCount");
    if (maxFileDescriptorCountGauge != null) {
      gauges.put("file.descriptor.max.count", maxFileDescriptorCountGauge);
    }

    Gauge<Double> processCpuLoadGauge = getDoubleGauge("getProcessCpuLoad");
    if (processCpuLoadGauge != null) {
      gauges.put("cpu.load.process", processCpuLoadGauge);
    }

    Gauge<Double> systemCpuLoadGauge = getDoubleGauge("getSystemCpuLoad");
    if (systemCpuLoadGauge != null) {
      gauges.put("cpu.load.system", systemCpuLoadGauge);
    }

    Gauge<Long> freePhysicalMemorySizeGauge = getLongGauge("getFreePhysicalMemorySize");
    if (freePhysicalMemorySizeGauge != null) {
      gauges.put("physical.memory.free.size", freePhysicalMemorySizeGauge);
    }

    Gauge<Long> totalPhysicalMemorySizeGauge = getLongGauge("getTotalPhysicalMemorySize");
    if (totalPhysicalMemorySizeGauge != null) {
      gauges.put("physical.memory.total.size", totalPhysicalMemorySizeGauge);
    }

    Gauge<Long> freeSwapSpaceSizeGauge = getLongGauge("getFreeSwapSpaceSize");
    if (freeSwapSpaceSizeGauge != null) {
      gauges.put("swap.space.free.size", freeSwapSpaceSizeGauge);
    }

    Gauge<Long> totalSwapSpaceSizeGauge = getLongGauge("getTotalSwapSpaceSize");
    if (totalSwapSpaceSizeGauge != null) {
      gauges.put("swap.space.total.size", totalSwapSpaceSizeGauge);
    }

    Gauge<Long> committedVirtualMemorySizeGauge = getLongGauge("getCommittedVirtualMemorySize");
    if (committedVirtualMemorySizeGauge != null) {
      gauges.put("virtual.memory.committed.size", committedVirtualMemorySizeGauge);
    }

    return Collections.unmodifiableMap(gauges);
  }
 // Get the current load on this machine
 private double getLoad() {
   OperatingSystemMXBean mxBean = ManagementFactory.getOperatingSystemMXBean();
   return mxBean.getSystemLoadAverage();
 }
Beispiel #8
0
 /** {@inheritDoc} */
 @Override
 public double getSystemLoadAverage() {
   return OS_MXBEAN.getSystemLoadAverage();
 }
 public static void getData() {
   java.lang.management.OperatingSystemMXBean data =
       java.lang.management.ManagementFactory.getOperatingSystemMXBean();
   d = data.getSystemLoadAverage();
   System.out.println(d);
 }
Beispiel #10
0
  public OptionsPane() {
    this.setBorder(new EmptyBorder(5, 5, 5, 5));
    currentRam = new JLabel();
    currentRam.setBounds(427, 114, 85, 23);
    long ram = 0;
    OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
    Method m;
    try {
      m = operatingSystemMXBean.getClass().getDeclaredMethod("getTotalPhysicalMemorySize");
      m.setAccessible(true);
      Object value = m.invoke(operatingSystemMXBean);
      if (value != null) {
        ram = Long.valueOf(value.toString()) / 1024 / 1024;
      } else {
        Logger.logWarn("Could not get RAM Value");
        ram = 8192;
      }
    } catch (Exception e) {
      Logger.logError(e.getMessage(), e);
    }

    ramMaximum = new JSlider();
    ramMaximum.setBounds(190, 114, 222, 23);
    ramMaximum.setSnapToTicks(true);
    ramMaximum.setMajorTickSpacing(256);
    ramMaximum.setMinorTickSpacing(256);
    ramMaximum.setMinimum(256);
    String vmType = System.getProperty("sun.arch.data.model");
    if (vmType != null) {
      if (vmType.equals("64")) {
        ramMaximum.setMaximum((int) ram);
      } else if (vmType.equals("32")) {
        if (ram < 1024) {
          ramMaximum.setMaximum((int) ram);
        } else {
          ramMaximum.setMaximum(1024);
        }
      }
    }
    int ramMax =
        (Integer.parseInt(Settings.getSettings().getRamMax()) > ramMaximum.getMaximum())
            ? ramMaximum.getMaximum()
            : Integer.parseInt(Settings.getSettings().getRamMax());
    ramMaximum.setValue(ramMax);
    currentRam.setText(getAmount());
    ramMaximum.addChangeListener(
        new ChangeListener() {
          @Override
          public void stateChanged(ChangeEvent arg0) {
            currentRam.setText(getAmount());
          }
        });
    ramMaximum.addFocusListener(settingsChangeListener);

    JButton installBrowseBtn = new JButton("...");
    installBrowseBtn.setBounds(786, 11, 49, 23);
    installBrowseBtn.addActionListener(new ChooseDir(this));
    setLayout(null);
    add(installBrowseBtn);

    lblInstallFolder = new JLabel(I18N.getLocaleString("INSTALL_FOLDER"));
    lblInstallFolder.setBounds(10, 11, 127, 23);
    add(lblInstallFolder);

    installFolderTextField = new JTextField();
    installFolderTextField.setBounds(147, 11, 629, 23);
    installFolderTextField.addFocusListener(settingsChangeListener);
    installFolderTextField.setColumns(10);
    installFolderTextField.setText(Settings.getSettings().getInstallPath());
    add(installFolderTextField);

    tglbtnForceUpdate = new JToggleButton(I18N.getLocaleString("FORCE_UPDATE"));
    tglbtnForceUpdate.setBounds(147, 45, 629, 29);
    tglbtnForceUpdate.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent arg0) {
            tglbtnForceUpdate.setEnabled(false);
            saveSettingsInto(Settings.getSettings());
          }
        });
    tglbtnForceUpdate.getModel().setPressed(Settings.getSettings().getForceUpdate());
    add(tglbtnForceUpdate);

    lblRamMaximum = new JLabel(I18N.getLocaleString("RAM_MAX"));
    lblRamMaximum.setBounds(10, 114, 195, 23);
    add(lblRamMaximum);
    add(ramMaximum);
    add(currentRam);

    ArrayList<String> locales = new ArrayList<String>();
    for (Map.Entry<Integer, String> entry : I18N.localeIndices.entrySet()) {
      Logger.logInfo(
          "[i18n] Added "
              + entry.getKey().toString()
              + " "
              + entry.getValue()
              + " to options pane");
      locales.add(entry.getKey(), I18N.localeFiles.get(entry.getValue()));
    }

    locale = new JComboBox(locales.toArray());
    locale.setBounds(190, 148, 222, 23);
    locale.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            I18N.setLocale(I18N.localeIndices.get(locale.getSelectedIndex()));
            if (LaunchFrame.getInstance() != null) {
              LaunchFrame.getInstance().updateLocale();
            }
          }
        });
    locale.addFocusListener(settingsChangeListener);
    locale.setSelectedItem(I18N.localeFiles.get(Settings.getSettings().getLocale()));

    lblLocale = new JLabel(I18N.getLocaleString("LANGUAGE"));
    lblLocale.setBounds(10, 148, 195, 23);
    add(lblLocale);
    add(locale);

    minecraftSize = new JLabel("Size for Minecraft Window");
    minecraftSize.setBounds(10, 182, 195, 23);
    add(minecraftSize);

    minecraftX = new JTextField();
    minecraftX.setBounds(190, 182, 85, 22);
    minecraftX.setDocument(new documentFilter("\\D++"));
    minecraftX.setText(Settings.getSettings().getMinecraftX());
    minecraftX.addFocusListener(settingsChangeListener);
    add(minecraftX);

    lblX = new JLabel("x");
    lblX.setBounds(297, 182, 6, 20);
    add(lblX);

    minecraftY = new JTextField();
    minecraftY.setBounds(327, 182, 85, 23);
    minecraftY.setDocument(new documentFilter("\\D++"));
    minecraftY.setText(Settings.getSettings().getMinecraftY());
    minecraftY.addFocusListener(settingsChangeListener);
    add(minecraftY);
    minecraftY.setColumns(5);

    JLabel minecraftPos = new JLabel("Position of Minecraft Window");
    minecraftPos.setBounds(10, 216, 195, 23);
    add(minecraftPos);

    xPosField = new JTextField();
    xPosField.setBounds(190, 217, 85, 22);
    xPosField.setDocument(new documentFilter("\\D++"));
    xPosField.setText(Settings.getSettings().getMinecraftXPos());
    xPosField.addFocusListener(settingsChangeListener);
    add(xPosField);
    xPosField.setColumns(10);

    JLabel lblX_1 = new JLabel("x");
    lblX_1.setBounds(297, 216, 6, 23);
    add(lblX_1);

    yPosField = new JTextField();
    yPosField.setBounds(327, 216, 85, 23);
    yPosField.setDocument(new documentFilter("\\D++"));
    yPosField.setText(Settings.getSettings().getMinecraftYPos());
    yPosField.addFocusListener(settingsChangeListener);
    add(yPosField);
    yPosField.setColumns(10);

    tglbtnCenterScreen = new JToggleButton("Center Window on Screen");
    tglbtnCenterScreen.setBounds(190, 252, 222, 23);
    tglbtnCenterScreen.setSelected(Boolean.parseBoolean(Settings.getSettings().getCenterWindow()));
    tglbtnCenterScreen.addFocusListener(settingsChangeListener);
    add(tglbtnCenterScreen);

    downloadServers = new JComboBox(getDownloadServerNames());
    downloadServers.setBounds(613, 115, 222, 23);
    downloadServers.addFocusListener(settingsChangeListener);
    if (DownloadUtils.serversLoaded) {
      if (DownloadUtils.downloadServers.containsKey(Settings.getSettings().getDownloadServer())) {
        downloadServers.setSelectedItem(Settings.getSettings().getDownloadServer());
      }
    }
    add(downloadServers);

    JLabel downloadLocation = new JLabel("Download Location");
    downloadLocation.setBounds(490, 118, 110, 14);
    add(downloadLocation);

    chckbxShowConsole = new JCheckBox("Show Console?");
    chckbxShowConsole.addFocusListener(settingsChangeListener);
    chckbxShowConsole.setSelected(Boolean.parseBoolean(Settings.getSettings().getConsoleActive()));
    chckbxShowConsole.setBounds(613, 148, 183, 23);
    add(chckbxShowConsole);

    autoMaxCheck = new JCheckBox("Automatically Maximize?");
    autoMaxCheck.addFocusListener(settingsChangeListener);
    autoMaxCheck.setSelected(Boolean.parseBoolean(Settings.getSettings().getAutoMaximize()));
    autoMaxCheck.setBounds(613, 184, 183, 23);
    add(autoMaxCheck);

    JLabel javaLocLabel = new JLabel("Java Location");
    javaLocLabel.setBounds(490, 220, 110, 14);
    add(javaLocLabel);

    javaInstallDir = new JTextField();
    javaInstallDir.setEditable(false);
    String javaInstall = Settings.getSettings().getJavaInstall();
    javaInstallDir.setText(javaInstall);
    javaInstallDir.setToolTipText(javaInstall);
    javaInstallDir.setBounds(613, 220, 230, 23);
    add(javaInstallDir);

    JButton dirChooserButton = new JButton("Change");
    dirChooserButton.setBounds(763, 240, 80, 23);
    dirChooserButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser(Settings.getSettings().getJavaInstall());
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int option = chooser.showOpenDialog(OptionsPane.this);
            if (JFileChooser.APPROVE_OPTION == option) {
              File selectedDir = chooser.getSelectedFile();
              String javaExecutableName = "java";
              if (OS.WINDOWS.equals(OSUtils.getCurrentOS())) {
                javaExecutableName += ".exe";
              }
              File javaExecutable =
                  new File(
                      selectedDir
                          + System.getProperty("file.separator")
                          + "bin"
                          + System.getProperty("file.separator")
                          + javaExecutableName);
              if (javaExecutable.exists()) {
                javaInstallDir.setText(selectedDir.getAbsolutePath());
                saveSettingsInto(Settings.getSettings());
              } else {
                JOptionPane.showMessageDialog(
                    OptionsPane.this,
                    "The selected directoy is not a proper Java installation.",
                    "Error",
                    JOptionPane.ERROR_MESSAGE);
              }
            }
          }
        });
    add(dirChooserButton);
  }
Beispiel #11
0
  synchronized Result formatSummary() {
    Result result = new Result();
    ProxyClient proxyClient = vmPanel.getProxyClient();
    if (proxyClient.isDead()) {
      return null;
    }

    buf = new StringBuilder();
    append("<table cellpadding=1>");

    try {
      RuntimeMXBean rmBean = proxyClient.getRuntimeMXBean();
      CompilationMXBean cmpMBean = proxyClient.getCompilationMXBean();
      ThreadMXBean tmBean = proxyClient.getThreadMXBean();
      MemoryMXBean memoryBean = proxyClient.getMemoryMXBean();
      ClassLoadingMXBean clMBean = proxyClient.getClassLoadingMXBean();
      OperatingSystemMXBean osMBean = proxyClient.getOperatingSystemMXBean();
      com.sun.management.OperatingSystemMXBean sunOSMBean =
          proxyClient.getSunOperatingSystemMXBean();

      append("<tr><td colspan=4>");
      append("<center><b>" + Messages.SUMMARY_TAB_TAB_NAME + "</b></center>");
      String dateTime = headerDateTimeFormat.format(System.currentTimeMillis());
      append("<center>" + dateTime + "</center>");

      append(newDivider);

      { // VM info
        append(newLeftTable);
        append(Messages.CONNECTION_NAME, vmPanel.getDisplayName());
        append(
            Messages.VIRTUAL_MACHINE,
            Resources.format(
                Messages.SUMMARY_TAB_VM_VERSION, rmBean.getVmName(), rmBean.getVmVersion()));
        append(Messages.VENDOR, rmBean.getVmVendor());
        append(Messages.NAME, rmBean.getName());
        append(endTable);

        append(newRightTable);
        result.upTime = rmBean.getUptime();
        append(Messages.UPTIME, formatTime(result.upTime));
        if (sunOSMBean != null) {
          result.processCpuTime = sunOSMBean.getProcessCpuTime();
          append(Messages.PROCESS_CPU_TIME, formatNanoTime(result.processCpuTime));
        }

        if (cmpMBean != null) {
          append(Messages.JIT_COMPILER, cmpMBean.getName());
          append(
              Messages.TOTAL_COMPILE_TIME,
              cmpMBean.isCompilationTimeMonitoringSupported()
                  ? formatTime(cmpMBean.getTotalCompilationTime())
                  : Messages.UNAVAILABLE);
        } else {
          append(Messages.JIT_COMPILER, Messages.UNAVAILABLE);
        }
        append(endTable);
      }

      append(newDivider);

      { // Threads and Classes
        append(newLeftTable);
        int tlCount = tmBean.getThreadCount();
        int tdCount = tmBean.getDaemonThreadCount();
        int tpCount = tmBean.getPeakThreadCount();
        long ttCount = tmBean.getTotalStartedThreadCount();
        String[] strings1 =
            formatLongs(
                tlCount, tpCount,
                tdCount, ttCount);
        append(Messages.LIVE_THREADS, strings1[0]);
        append(Messages.PEAK, strings1[1]);
        append(Messages.DAEMON_THREADS, strings1[2]);
        append(Messages.TOTAL_THREADS_STARTED, strings1[3]);
        append(endTable);

        append(newRightTable);
        long clCount = clMBean.getLoadedClassCount();
        long cuCount = clMBean.getUnloadedClassCount();
        long ctCount = clMBean.getTotalLoadedClassCount();
        String[] strings2 = formatLongs(clCount, cuCount, ctCount);
        append(Messages.CURRENT_CLASSES_LOADED, strings2[0]);
        append(Messages.TOTAL_CLASSES_LOADED, strings2[2]);
        append(Messages.TOTAL_CLASSES_UNLOADED, strings2[1]);
        append(null, "");
        append(endTable);
      }

      append(newDivider);

      { // Memory
        MemoryUsage u = memoryBean.getHeapMemoryUsage();

        append(newLeftTable);
        String[] strings1 = formatKByteStrings(u.getUsed(), u.getMax());
        append(Messages.CURRENT_HEAP_SIZE, strings1[0]);
        append(Messages.MAXIMUM_HEAP_SIZE, strings1[1]);
        append(endTable);

        append(newRightTable);
        String[] strings2 = formatKByteStrings(u.getCommitted());
        append(Messages.COMMITTED_MEMORY, strings2[0]);
        append(
            Messages.SUMMARY_TAB_PENDING_FINALIZATION_LABEL,
            Messages.SUMMARY_TAB_PENDING_FINALIZATION_VALUE,
            memoryBean.getObjectPendingFinalizationCount());
        append(endTable);

        append(newTable);
        Collection<GarbageCollectorMXBean> garbageCollectors =
            proxyClient.getGarbageCollectorMXBeans();
        for (GarbageCollectorMXBean garbageCollectorMBean : garbageCollectors) {
          String gcName = garbageCollectorMBean.getName();
          long gcCount = garbageCollectorMBean.getCollectionCount();
          long gcTime = garbageCollectorMBean.getCollectionTime();

          append(
              Messages.GARBAGE_COLLECTOR,
              Resources.format(
                  Messages.GC_INFO,
                  gcName,
                  gcCount,
                  (gcTime >= 0) ? formatTime(gcTime) : Messages.UNAVAILABLE),
              4);
        }
        append(endTable);
      }

      append(newDivider);

      { // Operating System info
        append(newLeftTable);
        String osName = osMBean.getName();
        String osVersion = osMBean.getVersion();
        String osArch = osMBean.getArch();
        result.nCPUs = osMBean.getAvailableProcessors();
        append(Messages.OPERATING_SYSTEM, osName + " " + osVersion);
        append(Messages.ARCHITECTURE, osArch);
        append(Messages.NUMBER_OF_PROCESSORS, result.nCPUs + "");

        if (pathSeparator == null) {
          // Must use separator of remote OS, not File.pathSeparator
          // from this local VM. In the future, consider using
          // RuntimeMXBean to get the remote system property.
          pathSeparator = osName.startsWith("Windows ") ? ";" : ":";
        }

        if (sunOSMBean != null) {
          String[] kbStrings1 = formatKByteStrings(sunOSMBean.getCommittedVirtualMemorySize());

          String[] kbStrings2 =
              formatKByteStrings(
                  sunOSMBean.getTotalPhysicalMemorySize(),
                  sunOSMBean.getFreePhysicalMemorySize(),
                  sunOSMBean.getTotalSwapSpaceSize(),
                  sunOSMBean.getFreeSwapSpaceSize());

          append(Messages.COMMITTED_VIRTUAL_MEMORY, kbStrings1[0]);
          append(endTable);

          append(newRightTable);
          append(Messages.TOTAL_PHYSICAL_MEMORY, kbStrings2[0]);
          append(Messages.FREE_PHYSICAL_MEMORY, kbStrings2[1]);
          append(Messages.TOTAL_SWAP_SPACE, kbStrings2[2]);
          append(Messages.FREE_SWAP_SPACE, kbStrings2[3]);
        }

        append(endTable);
      }

      append(newDivider);

      { // VM arguments and paths
        append(newTable);
        String args = "";
        java.util.List<String> inputArguments = rmBean.getInputArguments();
        for (String arg : inputArguments) {
          args += arg + " ";
        }
        append(Messages.VM_ARGUMENTS, args, 4);
        append(Messages.CLASS_PATH, rmBean.getClassPath(), 4);
        append(Messages.LIBRARY_PATH, rmBean.getLibraryPath(), 4);
        append(
            Messages.BOOT_CLASS_PATH,
            rmBean.isBootClassPathSupported() ? rmBean.getBootClassPath() : Messages.UNAVAILABLE,
            4);
        append(endTable);
      }
    } catch (IOException e) {
      if (JConsole.isDebug()) {
        e.printStackTrace();
      }
      proxyClient.markAsDead();
      return null;
    } catch (UndeclaredThrowableException e) {
      if (JConsole.isDebug()) {
        e.printStackTrace();
      }
      proxyClient.markAsDead();
      return null;
    }

    append("</table>");

    result.timeStamp = System.currentTimeMillis();
    result.summary = buf.toString();

    return result;
  }
Beispiel #12
0
  /**
   * Retrieve a JVM information text formatted using the given StringManager.
   *
   * @param requestedSm the StringManager to use
   * @return the formatted JVM information text
   */
  private static String getVMInfo(StringManager requestedSm) {
    StringBuilder sb = new StringBuilder();

    synchronized (timeformat) {
      sb.append(timeformat.format(new Date()));
    }
    sb.append(CRLF);

    sb.append(requestedSm.getString("diagnostics.vmInfoRuntime"));
    sb.append(":" + CRLF);
    sb.append(INDENT1 + "vmName: " + runtimeMXBean.getVmName() + CRLF);
    sb.append(INDENT1 + "vmVersion: " + runtimeMXBean.getVmVersion() + CRLF);
    sb.append(INDENT1 + "vmVendor: " + runtimeMXBean.getVmVendor() + CRLF);
    sb.append(INDENT1 + "specName: " + runtimeMXBean.getSpecName() + CRLF);
    sb.append(INDENT1 + "specVersion: " + runtimeMXBean.getSpecVersion() + CRLF);
    sb.append(INDENT1 + "specVendor: " + runtimeMXBean.getSpecVendor() + CRLF);
    sb.append(
        INDENT1 + "managementSpecVersion: " + runtimeMXBean.getManagementSpecVersion() + CRLF);
    sb.append(INDENT1 + "name: " + runtimeMXBean.getName() + CRLF);
    sb.append(INDENT1 + "startTime: " + runtimeMXBean.getStartTime() + CRLF);
    sb.append(INDENT1 + "uptime: " + runtimeMXBean.getUptime() + CRLF);
    sb.append(
        INDENT1 + "isBootClassPathSupported: " + runtimeMXBean.isBootClassPathSupported() + CRLF);
    sb.append(CRLF);

    sb.append(requestedSm.getString("diagnostics.vmInfoOs"));
    sb.append(":" + CRLF);
    sb.append(INDENT1 + "name: " + operatingSystemMXBean.getName() + CRLF);
    sb.append(INDENT1 + "version: " + operatingSystemMXBean.getVersion() + CRLF);
    sb.append(INDENT1 + "architecture: " + operatingSystemMXBean.getArch() + CRLF);
    sb.append(
        INDENT1 + "availableProcessors: " + operatingSystemMXBean.getAvailableProcessors() + CRLF);
    sb.append(
        INDENT1 + "systemLoadAverage: " + operatingSystemMXBean.getSystemLoadAverage() + CRLF);
    sb.append(CRLF);

    sb.append(requestedSm.getString("diagnostics.vmInfoThreadMxBean"));
    sb.append(":" + CRLF);
    sb.append(
        INDENT1
            + "isCurrentThreadCpuTimeSupported: "
            + threadMXBean.isCurrentThreadCpuTimeSupported()
            + CRLF);
    sb.append(
        INDENT1 + "isThreadCpuTimeSupported: " + threadMXBean.isThreadCpuTimeSupported() + CRLF);
    sb.append(INDENT1 + "isThreadCpuTimeEnabled: " + threadMXBean.isThreadCpuTimeEnabled() + CRLF);
    sb.append(
        INDENT1
            + "isObjectMonitorUsageSupported: "
            + threadMXBean.isObjectMonitorUsageSupported()
            + CRLF);
    sb.append(
        INDENT1
            + "isSynchronizerUsageSupported: "
            + threadMXBean.isSynchronizerUsageSupported()
            + CRLF);
    sb.append(
        INDENT1
            + "isThreadContentionMonitoringSupported: "
            + threadMXBean.isThreadContentionMonitoringSupported()
            + CRLF);
    sb.append(
        INDENT1
            + "isThreadContentionMonitoringEnabled: "
            + threadMXBean.isThreadContentionMonitoringEnabled()
            + CRLF);
    sb.append(CRLF);

    sb.append(requestedSm.getString("diagnostics.vmInfoThreadCounts"));
    sb.append(":" + CRLF);
    sb.append(INDENT1 + "daemon: " + threadMXBean.getDaemonThreadCount() + CRLF);
    sb.append(INDENT1 + "total: " + threadMXBean.getThreadCount() + CRLF);
    sb.append(INDENT1 + "peak: " + threadMXBean.getPeakThreadCount() + CRLF);
    sb.append(INDENT1 + "totalStarted: " + threadMXBean.getTotalStartedThreadCount() + CRLF);
    sb.append(CRLF);

    sb.append(requestedSm.getString("diagnostics.vmInfoStartup"));
    sb.append(":" + CRLF);
    for (String arg : runtimeMXBean.getInputArguments()) {
      sb.append(INDENT1 + arg + CRLF);
    }
    sb.append(CRLF);

    sb.append(requestedSm.getString("diagnostics.vmInfoPath"));
    sb.append(":" + CRLF);
    sb.append(INDENT1 + "bootClassPath: " + runtimeMXBean.getBootClassPath() + CRLF);
    sb.append(INDENT1 + "classPath: " + runtimeMXBean.getClassPath() + CRLF);
    sb.append(INDENT1 + "libraryPath: " + runtimeMXBean.getLibraryPath() + CRLF);
    sb.append(CRLF);

    sb.append(requestedSm.getString("diagnostics.vmInfoClassLoading"));
    sb.append(":" + CRLF);
    sb.append(INDENT1 + "loaded: " + classLoadingMXBean.getLoadedClassCount() + CRLF);
    sb.append(INDENT1 + "unloaded: " + classLoadingMXBean.getUnloadedClassCount() + CRLF);
    sb.append(INDENT1 + "totalLoaded: " + classLoadingMXBean.getTotalLoadedClassCount() + CRLF);
    sb.append(INDENT1 + "isVerbose: " + classLoadingMXBean.isVerbose() + CRLF);
    sb.append(CRLF);

    sb.append(requestedSm.getString("diagnostics.vmInfoClassCompilation"));
    sb.append(":" + CRLF);
    sb.append(INDENT1 + "name: " + compilationMXBean.getName() + CRLF);
    sb.append(
        INDENT1 + "totalCompilationTime: " + compilationMXBean.getTotalCompilationTime() + CRLF);
    sb.append(
        INDENT1
            + "isCompilationTimeMonitoringSupported: "
            + compilationMXBean.isCompilationTimeMonitoringSupported()
            + CRLF);
    sb.append(CRLF);

    for (MemoryManagerMXBean mbean : memoryManagerMXBeans) {
      sb.append(requestedSm.getString("diagnostics.vmInfoMemoryManagers", mbean.getName()));
      sb.append(":" + CRLF);
      sb.append(INDENT1 + "isValid: " + mbean.isValid() + CRLF);
      sb.append(INDENT1 + "mbean.getMemoryPoolNames: " + CRLF);
      String[] names = mbean.getMemoryPoolNames();
      Arrays.sort(names);
      for (String name : names) {
        sb.append(INDENT2 + name + CRLF);
      }
      sb.append(CRLF);
    }

    for (GarbageCollectorMXBean mbean : garbageCollectorMXBeans) {
      sb.append(requestedSm.getString("diagnostics.vmInfoGarbageCollectors", mbean.getName()));
      sb.append(":" + CRLF);
      sb.append(INDENT1 + "isValid: " + mbean.isValid() + CRLF);
      sb.append(INDENT1 + "mbean.getMemoryPoolNames: " + CRLF);
      String[] names = mbean.getMemoryPoolNames();
      Arrays.sort(names);
      for (String name : names) {
        sb.append(INDENT2 + name + CRLF);
      }
      sb.append(INDENT1 + "getCollectionCount: " + mbean.getCollectionCount() + CRLF);
      sb.append(INDENT1 + "getCollectionTime: " + mbean.getCollectionTime() + CRLF);
      sb.append(CRLF);
    }

    sb.append(requestedSm.getString("diagnostics.vmInfoMemory"));
    sb.append(":" + CRLF);
    sb.append(INDENT1 + "isVerbose: " + memoryMXBean.isVerbose() + CRLF);
    sb.append(
        INDENT1
            + "getObjectPendingFinalizationCount: "
            + memoryMXBean.getObjectPendingFinalizationCount()
            + CRLF);
    sb.append(formatMemoryUsage("heap", memoryMXBean.getHeapMemoryUsage()));
    sb.append(formatMemoryUsage("non-heap", memoryMXBean.getNonHeapMemoryUsage()));
    sb.append(CRLF);

    for (MemoryPoolMXBean mbean : memoryPoolMXBeans) {
      sb.append(requestedSm.getString("diagnostics.vmInfoMemoryPools", mbean.getName()));
      sb.append(":" + CRLF);
      sb.append(INDENT1 + "isValid: " + mbean.isValid() + CRLF);
      sb.append(INDENT1 + "getType: " + mbean.getType() + CRLF);
      sb.append(INDENT1 + "mbean.getMemoryManagerNames: " + CRLF);
      String[] names = mbean.getMemoryManagerNames();
      Arrays.sort(names);
      for (String name : names) {
        sb.append(INDENT2 + name + CRLF);
      }
      sb.append(INDENT1 + "isUsageThresholdSupported: " + mbean.isUsageThresholdSupported() + CRLF);
      try {
        sb.append(INDENT1 + "isUsageThresholdExceeded: " + mbean.isUsageThresholdExceeded() + CRLF);
      } catch (UnsupportedOperationException ex) {
        // IGNORE
      }
      sb.append(
          INDENT1
              + "isCollectionUsageThresholdSupported: "
              + mbean.isCollectionUsageThresholdSupported()
              + CRLF);
      try {
        sb.append(
            INDENT1
                + "isCollectionUsageThresholdExceeded: "
                + mbean.isCollectionUsageThresholdExceeded()
                + CRLF);
      } catch (UnsupportedOperationException ex) {
        // IGNORE
      }
      try {
        sb.append(INDENT1 + "getUsageThreshold: " + mbean.getUsageThreshold() + CRLF);
      } catch (UnsupportedOperationException ex) {
        // IGNORE
      }
      try {
        sb.append(INDENT1 + "getUsageThresholdCount: " + mbean.getUsageThresholdCount() + CRLF);
      } catch (UnsupportedOperationException ex) {
        // IGNORE
      }
      try {
        sb.append(
            INDENT1 + "getCollectionUsageThreshold: " + mbean.getCollectionUsageThreshold() + CRLF);
      } catch (UnsupportedOperationException ex) {
        // IGNORE
      }
      try {
        sb.append(
            INDENT1
                + "getCollectionUsageThresholdCount: "
                + mbean.getCollectionUsageThresholdCount()
                + CRLF);
      } catch (UnsupportedOperationException ex) {
        // IGNORE
      }
      sb.append(formatMemoryUsage("current", mbean.getUsage()));
      sb.append(formatMemoryUsage("collection", mbean.getCollectionUsage()));
      sb.append(formatMemoryUsage("peak", mbean.getPeakUsage()));
      sb.append(CRLF);
    }

    sb.append(requestedSm.getString("diagnostics.vmInfoSystem"));
    sb.append(":" + CRLF);
    Map<String, String> props = runtimeMXBean.getSystemProperties();
    ArrayList<String> keys = new ArrayList<String>(props.keySet());
    Collections.sort(keys);
    for (String prop : keys) {
      sb.append(INDENT1 + prop + ": " + props.get(prop) + CRLF);
    }
    sb.append(CRLF);

    sb.append(requestedSm.getString("diagnostics.vmInfoLogger"));
    sb.append(":" + CRLF);
    List<String> loggers = loggingMXBean.getLoggerNames();
    Collections.sort(loggers);
    for (String logger : loggers) {
      sb.append(
          INDENT1
              + logger
              + ": level="
              + loggingMXBean.getLoggerLevel(logger)
              + ", parent="
              + loggingMXBean.getParentLoggerName(logger)
              + CRLF);
    }
    sb.append(CRLF);

    return sb.toString();
  }