当前位置: 首页>>代码示例>>Java>>正文


Java ManagementFactory.getOperatingSystemMXBean方法代码示例

本文整理汇总了Java中java.lang.management.ManagementFactory.getOperatingSystemMXBean方法的典型用法代码示例。如果您正苦于以下问题:Java ManagementFactory.getOperatingSystemMXBean方法的具体用法?Java ManagementFactory.getOperatingSystemMXBean怎么用?Java ManagementFactory.getOperatingSystemMXBean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.management.ManagementFactory的用法示例。


在下文中一共展示了ManagementFactory.getOperatingSystemMXBean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getOSMemory

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private static long getOSMemory(String methodName, String warning) {
	long ram = 0;
	OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
	Method m;
	try {
		m = operatingSystemMXBean.getClass().getDeclaredMethod(methodName);
		m.setAccessible(true);
		Object value = m.invoke(operatingSystemMXBean);
		if (value != null) {
			ram = Long.valueOf(value.toString()) / 1024 / 1024;
		} else {
			OneClientLogging.logger.warn(warning);
			ram = 1024;
		}
	} catch (Exception e) {
		OneClientLogging.error(e);
	}

	return ram;
}
 
开发者ID:HearthProject,项目名称:OneClient,代码行数:21,代码来源:OperatingSystem.java

示例2: getMaxJvmHeapMemory

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
/**
 * The maximum JVM heap size, in bytes.
 * 
 * @return The maximum JVM heap size, in bytes.
 */
