/** Captures the connection pool metrics. */ private void captureConnectionPoolMetrics( ClientConnectionManager connectionManager, AWSRequestMetrics awsRequestMetrics) { if (awsRequestMetrics.isEnabled() && connectionManager instanceof ConnPoolControl) { ConnPoolControl<?> control = (ConnPoolControl<?>) connectionManager; PoolStats stats = control.getTotalStats(); awsRequestMetrics.setCounter( AWSRequestMetrics.Field.HttpClientPoolAvailableCount, stats.getAvailable()); awsRequestMetrics.setCounter( AWSRequestMetrics.Field.HttpClientPoolLeasedCount, stats.getLeased()); awsRequestMetrics.setCounter( AWSRequestMetrics.Field.HttpClientPoolPendingCount, stats.getPending()); } }
private String formatStats(final HttpRoute route) { final StringBuilder buf = new StringBuilder(); final PoolStats totals = this.pool.getTotalStats(); final PoolStats stats = this.pool.getStats(route); buf.append("[total kept alive: ").append(totals.getAvailable()).append("; "); buf.append("route allocated: ").append(stats.getLeased() + stats.getAvailable()); buf.append(" of ").append(stats.getMax()).append("; "); buf.append("total allocated: ").append(totals.getLeased() + totals.getAvailable()); buf.append(" of ").append(totals.getMax()).append("]"); return buf.toString(); }
/** * Forgive me these sins. This is the only way I can think of to determine the *actual* size of * the connection pool without wrapping large quantities of the underlying client. * * <p>This whole method is cheating and full of bad examples. Don't copy this. You've been warned. */ private int getPoolSize(JestHttpClient client) throws Exception { try { Field fieldHttpClient = client.getClass().getDeclaredField("httpClient"); fieldHttpClient.setAccessible(true); Object objInternalHttpClient = fieldHttpClient.get(client); Field fieldConnectionManager = objInternalHttpClient.getClass().getDeclaredField("connManager"); fieldConnectionManager.setAccessible(true); PoolingHttpClientConnectionManager poolingHttpClientConnectionManager = (PoolingHttpClientConnectionManager) fieldConnectionManager.get(objInternalHttpClient); PoolStats poolStats = poolingHttpClientConnectionManager.getTotalStats(); return poolStats.getAvailable() + poolStats.getLeased(); } catch (Exception e) { e.printStackTrace(); } return -1; }