Skip to content

Instantly share code, notes, and snippets.

@dhaval201279
Created May 17, 2020 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhaval201279/4b64a176fdb7a80ca7acdcc17e14e157 to your computer and use it in GitHub Desktop.
Save dhaval201279/4b64a176fdb7a80ca7acdcc17e14e157 to your computer and use it in GitHub Desktop.
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