【问题标题】:Spring Boot Actuator PoolingHttpClientConnectionManager MetricsSpring Boot Actuator PoolingHttpClientConnectionManager 指标
【发布时间】:2020-05-06 16:13:55
【问题描述】:

我们使用带有 Actuator 和 Prometheus 的 Spring Boot 2 来显示 Grafana 仪表板。我想添加 Apache Http Client PoolingHttpClientConnectionManager 指标来报告连接池统计信息。我看到这已添加到 micrometer-core:1.3.0 (https://github.com/micrometer-metrics/micrometer/pull/1223)。但是,我在 /actuator/metrics 或 /actuator/prometheus 端点中看不到任何相关指标。我尝试在 pom.xml 中更新依赖项:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
        <relativePath/>
        <!-- lookup parent from repository -->
    </parent>
...
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-core</artifactId>
            <version>1.4.2</version>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
            <version>1.4.2</version>
        </dependency>

application.yml

# Spring Actuator Configuration
management:
  endpoint:
    health:
      show-details: always

  endpoints:
    web:
      exposure:
        include: "*"
  metrics:
    enable:
      all: true

/执行器/指标

{
"names": [
"jvm.buffer.memory.used",
"jvm.threads.states",
"tomcat.servlet.error",
"process.uptime",
"jvm.memory.used",
"system.load.average.1m",
"tomcat.servlet.request.max",
"tomcat.cache.hit",
"tomcat.global.request.max",
"tomcat.global.error",
"tomcat.cache.access",
"logback.events",
"jvm.memory.committed",
"tomcat.sessions.active.current",
"jvm.buffer.total.capacity",
"jvm.gc.pause",
"jvm.memory.max",
"system.cpu.usage",
"jvm.threads.live",
"jvm.classes.unloaded",
"tomcat.global.sent",
"jvm.classes.loaded",
"jvm.threads.peak",
"tomcat.threads.config.max",
"tomcat.sessions.rejected",
"tomcat.sessions.alive.max",
"jvm.gc.memory.promoted",
"jvm.buffer.count",
"jvm.gc.memory.allocated",
"tomcat.global.received",
"tomcat.sessions.expired",
"tomcat.sessions.created",
"jvm.gc.max.data.size",
"system.cpu.count",
"tomcat.threads.busy",
"process.start.time",
"jvm.threads.daemon",
"process.files.max",
"tomcat.threads.current",
"tomcat.sessions.active.max",
"tomcat.global.request",
"process.files.open",
"jvm.gc.live.data.size",
"tomcat.servlet.request",
"process.cpu.usage"
]
}

是否需要在弹簧执行器中进行支持更改,或者我是否缺少配置内容?感谢您提供任何帮助或建议。

【问题讨论】:

标签: spring-boot prometheus spring-boot-actuator


【解决方案1】:

此代码是从 github issue 复制的 Apache HTTP client instrumentation

PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
HttpClient httpClient = HttpClientBuilder.create().setConnectionManager(connectionManager).build();
new PoolingHttpClientConnectionManagerMetricsBinder(connectionManager, "my-pool").bindTo(registry);

【讨论】:

    【解决方案2】:
    io.micrometer.core.instrument.binder.httpcomponents @Incubating(since = "1.4.0") 
    public class MicrometerHttpClientInterceptor
    extends Object
    Provides HttpRequestInterceptor and HttpResponseInterceptor for configuring with an org.apache.http.nio.client.HttpAsyncClient. Usage example:
     
         MicrometerHttpClientInterceptor interceptor = new MicrometerHttpClientInterceptor(registry,
                 request -> request.getRequestLine().getUri(),
                 Tags.empty(),
                 true);
    
         CloseableHttpAsyncClient httpAsyncClient = HttpAsyncClients.custom()
                 .addInterceptorFirst(interceptor.getRequestInterceptor())
                 .addInterceptorLast(interceptor.getResponseInterceptor())
                 .build();
     
    

    因为: 1.4.0

    【讨论】:

    猜你喜欢
    • 2019-02-08
    • 2021-06-16
    • 2019-10-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多