public static long getMaxJvmHeapMemory() {
	long maxMemory = Runtime.getRuntime().maxMemory();

	if (maxMemory == Long.MAX_VALUE) {
		// amount of free memory unknown
		try {
			// workaround for Oracle JDK
			OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
			Class<?> clazz = Class.forName("com.sun.management.OperatingSystemMXBean");
			Method method = clazz.getMethod("getTotalPhysicalMemorySize");
			maxMemory = (Long) method.invoke(operatingSystemMXBean) / 4;
		}
		catch (Throwable e) {
			throw new RuntimeException("Could not determine the amount of free memory.\n" +
					"Please set the maximum memory for the JVM, e.g. -Xmx512M for 512 megabytes.");
		}
	}
	
	return maxMemory;
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:26,代码来源:EnvironmentInformation.java

示例3: bindTo

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@Override
public void bindTo(MeterRegistry registry) {
    Runtime runtime = Runtime.getRuntime();

    Gauge.builder("system.cpu.count", runtime, Runtime::availableProcessors)
        .tags(tags)
        .description("The number of processors available to the Java virtual machine")
        .register(registry);

    OperatingSystemMXBean operatingSystemBean = ManagementFactory.getOperatingSystemMXBean();
    if(operatingSystemBean != null && operatingSystemBean.getSystemLoadAverage() >= 0) {
        Gauge.builder("system.load.average.1m", operatingSystemBean, OperatingSystemMXBean::getSystemLoadAverage)
            .tags(tags)
            .description("The sum of the number of runnable entities queued to available processors and the number " +
                "of runnable entities running on the available processors averaged over a period of time")
            .register(registry);
    }
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:19,代码来源:ProcessorMetrics.java

示例4: telnet

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@Override
   public String telnet(Channel channel, String message) {
	OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
   	double load;
   	try {
   	    Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
   	    load = (Double)method.invoke(operatingSystemMXBean, new Object[0]);
   	} catch (Throwable e) {
   	    load = -1;
   	}
   	int cpu = operatingSystemMXBean.getAvailableProcessors();
	return "load:[" + load + "] cpu:[" + cpu + "]";
}
 
开发者ID:tiglabs,项目名称:jsf-sdk,代码行数:14,代码来源:LoadTelnetHandler.java

示例5: TransmissionPhase

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public TransmissionPhase(MinebdConfig config, ExportProvider exportProvider) {
    super();
    this.maxUnflushedBytes = config.maxUnflushed.toBytes();
    this.minFreeSystemMem = config.minFreeSystemMem.toBytes();
    this.exportProvider = exportProvider;
    executor = new BlockingExecutor(10, 20);
    osBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
}
 
开发者ID:MineboxOS,项目名称:minebox,代码行数:9,代码来源:TransmissionPhase.java

示例6: setup

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@BeforeSuite
public static void setup() {
    java.lang.management.OperatingSystemMXBean bean =
            ManagementFactory.getOperatingSystemMXBean();
    if (bean instanceof OperatingSystemMXBean) {
        OperatingSystemMXBean os = (OperatingSystemMXBean)bean;
        long physicalMemorySize = os.getTotalPhysicalMemorySize() / (1024 * 1024);
        System.out.println("System memory size: " + physicalMemorySize + "M");
        // when we can get system memory size, and it's larger than 2G,
        // then we enable large array size test below,
        // else disable large array size test below.
        if (physicalMemorySize > (2 * 1024)) {
            arraySizeCollection  = new int[]{
                    SMALL_ARRAY_SIZE,
                    THRESHOLD_ARRAY_SIZE,
                    MEDIUM_ARRAY_SIZE,
                    LARGE_ARRAY_SIZE
                };
            System.out.println("System memory is large enough, add large array size test");
            return;
        }
    }
    arraySizeCollection  = new int[]{
            SMALL_ARRAY_SIZE,
            THRESHOLD_ARRAY_SIZE,
            MEDIUM_ARRAY_SIZE
        };
    System.out.println("System memory is not large enough, remove large array size test");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:ParallelPrefix.java

示例7: getTotalPhysicalMemorySize

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@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;
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:11,代码来源:StoreUtil.java

示例8: start

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void start() {
    if (started) throw new IllegalStateException("Already Started.");
    OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();

    lastSystemTime = System.nanoTime();
    lastProcessCpuTime = ((com.sun.management.OperatingSystemMXBean) os).getProcessCpuTime();

    Thread updater = new Thread(()->{
        cpuUsage = calculateCpuUsage(os);
    }, "AsyncInfoMonitor Updater");
    updater.setDaemon(true);
    updater.start();
    started = true;
}
 
开发者ID:natanbc,项目名称:GabrielBot,代码行数:15,代码来源:AsyncInfoMonitor.java

示例9: build

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public void build(String name, Map<Integer, List<float[]>> CachedList) throws UnknownHostException {
    com.sun.management.OperatingSystemMXBean operatingSystemMXBean =  (com.sun.management.OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean();
    long size = operatingSystemMXBean.getTotalPhysicalMemorySize() / 1024 / 1024 / 1024;
    this.nodeMemory = (int)size;
    nodeCore= Runtime.getRuntime().availableProcessors();
    nodeIP = InetAddress.getLocalHost().getHostAddress();
    nodeName = name;
    coreStatuses = new ArrayList<>();
    CachedList.forEach((e, v) -> {
        DataStatus status = new DataStatus();
        status.setCoreId(e);
        status.setSize(v.size());
        coreStatuses.add(status);
    });
}
 
开发者ID:Presageee,项目名称:DNCF,代码行数:16,代码来源:ClientInfo.java

示例10: systemInfo

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
/**
 *
 */
private static List<String> systemInfo() {
    String java = System.getProperty("java.home") + "/bin/java";
    RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
    OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
    List<String> jvmArgs = runtime.getInputArguments();

    REG_LOGGER.debug("JAVA_HOME     - " + java);
    REG_LOGGER.debug("ClassLoader   - " + runtime.getBootClassPath());
    REG_LOGGER.debug("ClassPath     - " + runtime.getClassPath());
    REG_LOGGER.debug("LibraryPath   - " + runtime.getLibraryPath());

    REG_LOGGER.debug("SYSTEM ARCH   - " + os.getArch());
    REG_LOGGER.debug("SYSTEM NAME   - " + os.getName());
    REG_LOGGER.debug("SYSTEM VERSION- " + os.getVersion());
    REG_LOGGER.debug("PROCESSORS    - " + os.getAvailableProcessors());

    for (int i = 0; i < jvmArgs.size(); i++) {
        REG_LOGGER.debug("JVM ARGS  - " + jvmArgs.get(i));
    }

    return Arrays.asList(
            "GPS server auto-restart has initiated",
            "JAVA_HOME     - " + java,
            "ClassLoader   - " + runtime.getBootClassPath(),
            "ClassPath     - " + runtime.getClassPath(),
            "LibraryPath   - " + runtime.getLibraryPath(),
            "SYSTEM ARCH   - " + os.getArch(),
            "SYSTEM NAME   - " + os.getName(),
            "SYSTEM VERSION- " + os.getVersion(),
            "PROCESSORS    - " + os.getAvailableProcessors()
    );
}
 
开发者ID:benj-c,项目名称:java-gps-tracking-server,代码行数:36,代码来源:MessageSenderConsumer.java

示例11: check

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public Status check() {
	OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
	double load;
	try {
	    Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
	    load = (Double)method.invoke(operatingSystemMXBean, new Object[0]);
	} catch (Throwable e) {
	    load = -1;
	}
	int cpu = operatingSystemMXBean.getAvailableProcessors();
    return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), "Load: " + load + " / CPU: " + cpu);
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:13,代码来源:LoadStatusChecker.java

示例12: getTotalPhysicalMemorySize

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@SuppressWarnings("restriction")
public static long getTotalPhysicalMemorySize() {
    long physicalTotal = 1024 * 1024 * 1024 * 24L;
    OperatingSystemMXBean osmxb = ManagementFactory.getOperatingSystemMXBean();
    if (osmxb instanceof com.sun.management.OperatingSystemMXBean) {
        physicalTotal = ((com.sun.management.OperatingSystemMXBean) osmxb).getTotalPhysicalMemorySize();
    }

    return physicalTotal;
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:11,代码来源:StoreUtil.java

示例13: check

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public Status check() {
    OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
    double load;
    try {
        Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
        load = (Double) method.invoke(operatingSystemMXBean, new Object[0]);
    } catch (Throwable e) {
        load = -1;
    }
    int cpu = operatingSystemMXBean.getAvailableProcessors();
    return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), "Load: " + load + " / CPU: " + cpu);
}
 
开发者ID:l1325169021,项目名称:github-test,代码行数:13,代码来源:LoadStatusChecker.java

示例14: check

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public Status check() {
	OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
	double load;
	try {
	    Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
	    load = (Double)method.invoke(operatingSystemMXBean, new Object[0]);
	} catch (Throwable e) {
	    load = -1;
	}
	int cpu = operatingSystemMXBean.getAvailableProcessors();
    return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), (load < 0 ? "" : "load:" + load + ",") + "cpu:" + cpu);
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:13,代码来源:LoadStatusChecker.java

示例15: getCurrentRamUsage

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
/**
 * Gets the current ram usage of this system
 *
 * @return The current usage in per cent
 */
public static int getCurrentRamUsage() {
    OperatingSystemMXBean bean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();

    long total = bean.getTotalPhysicalMemorySize() / 1024;
    long used = total - (bean.getFreePhysicalMemorySize() / 1024);

    return (int) (100D / (double)total * (double)used);
}
 
开发者ID:Superioz,项目名称:MooProject,代码行数:14,代码来源:SystemUtil.java


注:本文中的java.lang.management.ManagementFactory.getOperatingSystemMXBean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。