Spring boot 如何在spring Boot应用程序中监控HttpClientConnectionManager指标

Spring boot 如何在spring Boot应用程序中监控HttpClientConnectionManager指标,spring-boot,prometheus,grafana,spring-boot-actuator,apache-httpcomponents,Spring Boot,Prometheus,Grafana,Spring Boot Actuator,Apache Httpcomponents,我们使用Rest模板和HttpClientConnectionManager来调用外部API。我们希望监控来自HttpClientConnectionManager的指标,如可用连接、已用连接、等待时间等。 我试图参考下面的链接,但这对我的实现没有帮助。 下面是我们的池管理器代码 public HttpClientConnectionManager poolingConnectionManager() { SSLContextBuilder builder = new

我们使用Rest模板和HttpClientConnectionManager来调用外部API。我们希望监控来自HttpClientConnectionManager的指标,如可用连接、已用连接、等待时间等。 我试图参考下面的链接,但这对我的实现没有帮助。

下面是我们的池管理器代码

    public HttpClientConnectionManager poolingConnectionManager() {
        SSLContextBuilder builder = new SSLContextBuilder();
        try {
            builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
        } catch (NoSuchAlgorithmException | KeyStoreException e) {
            LOGGER.error("Pooling Connection Manager Initialisation failure because of " + e.getMessage(), e);
        }
 
        SSLConnectionSocketFactory sslsf = null;
        try {
            sslsf = new SSLConnectionSocketFactory(builder.build());
        } catch (KeyManagementException | NoSuchAlgorithmException e) {
            LOGGER.error("Pooling Connection Manager Initialisation failure because of " + e.getMessage(), e);
        }
 
        Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder
                .<ConnectionSocketFactory>create().register("https", sslsf)
                .register("http", new PlainConnectionSocketFactory())
                .build();
 
        ConnPoolControl<HttpRoute> poolingConnectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
        poolingConnectionManager.setMaxTotal(MAX_TOTAL_CONNECTIONS);
        poolingConnectionManager.setDefaultMaxPerRoute(MAX_CONNECTIONS_PER_ROUTE);
      //  connPoolControl = poolingConnectionManager;

        return (HttpClientConnectionManager) poolingConnectionManager;
    }
 
    @Bean
    public ConnectionKeepAliveStrategy connectionKeepAliveStrategy() {
        return new ConnectionKeepAliveStrategy() {
            @Override
            public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
                HeaderElementIterator it = new BasicHeaderElementIterator
                        (response.headerIterator(HTTP.CONN_KEEP_ALIVE));
                while (it.hasNext()) {
                    HeaderElement he = it.nextElement();
                    String param = he.getName();
                    String value = he.getValue();
 
                    if (value != null && param.equalsIgnoreCase("timeout")) {
                        return Long.parseLong(value) * 1000;
                    }
                }
                return DEFAULT_KEEP_ALIVE_TIME_MILLIS;
            }
        };
    }
表示度量将作为测微计核心的一部分提供,但我无法获得

您能否建议我如何获得HttpClientConnectionManager的统计数据,以便我们能够集成到Grafana或其他工具,并进行更好的监控。下面是pom.xml依赖项

   <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-test</artifactId>
           <scope>test</scope>
       </dependency>
              <dependency>
           <groupId>org.apache.httpcomponents</groupId>
           <artifactId>httpclient</artifactId>
       </dependency>
       <dependency>
           <groupId>io.micrometer</groupId>
           <artifactId>micrometer-core</artifactId>         
       </dependency>
       <dependency>
            <groupId>io.micrometer</groupId>
           <artifactId>micrometer-registry-prometheus</artifactId>
       </dependency>
</dependencies>




org.springframework.boot
弹簧起动试验
测试
org.apache.httpcomponents
httpclient
千分尺
测微计芯
千分尺
普罗米修斯测微计

看起来像是解决您的问题的方法:
   <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-test</artifactId>
           <scope>test</scope>
       </dependency>
              <dependency>
           <groupId>org.apache.httpcomponents</groupId>
           <artifactId>httpclient</artifactId>
       </dependency>
       <dependency>
           <groupId>io.micrometer</groupId>
           <artifactId>micrometer-core</artifactId>         
       </dependency>
       <dependency>
            <groupId>io.micrometer</groupId>
           <artifactId>micrometer-registry-prometheus</artifactId>
       </dependency>
</dependencies>