List of usage examples for java.lang.management OperatingSystemMXBean getAvailableProcessors
public int getAvailableProcessors();
From source file:api.Status.java
public static Result getMeta() { ObjectNode meta = Json.newObject();//from w w w .j a va 2s . c om 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: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./* w ww . ja v a 2s . 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.JvmStateLog.java
/** * @param clientPrixy/* www. jav a 2s . c o m*/ * @return */ public static JvmStateLog makeJvmStateLog(JvmClientProxy clientProxy) { JvmStateLog ret = new JvmStateLog(); try { // set log time ret.logDateTime_ = System.currentTimeMillis(); // ClassLoadingMXBean ClassLoadingMXBean classLoadingBean = clientProxy.getClassLoadingMXBean(); if (null != classLoadingBean) { ret.classLoadedCount_ = classLoadingBean.getLoadedClassCount(); ret.classUnloadedCount_ = classLoadingBean.getUnloadedClassCount(); ret.classTotalLoadedCount_ = classLoadingBean.getTotalLoadedClassCount(); } // CompilationMXBean CompilationMXBean compilationBean = clientProxy.getCompilationMXBean(); if (null != compilationBean) { ret.compileTime_ = compilationBean.getTotalCompilationTime(); } // MemoryMXBean MemoryMXBean memoryBean = clientProxy.getMemoryMXBean(); if (null != memoryBean) { ret.heapSize_ = memoryBean.getHeapMemoryUsage(); ret.notheapSize_ = memoryBean.getNonHeapMemoryUsage(); ret.pendingFinalizationCount_ = memoryBean.getObjectPendingFinalizationCount(); } // ThreadMXBean ThreadMXBean threadBean = clientProxy.getThreadMXBean(); if (null != threadBean) { ret.threadCount_ = threadBean.getThreadCount(); ret.daemonThreadCount_ = threadBean.getDaemonThreadCount(); ret.peakThreadCount_ = threadBean.getPeakThreadCount(); } // OperatingSystemMXBean OperatingSystemMXBean OpeSysBean = clientProxy.getOperatingSystemMXBean(); if (null != OpeSysBean) { ret.osAvailableProcessors_ = OpeSysBean.getAvailableProcessors(); ret.osSystemLoadAverage_ = OpeSysBean.getSystemLoadAverage(); } // com.sun.management.OperatingSystemMXBean com.sun.management.OperatingSystemMXBean sunOpeSysBean = clientProxy.getSunOperatingSystemMXBean(); if (null != sunOpeSysBean) { ret.committedVirtualMemorySize_ = sunOpeSysBean.getCommittedVirtualMemorySize(); ret.freePhysicalMemorySize_ = sunOpeSysBean.getFreePhysicalMemorySize(); ret.freeSwapSpaceSize_ = sunOpeSysBean.getFreeSwapSpaceSize(); ret.processCpuTime_ = sunOpeSysBean.getProcessCpuTime(); ret.totalPhysicalMemorySize_ = sunOpeSysBean.getTotalPhysicalMemorySize(); ret.totalSwapSpaceSize_ = sunOpeSysBean.getTotalSwapSpaceSize(); } // RuntimeMXBean RuntimeMXBean runtimeBean = clientProxy.getRuntimeMXBean(); if (null != runtimeBean) { ret.jvmUpTime_ = runtimeBean.getUptime(); } // MemoryPoolMXBean Collection<MemoryPoolClientProxy> memoryPoolBeansColl = clientProxy.getMemoryPoolClientProxies(); if (null != memoryPoolBeansColl) { ret.memoryPoolStateColl_ = new ArrayList<MemoryPoolState>(); for (MemoryPoolClientProxy elem : memoryPoolBeansColl) { if (null != elem) { MemoryPoolState state = elem.getStat(); if (null != state) { // add MemoryPoolState ret.memoryPoolStateColl_.add(state); } } } } // GarbageCollectorMXBean Collection<GarbageCollectorMXBean> garbageCollBeansColl = clientProxy.getGarbageCollectorMXBeans(); if (null != garbageCollBeansColl) { ret.gcCollectorState_ = new ArrayList<GarbageCollectorState>(); for (GarbageCollectorMXBean elem : garbageCollBeansColl) { if (null != elem) { long collectionCount = elem.getCollectionCount(); long collectionTime = elem.getCollectionTime(); String memoryManagerName = elem.getName(); GarbageCollectorState state = new GarbageCollectorState(memoryManagerName, collectionCount, collectionTime); // add GarbageCollectorState ret.gcCollectorState_.add(state); } } } } catch (IOException ex) { log.error(ex); // close JvmClientProxy clientProxy.disconnect(); } catch (Exception ex) { log.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 ww w. 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:io.ecarf.core.utils.Utils.java
/** * Log the CPU stats//from w w w . ja v a 2 s . com */ public static void logCpuStats() { OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory .getOperatingSystemMXBean(); RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); int availableProcessors = operatingSystemMXBean.getAvailableProcessors(); long upTime = runtimeMXBean.getUptime(); double loadAverage = operatingSystemMXBean.getSystemLoadAverage(); log.info("Available processors: " + availableProcessors); log.info("JVM upTime (ms): " + upTime); log.info("CPU load average: " + loadAverage); }
From source file:org.cloudfoundry.identity.statsd.UaaMetricsEmitter.java
@Scheduled(fixedRate = 5000, initialDelay = 2000) public void emitVmVitals() { OperatingSystemMXBean mbean = ManagementFactory.getOperatingSystemMXBean(); String prefix = "vitals.vm."; statsDClient.gauge(prefix + "cpu.count", mbean.getAvailableProcessors()); statsDClient.gauge(prefix + "cpu.load", (long) (mbean.getSystemLoadAverage() * 100)); invokeIfPresent(prefix + "memory.total", mbean, "getTotalPhysicalMemorySize"); invokeIfPresent(prefix + "memory.committed", mbean, "getCommittedVirtualMemorySize"); invokeIfPresent(prefix + "memory.free", mbean, "getFreePhysicalMemorySize"); }
From source file:org.artifactory.webapp.wicket.page.config.advanced.SystemInfoPage.java
/** * Return a formatted string of the system info to display * * @return/*from w ww. j a v a 2 s . com*/ */ private String collectSystemInfo() { StringBuilder infoBuilder = new StringBuilder(); StorageProperties storageProperties = ContextHelper.get().beanForType(StorageProperties.class); infoBuilder.append("Storage Info:").append("\n"); addInfo(infoBuilder, "Database Type", storageProperties.getDbType().toString()); BinaryProviderType binariesStorageType = storageProperties.getBinariesStorageType(); addInfo(infoBuilder, "Storage Type", binariesStorageType.toString()); if (BinaryProviderType.S3 == binariesStorageType) { // S3 properties addInfo(infoBuilder, "s3.bucket.name", storageProperties.getS3BucketName()); addInfo(infoBuilder, "s3.bucket.path", storageProperties.getS3BucketPath()); addInfo(infoBuilder, "s3.endpoint", storageProperties.getS3Entpoint()); // Retry properties addInfo(infoBuilder, "retry.max.retries.number", Integer.toString(storageProperties.getMaxRetriesNumber())); addInfo(infoBuilder, "retry.delay.between.retries", Integer.toString(storageProperties.getDelayBetweenRetries())); // Eventually persisted properties addInfo(infoBuilder, "eventually.persisted.max.number.of.threads", Integer.toString(storageProperties.getEventuallyPersistedMaxNumberOfThread())); addInfo(infoBuilder, "eventually.persisted.timeout", Integer.toString(storageProperties.getEventuallyPersistedTimeOut())); addInfo(infoBuilder, "eventually.dispatcher.sleep.time", Long.toString(storageProperties.getEventuallyPersistedDispatcherSleepTime())); } infoBuilder.append("\n").append("System Properties:").append("\n"); Properties properties = System.getProperties(); //// add Artifactory version to the properties, will be alphabetically sorted later. properties.setProperty(ConstantValues.artifactoryVersion.getPropertyName(), ConstantValues.artifactoryVersion.getString()); AddonsManager addonsManager = ContextHelper.get().beanForType(AddonsManager.class); addInfo(infoBuilder, "artifactory.running.mode", addonsManager.getArtifactoryRunningMode().name()); addInfo(infoBuilder, "artifactory.running.state", ContextHelper.get().isOffline() ? "Offline" : "Online"); addFromProperties(infoBuilder, properties); addHaProperties(infoBuilder); infoBuilder.append("\n").append("General JVM Info:").append("\n"); OperatingSystemMXBean systemBean = ManagementFactory.getOperatingSystemMXBean(); addInfo(infoBuilder, "Available Processors", Integer.toString(systemBean.getAvailableProcessors())); MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean(); MemoryUsage heapMemoryUsage = memoryBean.getHeapMemoryUsage(); addInfo(infoBuilder, "Heap Memory Usage-Committed", Long.toString(heapMemoryUsage.getCommitted())); addInfo(infoBuilder, "Heap Memory Usage-Init", Long.toString(heapMemoryUsage.getInit())); addInfo(infoBuilder, "Heap Memory Usage-Max", Long.toString(heapMemoryUsage.getMax())); addInfo(infoBuilder, "Heap Memory Usage-Used", Long.toString(heapMemoryUsage.getUsed())); MemoryUsage nonHeapMemoryUsage = memoryBean.getNonHeapMemoryUsage(); addInfo(infoBuilder, "Non-Heap Memory Usage-Committed", Long.toString(nonHeapMemoryUsage.getCommitted())); addInfo(infoBuilder, "Non-Heap Memory Usage-Init", Long.toString(nonHeapMemoryUsage.getInit())); addInfo(infoBuilder, "Non-Heap Memory Usage-Max", Long.toString(nonHeapMemoryUsage.getMax())); addInfo(infoBuilder, "Non-Heap Memory Usage-Used", Long.toString(nonHeapMemoryUsage.getUsed())); RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean(); StringBuilder vmArgumentBuilder = new StringBuilder(); List<String> vmArguments = RuntimemxBean.getInputArguments(); if (vmArguments != null) { for (String vmArgument : vmArguments) { if (InfoWriter.shouldMaskValue(vmArgument)) { vmArgument = Strings.maskKeyValue(vmArgument); } vmArgumentBuilder.append(vmArgument); if (vmArguments.indexOf(vmArgument) != (vmArguments.size() - 1)) { vmArgumentBuilder.append("\n"); } } } infoBuilder.append("\nJVM Arguments:\n").append(vmArgumentBuilder.toString()); return StringUtils.removeEnd(infoBuilder.toString(), "\n"); }
From source file:org.eclipse.gyrex.cloud.internal.NodeMetricsReporter.java
@Override protected IStatus run(final IProgressMonitor monitor) { if (monitor.isCanceled()) { return Status.CANCEL_STATUS; }/*from w ww .j a va 2s .c om*/ try { final Properties metrics = new Properties() { private static final long serialVersionUID = 1L; @Override public synchronized Enumeration<Object> keys() { return Collections.enumeration(keySet()); } @Override public Set<Object> keySet() { return new TreeSet<Object>(super.keySet()); } }; final OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); metrics.setProperty("os.availableProcessors", String.valueOf(operatingSystemMXBean.getAvailableProcessors())); metrics.setProperty("os.systemLoadAverage", String.valueOf(operatingSystemMXBean.getSystemLoadAverage())); metrics.setProperty("os.committedVirtualMemorySize", getUsingReflection(operatingSystemMXBean, "getCommittedVirtualMemorySize")); metrics.setProperty("os.totalSwapSpaceSize", getUsingReflection(operatingSystemMXBean, "getTotalSwapSpaceSize")); metrics.setProperty("os.freeSwapSpaceSize", getUsingReflection(operatingSystemMXBean, "getFreeSwapSpaceSize")); metrics.setProperty("os.processCpuTime", getUsingReflection(operatingSystemMXBean, "getProcessCpuTime")); metrics.setProperty("os.freePhysicalMemorySize", getUsingReflection(operatingSystemMXBean, "getFreePhysicalMemorySize")); metrics.setProperty("os.totalPhysicalMemorySize", getUsingReflection(operatingSystemMXBean, "getTotalPhysicalMemorySize")); metrics.setProperty("os.openFileDescriptorCount", getUsingReflection(operatingSystemMXBean, "getOpenFileDescriptorCount")); metrics.setProperty("os.maxFileDescriptorCount", getUsingReflection(operatingSystemMXBean, "getMaxFileDescriptorCount")); final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); final MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage(); metrics.setProperty("heap.used", String.valueOf(heapMemoryUsage.getUsed())); metrics.setProperty("heap.committed", String.valueOf(heapMemoryUsage.getCommitted())); metrics.setProperty("heap.max", String.valueOf(heapMemoryUsage.getMax())); metrics.setProperty("heap.init", String.valueOf(heapMemoryUsage.getInit())); final MemoryUsage nonHeapMemoryUsage = memoryMXBean.getNonHeapMemoryUsage(); metrics.setProperty("nonHeap.used", String.valueOf(nonHeapMemoryUsage.getUsed())); metrics.setProperty("nonHeap.committed", String.valueOf(nonHeapMemoryUsage.getCommitted())); metrics.setProperty("nonHeap.max", String.valueOf(nonHeapMemoryUsage.getMax())); metrics.setProperty("nonHeap.init", String.valueOf(nonHeapMemoryUsage.getInit())); final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); metrics.setProperty("thread.count", String.valueOf(threadMXBean.getThreadCount())); metrics.setProperty("thread.peak", String.valueOf(threadMXBean.getPeakThreadCount())); metrics.setProperty("thread.totalStarted", String.valueOf(threadMXBean.getTotalStartedThreadCount())); final RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); metrics.setProperty("uptime", String.valueOf(runtimeMXBean.getUptime())); final ByteArrayOutputStream out = new ByteArrayOutputStream(); final NodeInfo nodeInfo = CloudState.getNodeInfo(); metrics.store(out, String.valueOf(nodeInfo)); ZooKeeperGate.get().writeRecord(IZooKeeperLayout.PATH_NODES_METRICS.append(nodeInfo.getNodeId()), CreateMode.PERSISTENT, out.toByteArray()); if (CloudDebug.nodeMetrics) { LOG.debug("Node metrics reported successfully.{}{}", SystemUtils.LINE_SEPARATOR, new String(out.toByteArray(), CharEncoding.ISO_8859_1)); } } catch (final Exception e) { LOG.warn("Failed to update node metrics. {}", e.getMessage()); } finally { // reschedule schedule(DELAY); } return Status.OK_STATUS; }
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())); }