本文整理汇总了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;
}
示例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;
}
示例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);
}
}
示例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 + "]";
}
示例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();
}
示例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");
}
示例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;
}
示例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;
}
示例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);
});
}
示例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()
);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}