List of usage examples for java.lang.management RuntimeMXBean getSpecVersion
public String getSpecVersion();
From source file:Test.java
public static void main(String[] args) { RuntimeMXBean mxBean = ManagementFactory.getPlatformMXBean(RuntimeMXBean.class); System.out.println("JVM Name: " + mxBean.getName()); System.out.println("JVM Specification Name: " + mxBean.getSpecName()); System.out.println("JVM Specification Version: " + mxBean.getSpecVersion()); System.out.println("JVM Implemenation Name: " + mxBean.getVmName()); System.out.println("JVM Implemenation Vendor: " + mxBean.getVmVendor()); System.out.println("JVM Implemenation Version: " + mxBean.getVmVersion()); // Using the getPlatformMXBeans method List<OperatingSystemMXBean> list = ManagementFactory.getPlatformMXBeans(OperatingSystemMXBean.class); System.out.println("size: " + list.size()); for (OperatingSystemMXBean bean : list) { System.out.println("Operating System Name: " + bean.getName()); System.out.println("Operating System Architecture: " + bean.getArch()); System.out.println("Operating System Version: " + bean.getVersion()); }/* w w w . ja va 2s . co m*/ }
From source file:de.unisb.cs.st.javalanche.mutation.runtime.jmx.MutationMxClient.java
public static boolean connect(int i) { JMXConnector jmxc = null;/*from w ww . j a v a2s .c o 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: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 ww . ja v a 2s . co m 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: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.flink.runtime.util.EnvironmentInformation.java
public static String getJvmVersion() { try {//from ww w. j a v a 2 s . co m final RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean(); return bean.getVmName() + " - " + bean.getVmVendor() + " - " + bean.getSpecVersion() + '/' + bean.getVmVersion(); } catch (Throwable t) { return UNKNOWN; } }
From source file:org.craftercms.commons.monitoring.VersionMonitor.java
@SuppressWarnings("unchecked") private void initRuntime() { RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); java_version = runtime.getSpecVersion(); java_vendor = runtime.getSpecVendor(); java_runtime = runtime.getSpecName(); java_vm = runtime.getVmName();/*from w ww. j av a2s . c om*/ jvm_input_arguments = StringUtils.join(runtime.getInputArguments()); jvm_implementation_version = runtime.getVmVersion(); jvm_vendor = runtime.getVmVendor(); jvm_version = runtime.getSpecVersion(); }
From source file:org.fluentd.jvmwatcher.data.JvmWatchState.java
/** * @param clientPrixy/*from w w w. j av a2 s . c om*/ * @return */ public static JvmWatchState makeJvmWatchState(JvmClientProxy clientProxy) { // null check if (null == clientProxy) { return null; } if (null == clientProxy.getLocalJvmInfo()) { return null; } // create data object JvmWatchState ret = new JvmWatchState(); // set Local JVM Information ret.commandLine_ = clientProxy.getLocalJvmInfo().getCommandLine_(); ret.displayName_ = clientProxy.getLocalJvmInfo().getDisplayName(); ret.jvmId_ = clientProxy.getLocalJvmInfo().getJvmid(); ret.shortName_ = clientProxy.getLocalJvmInfo().getShortName(); // create log line array ret.stateLog_ = new ArrayList<JvmStateLog>(); // set JVM information try { // CompilationMXBean CompilationMXBean compilationBean = clientProxy.getCompilationMXBean(); if (null != compilationBean) { ret.jitName_ = compilationBean.getName(); } // OperatingSystemMXBean OperatingSystemMXBean OpeSysBean = clientProxy.getOperatingSystemMXBean(); if (null != OpeSysBean) { ret.osArch_ = OpeSysBean.getArch(); ret.osName_ = OpeSysBean.getName(); ret.osVersion_ = OpeSysBean.getVersion(); } // RuntimeMXBean RuntimeMXBean runtimeBean = clientProxy.getRuntimeMXBean(); if (null != runtimeBean) { ret.jvmStartTime_ = runtimeBean.getStartTime(); ret.jvmRuntimeName_ = runtimeBean.getName(); ret.vmName_ = runtimeBean.getVmName(); ret.vmVender_ = runtimeBean.getVmVendor(); ret.vmVersion_ = runtimeBean.getVmVersion(); ret.specName_ = runtimeBean.getSpecName(); ret.specVender_ = runtimeBean.getSpecVendor(); ret.specVersion_ = runtimeBean.getSpecVersion(); } } catch (IOException ex) { log.error("get MXBean error.", ex); // close JvmClientProxy clientProxy.disconnect(); } catch (Exception ex) { log.error("get MXBean error.", ex); // close JvmClientProxy clientProxy.disconnect(); } return ret; }
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;/* w w w . j a v a 2 s . c om*/ } 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); }
From source file:org.liferayhub.pc.service.impl.PowerConsoleServiceImpl.java
public String runCommand(long userId, long companyId, String mode, String command) { String response = ""; Date startDate = new Date(); if ("server".equalsIgnoreCase(mode)) { if ("help".equalsIgnoreCase(command)) { response = "Commands:\n" + "help\t\t\tShow this help message\n" + "version\t\t Display the version of the Liferay Portal\n" + "date\t\t\tDisplay the date and time of the database server\n" + "uptime\t\t Display the uptime of the portal\n" + "adduser\t\t Add a new user"; } else if ("version".equalsIgnoreCase(command)) { response = ReleaseInfo.getReleaseInfo() + " running on " + StringUtil.upperCaseFirstLetter(ServerDetector.getServerId()); } else if ("date".equalsIgnoreCase(command)) { response = new Date().toString(); } else if ("uptime".equalsIgnoreCase(command)) { response = getUptime(PortalUtil.getUptime().getTime()); } else if (command.toLowerCase().startsWith("adduser")) { response = handleAddUser(userId, companyId, command); }/* w w w . j av a 2 s.co m*/ } else if ("db".equalsIgnoreCase(mode)) { if ("help".equalsIgnoreCase(command)) { response = "Commands:\n" + "help\t\t\tShow this help message\n" + "version\t\t Display the version of the database\n" + "date\t\t\tDisplay the date and time of the database server\n" + "<sql query>\t Display result of any SQL query"; } else if ("date".equalsIgnoreCase(command)) { response = runSQLQuery("select now() \"\""); } else if ("version".equalsIgnoreCase(command)) { response = runSQLQuery( "select '" + DBFactoryUtil.getDBFactory().getDB().getType() + "' as '', version() ''"); } else response = runSQLQuery(command); } else if ("jvm".equalsIgnoreCase(mode)) { if ("help".equalsIgnoreCase(command)) { response = "Commands:\n" + "help\t\tShow this help message\n" + "mem\t\t Display memory usage of the JVM\n" + "osinfo\t Display operating system info of the running JVM\n" + "vminfo\t Display VM info"; } else if ("mem".equalsIgnoreCase(command)) { MemoryMXBean mem = ManagementFactory.getMemoryMXBean(); response = "Heap : " + mem.getHeapMemoryUsage().toString(); response += "\nNon Heap : " + mem.getNonHeapMemoryUsage().toString(); response += "\nFinalization: " + mem.getObjectPendingFinalizationCount() + " objects pending"; } else if ("osinfo".equalsIgnoreCase(command)) { OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); response = os.getName() + "[" + os.getArch() + "] " + os.getVersion() + " (" + os.getAvailableProcessors() + " processors)"; response += "\nLoad Average: " + os.getSystemLoadAverage(); } else if ("vminfo".equalsIgnoreCase(command)) { RuntimeMXBean vm = ManagementFactory.getRuntimeMXBean(); response = vm.getVmName() + " " + vm.getVmVersion() + " by " + vm.getVmVendor(); response += "\n" + vm.getSpecName() + " " + vm.getSpecVersion() + " by " + vm.getSpecVendor(); response += "\nStarted at: " + DateFormat.getInstance().format(new Date(vm.getStartTime())); response += "\nUptime : " + getUptime(vm.getStartTime()); } else { response = UNRECOGNIZED_COMMAND; } } // save command to database if it is not 'help' if (!command.startsWith("help")) { try { // add to history Date endDate = new Date(); long id = CounterLocalServiceUtil.increment(CommandHistory.class.getName()); CommandHistory history = CommandHistoryLocalServiceUtil.createCommandHistory(id); history.setCommand(command); history.setExecutionDate(startDate); history.setExecutionTime(endDate.getTime() - startDate.getTime()); history.setMode(mode); history.setUserId(userId); CommandHistoryLocalServiceUtil.updateCommandHistory(history); // TODO: delete the oldest entry > MAX_HISTORY_SIZE // get the history size long historySize = 100; List<CommandHistory> historyList = CommandHistoryLocalServiceUtil .findCommandHistoryByUserId(userId); if (historyList.size() >= historySize) { CommandHistoryLocalServiceUtil.deleteCommandHistory(historyList.get(0)); } } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e.getMessage()); } } return response; }