Search in sources :

Example 81 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project hazelcast by hazelcast.

the class OperatingSystemMetricSet method register.

/**
 * Registers all the metrics in this metrics pack.
 *
 * @param metricsRegistry the MetricsRegistry upon which the metrics are registered.
 */
public static void register(MetricsRegistry metricsRegistry) {
    checkNotNull(metricsRegistry, "metricsRegistry");
    OperatingSystemMXBean mxBean = ManagementFactory.getOperatingSystemMXBean();
    registerMethod(metricsRegistry, mxBean, "getCommittedVirtualMemorySize", OS_FULL_METRIC_COMMITTED_VIRTUAL_MEMORY_SIZE);
    registerMethod(metricsRegistry, mxBean, "getFreePhysicalMemorySize", OS_FULL_METRIC_FREE_PHYSICAL_MEMORY_SIZE);
    registerMethod(metricsRegistry, mxBean, "getFreeSwapSpaceSize", OS_FULL_METRIC_FREE_SWAP_SPACE_SIZE);
    registerMethod(metricsRegistry, mxBean, "getProcessCpuTime", OS_FULL_METRIC_PROCESS_CPU_TIME);
    registerMethod(metricsRegistry, mxBean, "getTotalPhysicalMemorySize", OS_FULL_METRIC_TOTAL_PHYSICAL_MEMORY_SIZE);
    registerMethod(metricsRegistry, mxBean, "getTotalSwapSpaceSize", OS_FULL_METRIC_TOTAL_SWAP_SPACE_SIZE);
    registerMethod(metricsRegistry, mxBean, "getMaxFileDescriptorCount", OS_FULL_METRIC_MAX_FILE_DESCRIPTOR_COUNT);
    registerMethod(metricsRegistry, mxBean, "getOpenFileDescriptorCount", OS_FULL_METRIC_OPEN_FILE_DESCRIPTOR_COUNT);
    // value will be between 0.0 and 1.0 or a negative value, if not available
    registerMethod(metricsRegistry, mxBean, "getProcessCpuLoad", OS_FULL_METRIC_PROCESS_CPU_LOAD, PERCENTAGE_MULTIPLIER);
    // value will be between 0.0 and 1.0 or a negative value, if not available
    registerMethod(metricsRegistry, mxBean, "getSystemCpuLoad", OS_FULL_METRIC_SYSTEM_CPU_LOAD, PERCENTAGE_MULTIPLIER);
    metricsRegistry.registerStaticProbe(mxBean, OS_FULL_METRIC_SYSTEM_LOAD_AVERAGE, MANDATORY, OperatingSystemMXBean::getSystemLoadAverage);
}
Also used : OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 82 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project hazelcast by hazelcast.

the class OperatingSystemMetricSetTest method assumeOperatingSystemMXBeanType.

