类io.netty.buffer.ByteBufAllocatorMetric源码实例Demo

下面列出了怎么用io.netty.buffer.ByteBufAllocatorMetric的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: blynk-server   文件: MemoryStat.java
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;
}
 
源代码2 项目: styx   文件: NettyAllocatorMetricSet.java
public NettyAllocatorMetricSet(String namespace,  ByteBufAllocatorMetric metric) {
    this.namespace = requireNonNull(namespace);
    this.metric = requireNonNull(metric);
}
 
源代码3 项目: styx   文件: NettyAllocatorMetricSetTest.java
@BeforeEach
public void before() {
    metricUnderTest = Mockito.mock(ByteBufAllocatorMetric.class);
}
 
源代码4 项目: reactor-netty   文件: ByteBufAllocatorMetrics.java
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;
	});
}