Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Http stats and stats per route extractor
public Runnable connectionPoolMetricsLogger(final PoolingHttpClientConnectionManager connectionManager) {
return new Runnable() {
@Override
@Scheduled(fixedDelay = 30000)
public void run() {
final StringBuilder buffer = new StringBuilder();
try {
if (connectionManager != null) {
final PoolStats totalPoolStats = connectionManager.getTotalStats();
log.info(" ** HTTP Client Connection Pool Stats : Available = {}, Leased = {}, Pending = {}, Max = {} **",
totalPoolStats.getAvailable(), totalPoolStats.getLeased(), totalPoolStats.getPending(), totalPoolStats.getMax());
connectionManager
.getRoutes()
.stream()
.forEach(route -> {
final PoolStats routeStats = connectionManager.getStats(route);
buffer
.append(" ++ HTTP Client Connection Pool Route Pool Stats ++ ")
.append(" Route : " + route.toString())
.append(" Available : " + routeStats.getAvailable())
.append(" Leased : " + routeStats.getLeased())
.append(" Pending : " + routeStats.getPending())
.append(" Max : " + routeStats.getMax());
});
log.info(buffer.toString());
}
} catch (Exception e) {
log.error("Exception occurred whilst logging http connection pool stats. msg = {}, e = {}", e.getMessage(), e);
}
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.