Search in sources :

Example 56 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project asterixdb by apache.

the class NCServiceTest method testJvmArgs.

@Test
public void testJvmArgs() {
    Map<String, String> configuration = new HashMap<>();
    OperatingSystemMXBean osMXBean = ManagementFactory.getOperatingSystemMXBean();
    PA.setValue(NCService.class, "nodeSection", "nc/nc1");
    PA.setValue(NCService.class, "osMXBean", osMXBean);
    PA.invokeMethod(NCService.class, "configEnvironment(java.util.Map)", configuration);
    String javaOpts = configuration.get("JAVA_OPTS");
    String prefix = javaOpts.substring(4);
    String sizeStr = prefix.substring(0, prefix.length() - 1);
    int size = Integer.parseInt(sizeStr);
    long ramSize = ((com.sun.management.OperatingSystemMXBean) osMXBean).getTotalPhysicalMemorySize();
    int base = 1024 * 1024 * 5;
    Assert.assertTrue(size == ramSize * 3 / base + ((ramSize * 3) % base == 0 ? 0 : 1));
}
Also used : HashMap(java.util.HashMap) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) Test(org.junit.Test)

Example 57 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project asterixdb by apache.

the class GetNodeDetailsJSONWork method getCCDetails.

private ObjectNode getCCDetails() {
    ObjectNode o = om.createObjectNode();
    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    List<GarbageCollectorMXBean> gcMXBeans = ManagementFactory.getGarbageCollectorMXBeans();
    ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
    OperatingSystemMXBean osMXBean = ManagementFactory.getOperatingSystemMXBean();
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    if (includeConfig) {
        o.put("os_name", osMXBean.getName());
        o.put("arch", osMXBean.getArch());
        o.put("os_version", osMXBean.getVersion());
        o.put("num_processors", osMXBean.getAvailableProcessors());
        o.put("vm_name", runtimeMXBean.getVmName());
        o.put("vm_version", runtimeMXBean.getVmVersion());
        o.put("vm_vendor", runtimeMXBean.getVmVendor());
        o.putPOJO("classpath", runtimeMXBean.getClassPath().split(File.pathSeparator));
        o.putPOJO("library_path", runtimeMXBean.getLibraryPath().split(File.pathSeparator));
        o.putPOJO("boot_classpath", runtimeMXBean.getBootClassPath().split(File.pathSeparator));
        o.putPOJO("input_arguments", runtimeMXBean.getInputArguments());
        o.putPOJO("system_properties", runtimeMXBean.getSystemProperties());
        o.put("pid", PidHelper.getPid());
    }
    if (includeStats) {
        MemoryUsage heapUsage = memoryMXBean.getHeapMemoryUsage();
        MemoryUsage nonheapUsage = memoryMXBean.getNonHeapMemoryUsage();
        List<ObjectNode> gcs = new ArrayList<>();
        for (GarbageCollectorMXBean gcMXBean : gcMXBeans) {
            ObjectNode gc = om.createObjectNode();
            gc.put("name", gcMXBean.getName());
            gc.put("collection-time", gcMXBean.getCollectionTime());
            gc.put("collection-count", gcMXBean.getCollectionCount());
            gcs.add(gc);
        }
        o.putPOJO("gcs", gcs);
        o.put("date", new Date().toString());
        o.put("heap_init_size", heapUsage.getInit());
        o.put("heap_used_size", heapUsage.getUsed());
        o.put("heap_committed_size", heapUsage.getCommitted());
        o.put("heap_max_size", heapUsage.getMax());
        o.put("nonheap_init_size", nonheapUsage.getInit());
        o.put("nonheap_used_size", nonheapUsage.getUsed());
        o.put("nonheap_committed_size", nonheapUsage.getCommitted());
        o.put("nonheap_max_size", nonheapUsage.getMax());
        o.put("thread_count", threadMXBean.getThreadCount());
        o.put("peak_thread_count", threadMXBean.getPeakThreadCount());
        o.put("started_thread_count", threadMXBean.getTotalStartedThreadCount());
        o.put("system_load_average", osMXBean.getSystemLoadAverage());
    }
    return o;
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) MemoryMXBean(java.lang.management.MemoryMXBean) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) ArrayList(java.util.ArrayList) RuntimeMXBean(java.lang.management.RuntimeMXBean) MemoryUsage(java.lang.management.MemoryUsage) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) Date(java.util.Date)

Example 58 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project lucene-solr by apache.

the class OperatingSystemMetricSet method getMetrics.

@Override
public Map<String, Metric> getMetrics() {
    final Map<String, Metric> metrics = new HashMap<>();
    OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
    MetricUtils.addMXBeanMetrics(os, MetricUtils.OS_MXBEAN_CLASSES, null, (k, v) -> {
        if (!metrics.containsKey(k)) {
            metrics.put(k, v);
        }
    });
    return metrics;
}
Also used : HashMap(java.util.HashMap) Metric(com.codahale.metrics.Metric) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 59 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project lucene-solr by apache.

the class SystemInfoHandler method getSystemInfo.

/**
   * Get system info
   */
public static SimpleOrderedMap<Object> getSystemInfo() {
    SimpleOrderedMap<Object> info = new SimpleOrderedMap<>();
    OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
    // add at least this one
    info.add(NAME, os.getName());
    // add remaining ones dynamically using Java Beans API
    // also those from JVM implementation-specific classes
    MetricUtils.addMXBeanMetrics(os, MetricUtils.OS_MXBEAN_CLASSES, null, (name, metric) -> {
        if (info.get(name) == null) {
            info.add(name, ((Gauge) metric).getValue());
        }
    });
    // Try some command line things:
    try {
        if (!Constants.WINDOWS) {
            info.add("uname", execute("uname -a"));
            info.add("uptime", execute("uptime"));
        }
    } catch (Exception ex) {
        log.warn("Unable to execute command line tools to get operating system properties.", ex);
    }
    return info;
}
Also used : SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) IOException(java.io.IOException)

Example 60 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project tdi-studio-se by Talend.

the class HeapHistogramPage method isSupported.

/**
     * Gets the state indicating if heap histogram is supported.
     * <p>
     * WORKAROUND: Heap histogram is disabled on 64bit OS when monitoring eclipse itself, due to the issue that the
     * method heapHisto() of the class HotSpotVirtualMachine causes continuously increasing the committed heap memory.
     * 
     * @return <tt>true</tt> if heap histogram is supported
     */
boolean isSupported() {
    IActiveJvm jvm = section.getJvm();
    if (jvm == null) {
        return false;
    }
    OperatingSystemMXBean osMBean = ManagementFactory.getOperatingSystemMXBean();
    RuntimeMXBean runtimeMBean = ManagementFactory.getRuntimeMXBean();
    if (osMBean.getArch().contains(ARCH_64BIT) && runtimeMBean.getName().contains(String.valueOf(jvm.getPid()))) {
        return false;
    }
    return true;
}
Also used : IActiveJvm(org.talend.designer.runtime.visualization.IActiveJvm) RuntimeMXBean(java.lang.management.RuntimeMXBean) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Aggregations

OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)89 RuntimeMXBean (java.lang.management.RuntimeMXBean)27 Method (java.lang.reflect.Method)20 IOException (java.io.IOException)15 MemoryMXBean (java.lang.management.MemoryMXBean)12 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