Search in sources :

Example 16 with OperatingSystemMXBean

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");
    }
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) RuntimeMXBean(java.lang.management.RuntimeMXBean) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) IOException(java.io.IOException)

Example 17 with OperatingSystemMXBean

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;
}
Also used : Method(java.lang.reflect.Method) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) IOException(java.io.IOException)

Example 18 with OperatingSystemMXBean

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;
}
Also used : OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 19 with OperatingSystemMXBean

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();
}
Also used : OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) Test(org.junit.jupiter.api.Test)

Example 20 with OperatingSystemMXBean

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;
}
Also used : OsInfo(com.serotonin.m2m2.module.definitions.settings.OperatingSystemInfoDefinition.OsInfo) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Aggregations

OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)88 RuntimeMXBean (java.lang.management.RuntimeMXBean)26 Method (java.lang.reflect.Method)20 IOException (java.io.IOException)15 MemoryMXBean (java.lang.management.MemoryMXBean)11 MemoryUsage (java.lang.management.MemoryUsage)8 ThreadMXBean (java.lang.management.ThreadMXBean)8 HashMap (java.util.HashMap)8 UnixOperatingSystemMXBean (com.sun.management.UnixOperatingSystemMXBean)7 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)6 Status (com.alibaba.dubbo.common.status.Status)5 File (java.io.File)5 LinkedHashMap (java.util.LinkedHashMap)5 Map (java.util.Map)5 Test (org.junit.Test)5 Test (org.testng.annotations.Test)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 UnknownHostException (java.net.UnknownHostException)4 Date (java.util.Date)4 ExtendedOperatingSystemMXBeanImpl (com.ibm.lang.management.internal.ExtendedOperatingSystemMXBeanImpl)3