private void assumeOperatingSystemMXBeanType(String expected) {
    OperatingSystemMXBean bean = ManagementFactory.getOperatingSystemMXBean();
    try {
        Class<?> expectedInterface = Class.forName(expected);
        assumeTrue(expectedInterface.isAssignableFrom(bean.getClass()));
    } catch (ClassNotFoundException e) {
        throw new AssumptionViolatedException("MXBean interface " + expected + " was not found");
    }
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 83 with OperatingSystemMXBean

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

the class LlapDaemonJvmMetrics method getJvmMetrics.

private void getJvmMetrics(final MetricsRecordBuilder rb) {
    List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
    long directBufferCount = 0;
    long directBufferTotalCapacity = 0;
    long directBufferMemoryUsed = 0;
    long mappedBufferCount = 0;
    long mappedBufferTotalCapacity = 0;
    long mappedBufferMemoryUsed = 0;
    for (BufferPoolMXBean pool : pools) {
        if (pool.getName().equals("direct")) {
            directBufferCount = pool.getCount();
            directBufferTotalCapacity = pool.getTotalCapacity();
            directBufferMemoryUsed = pool.getMemoryUsed();
        } else if (pool.getName().equals("mapped")) {
            mappedBufferCount = pool.getCount();
            mappedBufferTotalCapacity = pool.getTotalCapacity();
            mappedBufferMemoryUsed = pool.getMemoryUsed();
        }
    }
    OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
    long openFileHandles = 0;
    long maxFileHandles = 0;
    if (os instanceof UnixOperatingSystemMXBean) {
        openFileHandles = ((UnixOperatingSystemMXBean) os).getOpenFileDescriptorCount();
        maxFileHandles = ((UnixOperatingSystemMXBean) os).getMaxFileDescriptorCount();
        maxOpenFdCountSoFar = openFileHandles > maxOpenFdCountSoFar ? openFileHandles : maxOpenFdCountSoFar;
    }
    long rss = 0;
    long vmem = 0;
    if (processTree != null) {
        rss = processTree.getRssMemorySize();
        vmem = processTree.getVirtualMemorySize();
    }
    rb.addGauge(LlapDaemonDirectBufferCount, directBufferCount).addGauge(LlapDaemonDirectBufferTotalCapacity, directBufferTotalCapacity).addGauge(LlapDaemonDirectBufferMemoryUsed, directBufferMemoryUsed).addGauge(LlapDaemonMappedBufferCount, mappedBufferCount).addGauge(LlapDaemonMappedBufferTotalCapacity, mappedBufferTotalCapacity).addGauge(LlapDaemonMappedBufferMemoryUsed, mappedBufferMemoryUsed).addGauge(LlapDaemonOpenFileDescriptorCount, openFileHandles).addGauge(LlapDaemonMaxFileDescriptorCount, maxOpenFdCountSoFar).addGauge(LlapDaemonLimitFileDescriptorCount, maxFileHandles).addGauge(LlapDaemonResidentSetSize, rss).addGauge(LlapDaemonVirtualMemorySize, vmem);
}
Also used : UnixOperatingSystemMXBean(com.sun.management.UnixOperatingSystemMXBean) BufferPoolMXBean(java.lang.management.BufferPoolMXBean) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) UnixOperatingSystemMXBean(com.sun.management.UnixOperatingSystemMXBean)

Example 84 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project sonarqube by SonarSource.

the class JvmStateSection method toProtobuf.

// Visible for testing
ProtobufSystemInfo.Section toProtobuf(MemoryMXBean memoryBean) {
    ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder();
    protobuf.setName(name);
    addAttributeInMb(protobuf, "Max Memory (MB)", Runtime.getRuntime().maxMemory());
    addAttributeInMb(protobuf, "Free Memory (MB)", Runtime.getRuntime().freeMemory());
    MemoryUsage heap = memoryBean.getHeapMemoryUsage();
    addAttributeInMb(protobuf, "Heap Committed (MB)", heap.getCommitted());
    addAttributeInMb(protobuf, "Heap Init (MB)", heap.getInit());
    addAttributeInMb(protobuf, "Heap Max (MB)", heap.getMax());
    addAttributeInMb(protobuf, "Heap Used (MB)", heap.getUsed());
    MemoryUsage nonHeap = memoryBean.getNonHeapMemoryUsage();
    addAttributeInMb(protobuf, "Non Heap Committed (MB)", nonHeap.getCommitted());
    addAttributeInMb(protobuf, "Non Heap Init (MB)", nonHeap.getInit());
    addAttributeInMb(protobuf, "Non Heap Max (MB)", nonHeap.getMax());
    addAttributeInMb(protobuf, "Non Heap Used (MB)", nonHeap.getUsed());
    OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
    setAttribute(protobuf, "System Load Average", format(Locale.ENGLISH, "%.1f%% (last minute)", os.getSystemLoadAverage() * 100.0));
    ThreadMXBean thread = ManagementFactory.getThreadMXBean();
    setAttribute(protobuf, "Threads", thread.getThreadCount());
    return protobuf.build();
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) MemoryUsage(java.lang.management.MemoryUsage) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 85 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project metrics by dropwizard.

the class FileDescriptorRatioGaugeTest method validateFileDescriptorRatioPresenceOnNixPlatforms.

@Test
public void validateFileDescriptorRatioPresenceOnNixPlatforms() {
    OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
    assumeTrue(osBean instanceof com.sun.management.UnixOperatingSystemMXBean);
    assertThat(new FileDescriptorRatioGauge().getValue()).isGreaterThanOrEqualTo(0.0).isLessThanOrEqualTo(1.0);
}
Also used : UnixOperatingSystemMXBean(com.sun.management.UnixOperatingSystemMXBean) UnixOperatingSystemMXBean(com.sun.management.UnixOperatingSystemMXBean) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) Test(org.junit.Test)

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