Last active
October 25, 2021 07:34
-
-
Save ravin-singh/8654b654163c508cdb227a621fe078f0 to your computer and use it in GitHub Desktop.
Micrometer metrics exporter for apache http connection pool
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
1. Create a scheduler to add new routes | |
@Scheduled(fixedRate = 300000) | |
public void updateHttpRoutes() { | |
Set<HttpRoute> routes = poolingHttpClientConnectionManager.getRoutes(); | |
for (HttpRoute route : routes) { | |
httpMetricsTracker.add(route, poolingHttpClientConnectionManager); | |
} | |
} |
public class HttpPoolStats {
private final HttpRoute httpRoute;
private final PoolingHttpClientConnectionManager poolingHttpClientConnectionManager;
public HttpPoolStats(HttpRoute httpRoute, PoolingHttpClientConnectionManager poolingHttpClientConnectionManager) {
this.httpRoute = httpRoute;
this.poolingHttpClientConnectionManager = poolingHttpClientConnectionManager;
}
public int getLeased() {
return poolingHttpClientConnectionManager.getStats(httpRoute).getLeased();
}
public int getPending() {
return poolingHttpClientConnectionManager.getStats(httpRoute).getPending();
}
public int getAvailable() {
return poolingHttpClientConnectionManager.getStats(httpRoute).getAvailable();
}
public int getMax() {
return poolingHttpClientConnectionManager.getStats(httpRoute).getMax();
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@service
public class HttpMetricsTracker {
private static final String HTTP_METRIC_NAME_PREFIX = "httpcp";
private static final String METRIC_NAME_LEASED_CONNECTIONS = HTTP_METRIC_NAME_PREFIX + ".connections.leased";
private static final String METRIC_CATEGORY = "http_pool";
private static final String METRIC_NAME_AVAILABLE_CONNECTIONS = HTTP_METRIC_NAME_PREFIX + ".connections.available";
private static final String METRIC_NAME_PENDING_CONNECTIONS = HTTP_METRIC_NAME_PREFIX + ".connections.pending";
private static final String METRIC_NAME_MAX_CONNECTIONS = HTTP_METRIC_NAME_PREFIX + ".connections.max";
}