Created
May 17, 2020 11:48
-
-
Save dhaval201279/4b64a176fdb7a80ca7acdcc17e14e157 to your computer and use it in GitHub Desktop.
Http stats and stats per route extractor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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