List of usage examples for java.lang.management RuntimeMXBean getClassPath
public String getClassPath();
From source file:Main.java
public static void main(String args[]) throws Exception { RuntimeMXBean mx = ManagementFactory.getRuntimeMXBean(); System.out.println(mx.getClassPath()); }
From source file:Main.java
public static void main(String args[]) throws Exception { RuntimeMXBean mx = ManagementFactory.getRuntimeMXBean(); System.out.println(mx.getBootClassPath()); System.out.println(mx.getClassPath()); System.out.println(mx.getInputArguments()); System.out.println(mx.getSystemProperties()); System.out.println(new Date(mx.getStartTime())); System.out.println(mx.getUptime() + " ms"); }
From source file:com.searchbox.framework.web.SystemController.java
@ModelAttribute("jvmInfo") public static Map<String, Object> getJvmInfo() { Map<String, Object> jvm = new HashMap<String, Object>(); final String javaVersion = System.getProperty("java.specification.version", "unknown"); final String javaVendor = System.getProperty("java.specification.vendor", "unknown"); final String javaName = System.getProperty("java.specification.name", "unknown"); final String jreVersion = System.getProperty("java.version", "unknown"); final String jreVendor = System.getProperty("java.vendor", "unknown"); final String vmVersion = System.getProperty("java.vm.version", "unknown"); final String vmVendor = System.getProperty("java.vm.vendor", "unknown"); final String vmName = System.getProperty("java.vm.name", "unknown"); // Summary Info jvm.put("version", jreVersion + " " + vmVersion); jvm.put("name", jreVendor + " " + vmName); // details//from w ww.ja v a2s . c o m Map<String, Object> java = new HashMap<String, Object>(); java.put("vendor", javaVendor); java.put("name", javaName); java.put("version", javaVersion); jvm.put("spec", java); Map<String, Object> jre = new HashMap<String, Object>(); jre.put("vendor", jreVendor); jre.put("version", jreVersion); jvm.put("jre", jre); Map<String, Object> vm = new HashMap<String, Object>(); vm.put("vendor", vmVendor); vm.put("name", vmName); vm.put("version", vmVersion); jvm.put("vm", vm); Runtime runtime = Runtime.getRuntime(); jvm.put("processors", runtime.availableProcessors()); // not thread safe, but could be thread local DecimalFormat df = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.ROOT)); Map<String, Object> mem = new HashMap<String, Object>(); Map<String, Object> raw = new HashMap<String, Object>(); long free = runtime.freeMemory(); long max = runtime.maxMemory(); long total = runtime.totalMemory(); long used = total - free; double percentUsed = ((double) (used) / (double) max) * 100; raw.put("free", free); mem.put("free", humanReadableUnits(free, df)); raw.put("total", total); mem.put("total", humanReadableUnits(total, df)); raw.put("max", max); mem.put("max", humanReadableUnits(max, df)); raw.put("used", used); mem.put("used", humanReadableUnits(used, df) + " (%" + df.format(percentUsed) + ")"); raw.put("used%", percentUsed); mem.put("raw", raw); jvm.put("memory", mem); // JMX properties -- probably should be moved to a different handler Map<String, Object> jmx = new HashMap<String, Object>(); try { RuntimeMXBean mx = ManagementFactory.getRuntimeMXBean(); jmx.put("bootclasspath", mx.getBootClassPath()); jmx.put("classpath", mx.getClassPath()); // the input arguments passed to the Java virtual machine // which does not include the arguments to the main method. jmx.put("commandLineArgs", mx.getInputArguments()); jmx.put("startTime", new Date(mx.getStartTime())); jmx.put("upTimeMS", mx.getUptime()); } catch (Exception e) { LOGGER.warn("Error getting JMX properties", e); } jvm.put("jmx", jmx); return jvm; }
From source file:net.risesoft.soa.asf.web.controller.SystemController.java
private List<SysInfo> getVMInfo() { List list = new ArrayList(); String group = "3. VM ?"; RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean(); list.add(new SysInfo("BootClassPath", rt.getBootClassPath(), group)); list.add(new SysInfo("ClassPath", rt.getClassPath(), group)); list.add(new SysInfo("LibraryPath", rt.getLibraryPath(), group)); list.add(new SysInfo("ManagementSpecVersion", rt.getManagementSpecVersion(), group)); list.add(new SysInfo("Name", rt.getName(), group)); list.add(new SysInfo("SpecName", rt.getSpecName(), group)); list.add(new SysInfo("SpecVendor", rt.getSpecVendor(), group)); list.add(new SysInfo("SpecVersion", rt.getSpecVersion(), group)); list.add(new SysInfo("VmName", rt.getVmName(), group)); list.add(new SysInfo("VmVendor", rt.getVmVendor(), group)); list.add(new SysInfo("VmVersion", rt.getVmVersion(), group)); list.add(new SysInfo("StartTime", DateFormat.getDateTimeInstance().format(new Date(rt.getStartTime())), group));/*from w w w. j a va2 s .c om*/ list.add(new SysInfo("UpTime", this.helper.getUpTimeStr(rt.getUptime()), group)); list.add(new SysInfo("InputArguments", rt.getInputArguments(), group)); group = "6. ?"; Map<String, String> sysProps = rt.getSystemProperties(); for (Map.Entry entry : sysProps.entrySet()) { list.add(new SysInfo((String) entry.getKey(), entry.getValue(), group)); } Collections.sort(list, new Comparator() { public int compare(SystemController.SysInfo o1, SystemController.SysInfo o2) { String key1 = o1.getKey(); String key2 = o2.getKey(); return key1.compareToIgnoreCase(key2); } }); return list; }
From source file:de.unisb.cs.st.javalanche.mutation.runtime.jmx.MutationMxClient.java
public static boolean connect(int i) { JMXConnector jmxc = null;//from w w w . j a v a 2 s. co m JMXServiceURL url = null; try { url = new JMXServiceURL(MXBeanRegisterer.ADDRESS + i); jmxc = JMXConnectorFactory.connect(url, null); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { return false; // System.out.println("Could not connect to address: " + url); // e.printStackTrace(); } if (jmxc != null) { try { MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); ObjectName objectName = new ObjectName(MXBeanRegisterer.OBJECT_NAME); Object numberOfMutations = mbsc.getAttribute(objectName, "NumberOfMutations"); Object currentTest = mbsc.getAttribute(objectName, "CurrentTest"); Object currentMutation = mbsc.getAttribute(objectName, "CurrentMutation"); Object allMutations = mbsc.getAttribute(objectName, "Mutations"); Object mutationsDuration = mbsc.getAttribute(objectName, "MutationDuration"); Object testDuration = mbsc.getAttribute(objectName, "TestDuration"); // Object mutationSummary = mbsc.getAttribute(objectName, // "MutationSummary"); final RuntimeMXBean remoteRuntime = ManagementFactory.newPlatformMXBeanProxy(mbsc, ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class); final MemoryMXBean remoteMemory = ManagementFactory.newPlatformMXBeanProxy(mbsc, ManagementFactory.MEMORY_MXBEAN_NAME, MemoryMXBean.class); System.out.print("Connection: " + i + " "); System.out.println("Target VM: " + remoteRuntime.getName() + " - " + remoteRuntime.getVmVendor() + " - " + remoteRuntime.getSpecVersion() + " - " + remoteRuntime.getVmVersion()); System.out.println( "Running for: " + DurationFormatUtils.formatDurationHMS(remoteRuntime.getUptime())); System.out .println("Memory usage: Heap - " + formatMemory(remoteMemory.getHeapMemoryUsage().getUsed()) + " Non Heap - " + formatMemory(remoteMemory.getNonHeapMemoryUsage().getUsed())); String mutationDurationFormatted = DurationFormatUtils .formatDurationHMS(Long.parseLong(mutationsDuration.toString())); String testDurationFormatted = DurationFormatUtils .formatDurationHMS(Long.parseLong(testDuration.toString())); if (DEBUG_ADD) { System.out.println("Classpath: " + remoteRuntime.getClassPath()); System.out.println("Args: " + remoteRuntime.getInputArguments()); System.out.println("All Mutations: " + allMutations); } // System.out.println(mutationSummary); System.out.println( "Current mutation (Running for: " + mutationDurationFormatted + "): " + currentMutation); System.out.println("Mutations tested: " + numberOfMutations); System.out.println("Current test: (Running for: " + testDurationFormatted + "): " + currentTest); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (MalformedObjectNameException e) { e.printStackTrace(); } catch (NullPointerException e) { e.printStackTrace(); } catch (AttributeNotFoundException e) { e.printStackTrace(); } catch (InstanceNotFoundException e) { e.printStackTrace(); } catch (MBeanException e) { e.printStackTrace(); } catch (ReflectionException e) { e.printStackTrace(); } finally { try { jmxc.close(); } catch (IOException e) { e.printStackTrace(); } } } return true; }
From source file:com.thoughtworks.go.server.service.support.ServerRuntimeInformationProvider.java
private void runtimeInfo(RuntimeMXBean runtimeMXBean, InformationStringBuilder builder) { builder.addSection("Runtime information"); builder.append(String.format("Name - %s\n", runtimeMXBean.getName())); long uptime = runtimeMXBean.getUptime(); long uptimeInSeconds = uptime / 1000; long numberOfHours = uptimeInSeconds / (60 * 60); long numberOfMinutes = (uptimeInSeconds / 60) - (numberOfHours * 60); long numberOfSeconds = uptimeInSeconds % 60; builder.append(String.format("Uptime - %s [About %s hours, %s minutes, %s seconds]\n", uptime, numberOfHours, numberOfMinutes, numberOfSeconds)); builder.append(String.format("Spec Name - %s\n", runtimeMXBean.getSpecName())); builder.append(String.format("Spec Vendor - %s\n", runtimeMXBean.getSpecVendor())); builder.append(String.format("Spec Version - %s\n", runtimeMXBean.getSpecVersion())); builder.addSubSection("Input Arguments") .append(asIndentedMultilineValues(runtimeMXBean.getInputArguments())); builder.addSubSection("System Properties") .append(asIndentedMultilineValues(runtimeMXBean.getSystemProperties())); builder.addSubSection("Classpath").append(prettyClassPath(runtimeMXBean.getClassPath())); builder.addSubSection("Boot Classpath").append(prettyClassPath(runtimeMXBean.getBootClassPath())); }
From source file:org.apache.solr.handler.admin.SystemInfoHandler.java
/** * Get JVM Info - including memory info/*from www . j av a2s. co m*/ */ public static SimpleOrderedMap<Object> getJvmInfo() { SimpleOrderedMap<Object> jvm = new SimpleOrderedMap<Object>(); jvm.add("version", System.getProperty("java.vm.version")); jvm.add("name", System.getProperty("java.vm.name")); Runtime runtime = Runtime.getRuntime(); jvm.add("processors", runtime.availableProcessors()); long used = runtime.totalMemory() - runtime.freeMemory(); // not thread safe, but could be thread local DecimalFormat df = new DecimalFormat("#.#"); double percentUsed = ((double) (used) / (double) runtime.maxMemory()) * 100; SimpleOrderedMap<Object> mem = new SimpleOrderedMap<Object>(); mem.add("free", humanReadableUnits(runtime.freeMemory(), df)); mem.add("total", humanReadableUnits(runtime.totalMemory(), df)); mem.add("max", humanReadableUnits(runtime.maxMemory(), df)); mem.add("used", humanReadableUnits(used, df) + " (%" + df.format(percentUsed) + ")"); jvm.add("memory", mem); // JMX properties -- probably should be moved to a different handler SimpleOrderedMap<Object> jmx = new SimpleOrderedMap<Object>(); try { RuntimeMXBean mx = ManagementFactory.getRuntimeMXBean(); jmx.add("bootclasspath", mx.getBootClassPath()); jmx.add("classpath", mx.getClassPath()); // the input arguments passed to the Java virtual machine // which does not include the arguments to the main method. jmx.add("commandLineArgs", mx.getInputArguments()); // a map of names and values of all system properties. //jmx.add( "SYSTEM PROPERTIES", mx.getSystemProperties()); jmx.add("startTime", new Date(mx.getStartTime())); jmx.add("upTimeMS", mx.getUptime()); } catch (Exception e) { log.warn("Error getting JMX properties", e); } jvm.add("jmx", jmx); return jvm; }
From source file:org.jwebsocket.plugins.system.SystemPlugIn.java
private void getJVMInfo(WebSocketConnector aConnector, Token aToken) { // check if user is allowed to run 'getjvminfo' command if (!hasAuthority(aConnector, NS_SYSTEM + ".getjvminfo")) { sendToken(aConnector, aConnector, createAccessDenied(aToken)); return;/*from w w w . jav a 2 s . c o m*/ } Token lResponse = createResponse(aToken); RuntimeMXBean lBean = ManagementFactory.getRuntimeMXBean(); MemoryMXBean lMemory = ManagementFactory.getMemoryMXBean(); OperatingSystemMXBean lOS = ManagementFactory.getOperatingSystemMXBean(); lResponse.setMap("data", new MapAppender().append("inputArguments", lBean.getInputArguments()) .append("libraryPath", lBean.getLibraryPath()) .append("managementSpecVersion", lBean.getManagementSpecVersion()).append("name", lBean.getName()) .append("specName", lBean.getSpecName()).append("specVendor", lBean.getSpecVendor()) .append("specVersion", lBean.getSpecVersion()).append("startTime", lBean.getStartTime()) .append("systemProperties", lBean.getSystemProperties()).append("uptime", lBean.getUptime()) .append("vmName", lBean.getVmName()).append("vmVendor", lBean.getVmVendor()) .append("vmVersion", lBean.getVmVersion()).append("classPath", lBean.getClassPath()) .append("osArch", lOS.getArch()).append("osAvailableProcessors", lOS.getAvailableProcessors()) .append("osName", lOS.getName()).append("osVersion", lOS.getVersion()) .append("osLoadAverage", lOS.getSystemLoadAverage()) .append("heapMemoryUsed", lMemory.getHeapMemoryUsage().getUsed()) .append("heapMemoryMax", lMemory.getHeapMemoryUsage().getMax()) .append("heapMemoryInit", lMemory.getHeapMemoryUsage().getInit()) .append("nonheapMemoryInit", lMemory.getNonHeapMemoryUsage().getInit()) .append("nonheapMemoryMax", lMemory.getNonHeapMemoryUsage().getMax()) .append("nonheapMemoryUsed", lMemory.getNonHeapMemoryUsage().getUsed()).getMap()); sendToken(aConnector, lResponse); }