Search in sources :

Example 1 with HostStats

use of org.asynchttpclient.HostStats in project async-http-client by AsyncHttpClient.

the class ChannelManager method getClientStats.

public ClientStats getClientStats() {
    Map<String, Long> totalConnectionsPerHost = openChannels.stream().map(Channel::remoteAddress).filter(a -> a.getClass() == InetSocketAddress.class).map(a -> (InetSocketAddress) a).map(InetSocketAddress::getHostName).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
    Map<String, Long> idleConnectionsPerHost = channelPool.getIdleChannelCountPerHost();
    Map<String, HostStats> statsPerHost = totalConnectionsPerHost.entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> {
        final long totalConnectionCount = entry.getValue();
        final long idleConnectionCount = idleConnectionsPerHost.getOrDefault(entry.getKey(), 0L);
        final long activeConnectionCount = totalConnectionCount - idleConnectionCount;
        return new HostStats(activeConnectionCount, idleConnectionCount);
    }));
    return new ClientStats(statsPerHost);
}
Also used : TooManyConnectionsException(org.asynchttpclient.exception.TooManyConnectionsException) ChannelPoolPartitioning(org.asynchttpclient.channel.ChannelPoolPartitioning) DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) TooManyConnectionsPerHostException(org.asynchttpclient.exception.TooManyConnectionsPerHostException) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) LoggerFactory(org.slf4j.LoggerFactory) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) WebSocket08FrameDecoder(io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) GlobalEventExecutor(io.netty.util.concurrent.GlobalEventExecutor) AsyncHttpClientConfig(org.asynchttpclient.AsyncHttpClientConfig) Map(java.util.Map) ThreadFactory(java.util.concurrent.ThreadFactory) ChannelGroup(io.netty.channel.group.ChannelGroup) ChannelInitializer(io.netty.channel.ChannelInitializer) NettyResponseFuture(org.asynchttpclient.netty.NettyResponseFuture) WebSocketHandler(org.asynchttpclient.netty.handler.WebSocketHandler) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AsyncHandler(org.asynchttpclient.AsyncHandler) ChannelPipeline(io.netty.channel.ChannelPipeline) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ChannelPool(org.asynchttpclient.channel.ChannelPool) PoolAlreadyClosedException(org.asynchttpclient.exception.PoolAlreadyClosedException) SSLException(javax.net.ssl.SSLException) LogLevel(io.netty.handler.logging.LogLevel) SslHandler(io.netty.handler.ssl.SslHandler) Entry(java.util.Map.Entry) Timer(io.netty.util.Timer) ChannelOption(io.netty.channel.ChannelOption) LoggingHandler(io.netty.handler.logging.LoggingHandler) AsyncHttpClientHandler(org.asynchttpclient.netty.handler.AsyncHttpClientHandler) Function(java.util.function.Function) ClientStats(org.asynchttpclient.ClientStats) SSLEngine(javax.net.ssl.SSLEngine) NoopChannelPool(org.asynchttpclient.channel.NoopChannelPool) HttpHandler(org.asynchttpclient.netty.handler.HttpHandler) SslEngineFactory(org.asynchttpclient.SslEngineFactory) WebSocketFrameAggregator(io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator) ChannelFactory(io.netty.channel.ChannelFactory) WebSocket08FrameEncoder(io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder) EventLoopGroup(io.netty.channel.EventLoopGroup) Logger(org.slf4j.Logger) Semaphore(java.util.concurrent.Semaphore) DefaultSslEngineFactory(org.asynchttpclient.netty.ssl.DefaultSslEngineFactory) IOException(java.io.IOException) OioEventLoopGroup(io.netty.channel.oio.OioEventLoopGroup) HostStats(org.asynchttpclient.HostStats) ProxyServer(org.asynchttpclient.proxy.ProxyServer) Channel(io.netty.channel.Channel) TimeUnit(java.util.concurrent.TimeUnit) Bootstrap(io.netty.bootstrap.Bootstrap) AsyncHandlerExtensions(org.asynchttpclient.handler.AsyncHandlerExtensions) OnLastHttpContentCallback(org.asynchttpclient.netty.OnLastHttpContentCallback) Uri(org.asynchttpclient.uri.Uri) HttpContentDecompressor(io.netty.handler.codec.http.HttpContentDecompressor) NettyRequestSender(org.asynchttpclient.netty.request.NettyRequestSender) ThrowableUtil.unknownStackTrace(io.netty.util.internal.ThrowableUtil.unknownStackTrace) ClientStats(org.asynchttpclient.ClientStats) Channel(io.netty.channel.Channel) HostStats(org.asynchttpclient.HostStats)

Aggregations

Bootstrap (io.netty.bootstrap.Bootstrap)1 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)1 Channel (io.netty.channel.Channel)1 ChannelFactory (io.netty.channel.ChannelFactory)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 ChannelOption (io.netty.channel.ChannelOption)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 ChannelGroup (io.netty.channel.group.ChannelGroup)1 DefaultChannelGroup (io.netty.channel.group.DefaultChannelGroup)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 OioEventLoopGroup (io.netty.channel.oio.OioEventLoopGroup)1 HttpClientCodec (io.netty.handler.codec.http.HttpClientCodec)1 HttpContentDecompressor (io.netty.handler.codec.http.HttpContentDecompressor)1 WebSocket08FrameDecoder (io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder)1 WebSocket08FrameEncoder (io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder)1 WebSocketFrameAggregator (io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator)1 LogLevel (io.netty.handler.logging.LogLevel)1 LoggingHandler (io.netty.handler.logging.LoggingHandler)1 SslHandler (io.netty.handler.ssl.SslHandler)1