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);
}
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");
}
}
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);
}
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();
}
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);
}
Aggregations