Search in sources :

Example 1 with ByteBufAllocatorMetric

use of io.netty.buffer.ByteBufAllocatorMetric in project reactor-netty by reactor.

the class ByteBufAllocatorMetrics method registerMetrics.

void registerMetrics(String allocType, ByteBufAllocatorMetric metrics, ByteBufAllocator alloc) {
    MapUtils.computeIfAbsent(cache, metrics.hashCode() + "", key -> {
        Tags tags = Tags.of(ID.getKey(), key, TYPE.getKey(), allocType);
        Gauge.builder(USED_HEAP_MEMORY.getName(), metrics, ByteBufAllocatorMetric::usedHeapMemory).tags(tags).register(REGISTRY);
        Gauge.builder(USED_DIRECT_MEMORY.getName(), metrics, ByteBufAllocatorMetric::usedDirectMemory).tags(tags).register(REGISTRY);
        if (metrics instanceof PooledByteBufAllocatorMetric) {
            PooledByteBufAllocatorMetric pooledMetrics = (PooledByteBufAllocatorMetric) metrics;
            PooledByteBufAllocator pooledAlloc = (PooledByteBufAllocator) alloc;
            Gauge.builder(HEAP_ARENAS.getName(), pooledMetrics, PooledByteBufAllocatorMetric::numHeapArenas).tags(tags).register(REGISTRY);
            Gauge.builder(DIRECT_ARENAS.getName(), pooledMetrics, PooledByteBufAllocatorMetric::numDirectArenas).tags(tags).register(REGISTRY);
            Gauge.builder(THREAD_LOCAL_CACHES.getName(), pooledMetrics, PooledByteBufAllocatorMetric::numThreadLocalCaches).tags(tags).register(REGISTRY);
            Gauge.builder(SMALL_CACHE_SIZE.getName(), pooledMetrics, PooledByteBufAllocatorMetric::smallCacheSize).tags(tags).register(REGISTRY);
            Gauge.builder(NORMAL_CACHE_SIZE.getName(), pooledMetrics, PooledByteBufAllocatorMetric::normalCacheSize).tags(tags).register(REGISTRY);
            Gauge.builder(CHUNK_SIZE.getName(), pooledMetrics, PooledByteBufAllocatorMetric::chunkSize).tags(tags).register(REGISTRY);
            Gauge.builder(ACTIVE_HEAP_MEMORY.getName(), pooledAlloc, PooledByteBufAllocator::pinnedHeapMemory).tags(tags).register(REGISTRY);
            Gauge.builder(ACTIVE_DIRECT_MEMORY.getName(), pooledAlloc, PooledByteBufAllocator::pinnedDirectMemory).tags(tags).register(REGISTRY);
        }
        return metrics;
    });
}
Also used : PooledByteBufAllocatorMetric(io.netty.buffer.PooledByteBufAllocatorMetric) ByteBufAllocatorMetric(io.netty.buffer.ByteBufAllocatorMetric) PooledByteBufAllocatorMetric(io.netty.buffer.PooledByteBufAllocatorMetric) Tags(io.micrometer.api.instrument.Tags) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator)

Example 2 with ByteBufAllocatorMetric

use of io.netty.buffer.ByteBufAllocatorMetric in project ratpack by ratpack.

the class UnpooledByteBufAllocatorMetricSet method initMetrics.

private void initMetrics() {
    final ByteBufAllocatorMetric metric = unpooledByteBufAllocator.metric();
    metrics.put("usedDirectMemory", (Gauge<Long>) () -> metric.usedDirectMemory());
    metrics.put("usedHeapMemory", (Gauge<Long>) () -> metric.usedHeapMemory());
}
Also used : ByteBufAllocatorMetric(io.netty.buffer.ByteBufAllocatorMetric)

Example 3 with ByteBufAllocatorMetric

use of io.netty.buffer.ByteBufAllocatorMetric in project zuul by Netflix.

the class Server method start.

public void start() {
    serverGroup = new ServerGroup("Salamander", eventLoopConfig.acceptorCount(), eventLoopConfig.eventLoopCount(), eventLoopGroupMetrics);
    serverGroup.initializeTransport();
    try {
        List<ChannelFuture> allBindFutures = new ArrayList<>(addressesToInitializers.size());
        // Setup each of the channel initializers on requested ports.
        for (Map.Entry<NamedSocketAddress, ? extends ChannelInitializer<?>> entry : addressesToInitializers.entrySet()) {
            NamedSocketAddress requestedNamedAddr = entry.getKey();
            ChannelFuture nettyServerFuture = setupServerBootstrap(requestedNamedAddr, entry.getValue());
            Channel chan = nettyServerFuture.channel();
            addressesToChannels.put(requestedNamedAddr.withNewSocket(chan.localAddress()), chan);
            allBindFutures.add(nettyServerFuture);
        }
        // Add metrics to monitor that allocator's memory usage.
        if (!allBindFutures.isEmpty()) {
            ByteBufAllocator alloc = allBindFutures.get(0).channel().alloc();
            if (alloc instanceof ByteBufAllocatorMetricProvider) {
                ByteBufAllocatorMetric metrics = ((ByteBufAllocatorMetricProvider) alloc).metric();
                PolledMeter.using(registry).withId(registry.createId("zuul.nettybuffermem.live", "type", "heap")).monitorValue(metrics, ByteBufAllocatorMetric::usedHeapMemory);
                PolledMeter.using(registry).withId(registry.createId("zuul.nettybuffermem.live", "type", "direct")).monitorValue(metrics, ByteBufAllocatorMetric::usedDirectMemory);
            }
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) ByteBufAllocatorMetric(io.netty.buffer.ByteBufAllocatorMetric) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) ByteBufAllocatorMetricProvider(io.netty.buffer.ByteBufAllocatorMetricProvider) IOUringServerSocketChannel(io.netty.incubator.channel.uring.IOUringServerSocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) ServerChannel(io.netty.channel.ServerChannel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) KQueueServerSocketChannel(io.netty.channel.kqueue.KQueueServerSocketChannel) EpollSocketChannel(io.netty.channel.epoll.EpollSocketChannel) EpollServerSocketChannel(io.netty.channel.epoll.EpollServerSocketChannel) KQueueSocketChannel(io.netty.channel.kqueue.KQueueSocketChannel) IOUringSocketChannel(io.netty.incubator.channel.uring.IOUringSocketChannel) Channel(io.netty.channel.Channel) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ByteBufAllocatorMetric (io.netty.buffer.ByteBufAllocatorMetric)3 Tags (io.micrometer.api.instrument.Tags)1 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)1 ByteBufAllocatorMetricProvider (io.netty.buffer.ByteBufAllocatorMetricProvider)1 PooledByteBufAllocator (io.netty.buffer.PooledByteBufAllocator)1 PooledByteBufAllocatorMetric (io.netty.buffer.PooledByteBufAllocatorMetric)1 Channel (io.netty.channel.Channel)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ServerChannel (io.netty.channel.ServerChannel)1 EpollServerSocketChannel (io.netty.channel.epoll.EpollServerSocketChannel)1 EpollSocketChannel (io.netty.channel.epoll.EpollSocketChannel)1 KQueueServerSocketChannel (io.netty.channel.kqueue.KQueueServerSocketChannel)1 KQueueSocketChannel (io.netty.channel.kqueue.KQueueSocketChannel)1 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 IOUringServerSocketChannel (io.netty.incubator.channel.uring.IOUringServerSocketChannel)1 IOUringSocketChannel (io.netty.incubator.channel.uring.IOUringSocketChannel)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1