List of usage examples for java.lang.management OperatingSystemMXBean getVersion
public String getVersion();
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 ww .ja va2s . com }
From source file:api.Status.java
public static Result getMeta() { ObjectNode meta = Json.newObject();/*from www. ja v a 2 s .co m*/ OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); meta.put("osName", os.getName()); meta.put("osVersion", os.getVersion()); meta.put("arch", os.getArch()); meta.put("cpus", os.getAvailableProcessors()); return ok(meta.toString()); }
From source file:ro.nextreports.server.web.debug.InfoUtil.java
public static List<Info> getGeneralJVMInfo() { List<Info> infos = new ArrayList<Info>(); RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); infos.add(new Info("uptime", "" + Duration.milliseconds(runtimeBean.getUptime()).toString())); infos.add(new Info("name", runtimeBean.getName())); infos.add(new Info("pid", runtimeBean.getName().split("@")[0])); OperatingSystemMXBean systemBean = ManagementFactory.getOperatingSystemMXBean(); infos.add(new Info("os name", "" + systemBean.getName())); infos.add(new Info("os version", "" + systemBean.getVersion())); infos.add(new Info("system load average", "" + systemBean.getSystemLoadAverage())); infos.add(new Info("available processors", "" + systemBean.getAvailableProcessors())); ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); infos.add(new Info("thread count", "" + threadBean.getThreadCount())); infos.add(new Info("peak thread count", "" + threadBean.getPeakThreadCount())); MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean(); infos.add(new Info("heap memory used", FileUtils.byteCountToDisplaySize(memoryBean.getHeapMemoryUsage().getUsed()))); infos.add(new Info("non-heap memory used", FileUtils.byteCountToDisplaySize(memoryBean.getNonHeapMemoryUsage().getUsed()))); return infos; }
From source file:net.centro.rtb.monitoringcenter.infos.OperatingSystemInfo.java
public static OperatingSystemInfo create() { OperatingSystemInfo operatingSystemInfo = new OperatingSystemInfo(); OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); operatingSystemInfo.name = operatingSystemMXBean.getName(); operatingSystemInfo.version = operatingSystemMXBean.getVersion(); if (SystemUtils.IS_OS_LINUX) { operatingSystemInfo.distributionName = resolveLinuxDistributionName(); }/*from w ww. j av a2 s . c om*/ operatingSystemInfo.architecture = operatingSystemMXBean.getArch(); operatingSystemInfo.numberOfLogicalProcessors = operatingSystemMXBean.getAvailableProcessors(); if (com.sun.management.OperatingSystemMXBean.class.isAssignableFrom(operatingSystemMXBean.getClass())) { com.sun.management.OperatingSystemMXBean sunOsMxBean = com.sun.management.OperatingSystemMXBean.class .cast(operatingSystemMXBean); operatingSystemInfo.physicalMemorySizeInBytes = sunOsMxBean.getTotalPhysicalMemorySize(); operatingSystemInfo.swapSpaceSizeInBytes = sunOsMxBean.getTotalSwapSpaceSize(); } Map<String, Long> diskSpaceInBytesByRootPaths = new HashMap<>(); for (File rootFile : File.listRoots()) { diskSpaceInBytesByRootPaths.put(rootFile.getAbsolutePath(), rootFile.getTotalSpace()); } operatingSystemInfo.diskSpaceInBytesByRootPaths = diskSpaceInBytesByRootPaths; return operatingSystemInfo; }
From source file:org.apache.solr.handler.admin.SystemInfoHandler.java
/** * Get system info/* w w w.java2s . co m*/ */ public static SimpleOrderedMap<Object> getSystemInfo() throws Exception { SimpleOrderedMap<Object> info = new SimpleOrderedMap<Object>(); OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); info.add("name", os.getName()); info.add("version", os.getVersion()); info.add("arch", os.getArch()); // Java 1.6 addGetterIfAvaliable(os, "systemLoadAverage", info); // com.sun.management.UnixOperatingSystemMXBean addGetterIfAvaliable(os, "openFileDescriptorCount", info); addGetterIfAvaliable(os, "maxFileDescriptorCount", info); // com.sun.management.OperatingSystemMXBean addGetterIfAvaliable(os, "committedVirtualMemorySize", info); addGetterIfAvaliable(os, "totalPhysicalMemorySize", info); addGetterIfAvaliable(os, "totalSwapSpaceSize", info); addGetterIfAvaliable(os, "processCpuTime", info); try { if (!os.getName().toLowerCase(Locale.ENGLISH).startsWith("windows")) { // Try some command line things info.add("uname", execute("uname -a")); info.add("ulimit", execute("ulimit -n")); info.add("uptime", execute("uptime")); } } catch (Throwable ex) { } // ignore return info; }
From source file:org.fluentd.jvmwatcher.data.JvmWatchState.java
/** * @param clientPrixy/* w w w . ja v a 2s . c o m*/ * @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.craftercms.commons.monitoring.VersionMonitor.java
private void initOS() { OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); operating_system = os.getName() + "-" + os.getVersion(); os_architecture = os.getArch();/* ww w .java 2 s . c o m*/ system_encoding = System.getProperty(FILE_ENCODING_SYSTEM_PROP_KEY); }
From source file:com.thoughtworks.go.server.service.support.ServerRuntimeInformationProvider.java
private void osInfo(OperatingSystemMXBean operatingSystemMXBean, InformationStringBuilder builder) { builder.addSection("OS information"); builder.append(String.format("%s, %s, %s, %s, %s\n", operatingSystemMXBean.getName(), operatingSystemMXBean.getArch(), operatingSystemMXBean.getVersion(), operatingSystemMXBean.getAvailableProcessors(), operatingSystemMXBean.getSystemLoadAverage())); }
From source file:com.searchbox.framework.web.SystemController.java
@ModelAttribute("systemInfo") private Map<String, Object> getSystemInfo() { Map<String, Object> info = new HashMap<String, Object>(); OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); info.put("name", os.getName()); info.put("version", os.getVersion()); info.put("arch", os.getArch()); info.put("systemLoadAverage", os.getSystemLoadAverage()); // com.sun.management.OperatingSystemMXBean addGetterIfAvaliable(os, "committedVirtualMemorySize", info); addGetterIfAvaliable(os, "freePhysicalMemorySize", info); addGetterIfAvaliable(os, "freeSwapSpaceSize", info); addGetterIfAvaliable(os, "processCpuTime", info); addGetterIfAvaliable(os, "totalPhysicalMemorySize", info); addGetterIfAvaliable(os, "totalSwapSpaceSize", info); // com.sun.management.UnixOperatingSystemMXBean addGetterIfAvaliable(os, "openFileDescriptorCount", info); addGetterIfAvaliable(os, "maxFileDescriptorCount", info); try {//from w w w . j av a 2 s .com if (!os.getName().toLowerCase(Locale.ROOT).startsWith("windows")) { // Try some command line things info.put("uname", execute("uname -a")); info.put("uptime", execute("uptime")); } } catch (Exception ex) { ex.printStackTrace(); } return info; }
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); }/*from ww w. j a va2 s . c om*/ } 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; }