Java Code Examples for java.lang.management.ManagementFactory#getOperatingSystemMXBean()
The following examples show how to use
java.lang.management.ManagementFactory#getOperatingSystemMXBean() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VMLogger.java From openjdk-systemtest with Apache License 2.0 | 6 votes |
private void initialiseProxies() { runtimeBean = ManagementFactory.getRuntimeMXBean(); osBean = ManagementFactory.getOperatingSystemMXBean(); classBean = ManagementFactory.getClassLoadingMXBean(); if (!(compiler.equals(""))) { compBean = ManagementFactory.getCompilationMXBean(); } threadBean = ManagementFactory.getThreadMXBean(); memBean = ManagementFactory.getMemoryMXBean(); logBean = LogManager.getLoggingMXBean(); memPoolBeans = ManagementFactory.getMemoryPoolMXBeans(); memMgrBeans = ManagementFactory.getMemoryManagerMXBeans(); gcBeans = ManagementFactory.getGarbageCollectorMXBeans(); }
Example 2
Source File: HealthStatisticsReader.java From attic-stratos with Apache License 2.0 | 6 votes |
public CartridgeStatistics getCartridgeStatistics() throws IOException { OperatingSystemMXBean osBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); double totalMemory = (double) (osBean.getTotalPhysicalMemorySize() / MB); double usedMemory = (double) ((totalMemory - (osBean.getFreePhysicalMemorySize() / MB))); double loadAvg = (double) osBean.getSystemLoadAverage(); // assume system cores = available cores to JVM int cores = osBean.getAvailableProcessors(); double memoryConsumption = (usedMemory / totalMemory) * 100; double loadAvgPercentage = (loadAvg / cores) * 100; if (log.isDebugEnabled()) { log.debug("Memory consumption: [totalMemory] " + totalMemory + "Mb [usedMemory] " + usedMemory + "Mb: " + memoryConsumption + "%"); log.debug("Processor consumption: [loadAverage] " + loadAvg + " [cores] " + cores + ": " + loadAvgPercentage + "%"); } return (new CartridgeStatistics(memoryConsumption, loadAvgPercentage)); }
Example 3
Source File: StoreUtil.java From RocketMQ-Master-analyze with Apache License 2.0 | 5 votes |
@SuppressWarnings("restriction") public static long getTotalPhysicalMemorySize() { long physicalTotal = 1024 * 1024 * 1024 * 24; OperatingSystemMXBean osmxb = ManagementFactory.getOperatingSystemMXBean(); if (osmxb instanceof com.sun.management.OperatingSystemMXBean) { physicalTotal = ((com.sun.management.OperatingSystemMXBean) osmxb).getTotalPhysicalMemorySize(); } return physicalTotal; }
Example 4
Source File: GetSystemInfo.java From csustRepo with MIT License | 5 votes |
/** * 获取内存使用率 * @return */ public static String getMemeryRate() { OperatingSystemMXBean osmxb = (OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean(); // 总的物理内存+虚拟内存 long totalvirtualMemory = osmxb.getTotalSwapSpaceSize(); // 剩余的物理内存 long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize(); Double compare = (Double)(1 - freePhysicalMemorySize * 1.0 / totalvirtualMemory) * 100; String str = compare.intValue() + "%"; return str; }
Example 5
Source File: WindowsInfoUtil.java From charging_pile_cloud with MIT License | 5 votes |
public static int getMemery() { OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory .getOperatingSystemMXBean(); // 总的物理内存+虚拟内存 long totalvirtualMemory = osmxb.getTotalSwapSpaceSize(); // 剩余的物理内存 long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize(); Double compare = (Double) (1 - freePhysicalMemorySize * 1.0 / totalvirtualMemory) * 100; return compare.intValue(); }
Example 6
Source File: Environment.java From rtg-tools with BSD 2-Clause "Simplified" License | 5 votes |
/** * Get number of available processors. * @return number of available processors. */ public static int getAvailableProcessors() { final OperatingSystemMXBean bean = ManagementFactory.getOperatingSystemMXBean(); if (bean != null) { return bean.getAvailableProcessors(); } throw new IllegalStateException(); }
Example 7
Source File: SystemCpuStressMonitor.java From apm-agent-java with Apache License 2.0 | 5 votes |
SystemCpuStressMonitor(ElasticApmTracer tracer) { super(tracer); operatingSystemBean = ManagementFactory.getOperatingSystemMXBean(); systemCpuUsageMethod = JmxUtils.getOperatingSystemMBeanMethod(operatingSystemBean, "getSystemCpuLoad"); if (systemCpuUsageMethod != null) { logger.debug("Successfully obtained reference to the getSystemCpuLoad method of this JVM's OperatingSystemMXBean implementation"); } else { logger.warn("Failed to obtain reference to the getSystemCpuLoad method of this JVM's OperatingSystemMXBean implementation"); } }
Example 8
Source File: OperatingSystemDiagnosticTask.java From nifi with Apache License 2.0 | 5 votes |
@Override public DiagnosticsDumpElement captureDump(final boolean verbose) { final OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); final List<String> details = new ArrayList<>(); final NumberFormat numberFormat = NumberFormat.getInstance(); try { final SortedMap<String, String> attributes = new TreeMap<>(); final ObjectName osObjectName = os.getObjectName(); final MBeanInfo mbeanInfo = ManagementFactory.getPlatformMBeanServer().getMBeanInfo(osObjectName); for (final MBeanAttributeInfo attributeInfo : mbeanInfo.getAttributes()) { final String attributeName = attributeInfo.getName(); if (IGNORABLE_ATTRIBUTE_NAMES.contains(attributeName)) { continue; } final Object attributeValue = ManagementFactory.getPlatformMBeanServer().getAttribute(osObjectName, attributeName); if (attributeValue instanceof Number) { attributes.put(attributeName, numberFormat.format(attributeValue)); } else { attributes.put(attributeName, String.valueOf(attributeValue)); } } attributes.forEach((key, value) -> details.add(key + " : " + value)); } catch (final Exception e) { logger.error("Failed to obtain Operating System details", e); return new StandardDiagnosticsDumpElement("Operating System / Hardware", Collections.singletonList("Failed to obtain Operating System details")); } return new StandardDiagnosticsDumpElement("Operating System / Hardware", details); }
Example 9
Source File: CPUInfo.java From netbeans with Apache License 2.0 | 5 votes |
static void logCPUInfo() { LogRecord log = new LogRecord(Level.FINEST, MESSAGE); // NOI18N OperatingSystemMXBean bean = ManagementFactory.getOperatingSystemMXBean(); Object [] params = new Object[]{bean.getAvailableProcessors()}; log.setParameters(params); Logger.getLogger(Installer.UI_PERFORMANCE_LOGGER_NAME).log(log); }
Example 10
Source File: Sys.java From boon with Apache License 2.0 | 5 votes |
public static long maxFileDescriptorCount() { if (oracleJVMAndUnix) { UnixOperatingSystemMXBean unix = (UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); return unix.getMaxFileDescriptorCount(); }else { return -1; } }
Example 11
Source File: IndexAdminController.java From Roothub with GNU Affero General Public License v3.0 | 5 votes |
@RequestMapping(value = "/console", method = RequestMethod.GET) public String console(Model model) { // 查询当天新增话题 model.addAttribute("topic_count", topicService.countToday()); // 查询当天新增评论 model.addAttribute("comment_count", replyService.count()); // 查询当天新增用户 model.addAttribute("user_count", userService.countToday()); //查询当天新增节点 model.addAttribute("node_count", nodeService.countToday()); // 获取操作系统的名字 model.addAttribute("os_name", System.getProperty("os.name")); // 内存 int kb = 1024; OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory .getOperatingSystemMXBean(); // 总的物理内存(G) float totalMemorySize = (float) osmxb.getTotalPhysicalMemorySize() / kb / kb / kb; //已使用的物理内存(G) float usedMemory = (float) (osmxb.getTotalPhysicalMemorySize() - osmxb.getFreePhysicalMemorySize()) / kb / kb /kb; // 获取系统cpu负载 double systemCpuLoad = osmxb.getSystemCpuLoad(); // 获取jvm线程负载 double processCpuLoad = osmxb.getProcessCpuLoad(); DecimalFormat df = new DecimalFormat("0.0"); model.addAttribute("totalMemorySize", df.format(totalMemorySize)); model.addAttribute("usedMemory", df.format(usedMemory)); model.addAttribute("systemCpuLoad", df.format(systemCpuLoad)); model.addAttribute("processCpuLoad", df.format(processCpuLoad)); return "/admin/console"; }
Example 12
Source File: OperatingSystemMetricSet.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public Map<String, Metric> getMetrics() { final Map<String, Metric> metrics = new HashMap<>(); OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); MetricUtils.addMXBeanMetrics(os, MetricUtils.OS_MXBEAN_CLASSES, null, (k, v) -> { if (!metrics.containsKey(k)) { metrics.put(k, v); } }); return metrics; }
Example 13
Source File: ServerArgument.java From incubator-iotdb with Apache License 2.0 | 4 votes |
private long freePhysicalMemory() { OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); long freeMemorySize = osmxb.getFreePhysicalMemorySize() / 1024 / 1024; return freeMemorySize; }
Example 14
Source File: VMDetailView.java From vjtools with Apache License 2.0 | 4 votes |
public VMDetailView(String pid, DetailMode mode, Integer width) throws Exception { this.vmInfo = VMInfo.processNewVM(pid); this.mode = mode; setWidth(width); operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); }
Example 15
Source File: JvmOSImpl.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
static OperatingSystemMXBean getOSMBean() { return ManagementFactory.getOperatingSystemMXBean(); }
Example 16
Source File: StandardExports.java From client_java with Apache License 2.0 | 4 votes |
public StandardExports() { this(new StatusReader(), ManagementFactory.getOperatingSystemMXBean(), ManagementFactory.getRuntimeMXBean()); }
Example 17
Source File: Runner.java From locust4j with MIT License | 4 votes |
private OperatingSystemMXBean getOsBean() { return (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); }
Example 18
Source File: EnvironmentCommand.java From LagMonitor with MIT License | 4 votes |
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!canExecute(sender, command)) { return true; } OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean(); //os general info sendMessage(sender, "OS Name", osBean.getName()); sendMessage(sender, "OS Arch", osBean.getArch()); Optional<SystemInfo> optInfo = plugin.getNativeData().getSystemInfo(); if (optInfo.isPresent()) { SystemInfo systemInfo = optInfo.get(); OperatingSystem osInfo = systemInfo.getOperatingSystem(); sendMessage(sender, "OS family", osInfo.getFamily()); sendMessage(sender, "OS version", osInfo.getVersionInfo().toString()); sendMessage(sender, "OS Manufacturer", osInfo.getManufacturer()); sendMessage(sender, "Total processes", String.valueOf(osInfo.getProcessCount())); sendMessage(sender, "Total threads", String.valueOf(osInfo.getThreadCount())); } //CPU sender.sendMessage(PRIMARY_COLOR + "CPU:"); if (optInfo.isPresent()) { CentralProcessor processor = optInfo.get().getHardware().getProcessor(); ProcessorIdentifier identifier = processor.getProcessorIdentifier(); sendMessage(sender, " Vendor", identifier.getVendor()); sendMessage(sender, " Family", identifier.getFamily()); sendMessage(sender, " Name", identifier.getName()); sendMessage(sender, " Model", identifier.getModel()); sendMessage(sender, " Id", identifier.getIdentifier()); sendMessage(sender, " Vendor freq", String.valueOf(identifier.getVendorFreq())); sendMessage(sender, " Physical Cores", String.valueOf(processor.getPhysicalProcessorCount())); } sendMessage(sender, " Logical Cores", String.valueOf(osBean.getAvailableProcessors())); sendMessage(sender, " Endian", System.getProperty("sun.cpu.endian", "Unknown")); sendMessage(sender, "Load Average", String.valueOf(osBean.getSystemLoadAverage())); printExtendOsInfo(sender); displayDiskSpace(sender); NativeManager nativeData = plugin.getNativeData(); sendMessage(sender, "Open file descriptors", String.valueOf(nativeData.getOpenFileDescriptors())); sendMessage(sender, "Max file descriptors", String.valueOf(nativeData.getMaxFileDescriptors())); sender.sendMessage(PRIMARY_COLOR + "Variables:"); for (Entry<String, String> variable : System.getenv().entrySet()) { sendMessage(sender, " " + variable.getKey(), variable.getValue()); } return true; }
Example 19
Source File: UsedCPUDisplay.java From Rel with Apache License 2.0 | 3 votes |
public static int getProcessCPULoad() { java.lang.management.OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); double processCpuLoad = ((com.sun.management.OperatingSystemMXBean)operatingSystemMXBean).getProcessCpuLoad(); return (int)(processCpuLoad * 100.0); }
Example 20
Source File: SystemSupplier.java From joyrpc with Apache License 2.0 | 2 votes |
/** * 获取内存大小 * * @return 内存大小 */ protected long getMemory() { OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); return osmxb.getTotalPhysicalMemorySize(); }