io.netty.buffer.ByteBufAllocatorMetric Java Examples

The following examples show how to use io.netty.buffer.ByteBufAllocatorMetric. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MemoryStat.java    From blynk-server with GNU General Public License v3.0 5 votes vote down vote up
public MemoryStat(ByteBufAllocator byteBufAllocator) {
    long directMemory = 0;
    long heapMemory = 0;

    if (byteBufAllocator instanceof ByteBufAllocatorMetricProvider) {
        ByteBufAllocatorMetric metric = ((ByteBufAllocatorMetricProvider) byteBufAllocator).metric();
        directMemory = metric.usedDirectMemory();
        heapMemory = metric.usedHeapMemory();
    }

    this.directBytes = directMemory;
    this.heapBytes = heapMemory;
}
 
Example #2
Source File: NettyAllocatorMetricSet.java    From styx with Apache License 2.0 4 votes vote down vote up
public NettyAllocatorMetricSet(String namespace,  ByteBufAllocatorMetric metric) {
    this.namespace = requireNonNull(namespace);
    this.metric = requireNonNull(metric);
}
 
Example #3
Source File: NettyAllocatorMetricSetTest.java    From styx with Apache License 2.0 4 votes vote down vote up
@BeforeEach
public void before() {
    metricUnderTest = Mockito.mock(ByteBufAllocatorMetric.class);
}
 
Example #4
Source File: ByteBufAllocatorMetrics.java    From reactor-netty with Apache License 2.0 4 votes vote down vote up
void registerMetrics(String allocType, ByteBufAllocatorMetric metrics) {
	cache.computeIfAbsent(metrics.hashCode() + "", key -> {
		String[] tags = new String[] {ID, key, TYPE, allocType};

		Gauge.builder(BYTE_BUF_ALLOCATOR_PREFIX + USED_HEAP_MEMORY, metrics, ByteBufAllocatorMetric::usedHeapMemory)
		     .description("The number of the bytes of the heap memory.")
		     .tags(tags)
		     .register(REGISTRY);

		Gauge.builder(BYTE_BUF_ALLOCATOR_PREFIX + USED_DIRECT_MEMORY, metrics, ByteBufAllocatorMetric::usedDirectMemory)
		     .description("The number of the bytes of the direct memory.")
		     .tags(tags)
		     .register(REGISTRY);

		if (metrics instanceof PooledByteBufAllocatorMetric) {
			PooledByteBufAllocatorMetric pooledMetrics = (PooledByteBufAllocatorMetric) metrics;

			Gauge.builder(BYTE_BUF_ALLOCATOR_PREFIX + HEAP_ARENAS, pooledMetrics, PooledByteBufAllocatorMetric::numHeapArenas)
			     .description("The number of heap arenas.")
			     .tags(tags)
			     .register(REGISTRY);

			Gauge.builder(BYTE_BUF_ALLOCATOR_PREFIX + DIRECT_ARENAS, pooledMetrics, PooledByteBufAllocatorMetric::numDirectArenas)
			     .description("The number of direct arenas.")
			     .tags(tags)
			     .register(REGISTRY);

			Gauge.builder(BYTE_BUF_ALLOCATOR_PREFIX + THREAD_LOCAL_CACHES, pooledMetrics, PooledByteBufAllocatorMetric::numThreadLocalCaches)
			     .description("The number of thread local caches.")
			     .tags(tags)
			     .register(REGISTRY);

			Gauge.builder(BYTE_BUF_ALLOCATOR_PREFIX + TINY_CACHE_SIZE, pooledMetrics, PooledByteBufAllocatorMetric::tinyCacheSize)
			     .description("The size of the tiny cache.")
			     .tags(tags)
			     .register(REGISTRY);

			Gauge.builder(BYTE_BUF_ALLOCATOR_PREFIX + SMALL_CACHE_SIZE, pooledMetrics, PooledByteBufAllocatorMetric::smallCacheSize)
			     .description("The size of the small cache.")
			     .tags(tags)
			     .register(REGISTRY);

			Gauge.builder(BYTE_BUF_ALLOCATOR_PREFIX + NORMAL_CACHE_SIZE, pooledMetrics, PooledByteBufAllocatorMetric::normalCacheSize)
			     .description("The size of the normal cache.")
			     .tags(tags)
			     .register(REGISTRY);

			Gauge.builder(BYTE_BUF_ALLOCATOR_PREFIX + CHUNK_SIZE, pooledMetrics, PooledByteBufAllocatorMetric::chunkSize)
			     .description("The chunk size for an arena.")
			     .tags(tags)
			     .register(REGISTRY);
		}

		return metrics;
	});
}