use of java.lang.management.OperatingSystemMXBean in project traccar by traccar.
the class Log method logSystemInfo.
public static void logSystemInfo() {
try {
OperatingSystemMXBean operatingSystemBean = ManagementFactory.getOperatingSystemMXBean();
Log.info("Operating system" + " name: " + operatingSystemBean.getName() + " version: " + operatingSystemBean.getVersion() + " architecture: " + operatingSystemBean.getArch());
RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
Log.info("Java runtime" + " name: " + runtimeBean.getVmName() + " vendor: " + runtimeBean.getVmVendor() + " version: " + runtimeBean.getVmVersion());
MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
Log.info("Memory limit" + " heap: " + memoryBean.getHeapMemoryUsage().getMax() / (1024 * 1024) + "mb" + " non-heap: " + memoryBean.getNonHeapMemoryUsage().getMax() / (1024 * 1024) + "mb");
Log.info("Character encoding: " + System.getProperty("file.encoding") + " charset: " + Charset.defaultCharset());
} catch (Exception error) {
Log.warning("Failed to get system info");
}
}
use of java.lang.management.OperatingSystemMXBean in project h2database by h2database.
the class Utils method scaleForAvailableMemory.
/**
* Scale the value with the available memory. If 1 GB of RAM is available,
* the value is returned, if 2 GB are available, then twice the value, and
* so on.
*
* @param value the value to scale
* @return the scaled value
*/
public static int scaleForAvailableMemory(int value) {
long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory != Long.MAX_VALUE) {
// we are limited by an -XmX parameter
return (int) (value * maxMemory / (1024 * 1024 * 1024));
}
try {
OperatingSystemMXBean mxBean = ManagementFactory.getOperatingSystemMXBean();
// this method is only available on the class
// com.sun.management.OperatingSystemMXBean, which mxBean
// is an instance of under the Oracle JDK, but it is not present on
// Android and other JDK's
Method method = Class.forName("com.sun.management.OperatingSystemMXBean").getMethod("getTotalPhysicalMemorySize");
long physicalMemorySize = ((Number) method.invoke(mxBean)).longValue();
return (int) (value * physicalMemorySize / (1024 * 1024 * 1024));
} catch (Exception e) {
// ignore
}
return value;
}
use of java.lang.management.OperatingSystemMXBean in project mlib by myshzzx.
the class Oss method getOS.
/**
* get os.
*/
public static OS getOS() {
if (currOs != null)
return currOs;
OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
String osName = osBean.getName().toLowerCase();
if (osName.contains("windows"))
currOs = OS.Windows;
else if (osName.contains("linux"))
currOs = OS.Linux;
else if (osName.contains("mac"))
currOs = OS.Mac;
else if (osName.contains("unix"))
currOs = OS.Unix;
else
currOs = OS.Unknown;
return currOs;
}
use of java.lang.management.OperatingSystemMXBean in project micrometer by micrometer-metrics.
the class FileDescriptorMetricsTest method fileDescriptorMetricsUnsupportedOsBeanMock.
@Test
void fileDescriptorMetricsUnsupportedOsBeanMock() {
final OperatingSystemMXBean osBean = mock(UnsupportedOperatingSystemMXBean.class);
new FileDescriptorMetrics(osBean, Tags.of("some", "tag")).bindTo(registry);
assertThat(registry.find("process.files.open").gauge()).isNull();
assertThat(registry.find("process.files.max").gauge()).isNull();
}
use of java.lang.management.OperatingSystemMXBean in project ma-core-public by infiniteautomation.
the class OperatingSystemInfoDefinition method getValue.
/* (non-Javadoc)
* @see com.serotonin.m2m2.module.ReadOnlySettingDefinition#getValue()
*/
@Override
public OsInfo getValue() {
OsInfo info = new OsInfo();
OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
if (osBean != null) {
info.setArchitecture(osBean.getArch());
info.setOperatingSystem(osBean.getName());
info.setOsVersion(osBean.getVersion());
}
return info;
}
Aggregations