List of usage examples for java.lang.management OperatingSystemMXBean getArch
public String getArch();
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 .j a v a 2s . c om }
From source file:api.Status.java
public static Result getMeta() { ObjectNode meta = Json.newObject();// w ww .j a v a 2s . c o 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:org.apache.solr.handler.admin.SystemInfoHandler.java
/** * Get system info//from w ww. ja v a 2s.c o 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.pepstock.jem.node.NodeInfoUtility.java
/** * Factory creates a NodeInfo copying a set of information from Member * object of Hazelcast framework. NodeInfo will use Uuid of Member as the * key./*from w ww . j a v a2 s . com*/ * * @see org.pepstock.jem.node.NodeInfo * @param member member object of Hazelcast framework * @param info node info to load * @throws NodeException if any exception occurs */ public static final void loadNodeInfo(Member member, NodeInfo info) throws NodeException { String jemVersion = getManifestAttribute(ConfigKeys.JEM_MANIFEST_VERSION); // sets the version if (jemVersion != null) { info.setJemVersion(jemVersion); } // set uuid of member of hazelcast as key info.setKey(member.getUuid()); // set status starting at the beginning info.setStatus(Status.STARTING); // sets boolean if has affinity loader // for net info of member, loads all info inside of nodeinfo // port of RMI will be set later InetSocketAddress address = member.getInetSocketAddress(); info.setPort(address.getPort()); info.setIpaddress(address.getAddress().getHostAddress()); // sets label to be displayed by GRS info.setLabel(info.getIpaddress() + ":" + info.getPort()); // sets execution environment info.setExecutionEnvironment(Main.EXECUTION_ENVIRONMENT); // use JMX to extract current process id info.setProcessId(ManagementFactory.getRuntimeMXBean().getName()); // extracts the name using the MXBean result String hostname = StringUtils.substringAfter(info.getProcessId(), "@"); info.setHostname(hostname); // extracts from operating ssytem MXbean all info about the ssytem OperatingSystemMXBean bean = ManagementFactory.getOperatingSystemMXBean(); info.getNodeInfoBean().setSystemArchitecture(bean.getArch()); info.getNodeInfoBean().setAvailableProcessors(bean.getAvailableProcessors()); info.getNodeInfoBean().setSystemName(bean.getName()); // uses SIGAR to get total memory and the user used by JEM to start try { info.getNodeInfoBean().setTotalMemory(SIGAR.getMem().getTotal()); ProcCredName cred = SIGAR.getProcCredName(SIGAR.getPid()); info.setUser(cred.getUser()); } catch (SigarException e) { throw new NodeException(e.getMessage(), e); } // informs the node itself that it has been loaded info.loaded(); }
From source file:org.fluentd.jvmwatcher.data.JvmWatchState.java
/** * @param clientPrixy/*from w w w . j a va 2 s. co 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: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 www. j a v a 2s . c o m*/ 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.craftercms.commons.monitoring.VersionMonitor.java
private void initOS() { OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); operating_system = os.getName() + "-" + os.getVersion(); os_architecture = os.getArch(); 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: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 www. ja v a 2s . com*/ } 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; }
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 {/*ww w .jav a 2 s . c om*/ 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; }