监控 Spring Embedded Tomcat 指标 [英] Monitor Spring Embedded Tomcat metrics

查看:19
本文介绍了监控 Spring Embedded Tomcat 指标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想监控我的 Spring Boot 服务中嵌入的 Tomcat.Spring 本身为我提供了一些会话使用统计信息,但我需要有关底层线程池的其他信息,例如活动连接、队列长度等.

I would like to monitor the embedded Tomcat in my Spring Boot Service. Spring itself gives me some session usage stats, but I need additional information about the underlying thread pool like active connections, queue length etc.

我已经搜索了注册的 bean,但找不到使用的线程池.

I've searched the registered beans but can't find the thread pool that is used.

对如何检索该信息有任何想法吗?

Any thoughts on how to retrieve that information?

推荐答案

18 个月前的问题!

因此,事实证明,使用 Spring Boot 2.0 及其新的 Metrics 包可以轻松监控嵌入式 Tomcat 指标.升级该应用的理由.

So, turns out the embedded Tomcat metrics are pretty easy to monitor with Spring Boot 2.0 and its new Metrics package. A reason to upgrade that app.

这里有一些示例代码可以帮助您入门.

Here's some sample code to get you started.

class SomeClass {

@Autowired
private MeterRegistry repo;

@ReadOperation
public WebEndpointResponse<Map> invoke() {
    Gauge busyThreads = repo.get("tomcat.threads.busy").gauge();
    Gauge allThreads  = repo.get("tomcat.threads.config.max").gauge();  // yes, could do @Value("${server.tomcat.max-threads:200}") and have it injected

    double busyThreadsCount = busyThreads.value();
    double allThreadsCount = allThreads.value();

    ....
}
}

查看更多:

  • https://github.com/rwilcox/k8_spring_actuators <-- 我有一个如果 Tomcat 线程的负载过高,则就绪执行器将失败.
  • Tomcat 指标的源代码.我很快的任务之一可能是将此代码向后移植到 Spring Boot 1.x 应用程序中.TomcatMetrics 类专门向 Tomcat 询问它,因此将其放入 Spring Boot 1.x 执行器应该不会太难.
  • https://github.com/rwilcox/k8_spring_actuators <-- where I have a Readiness actuator that fails if the load on the Tomcat threads are too high.
  • The source code for the Tomcat metrics stuff. One of my tasks soon may be to backport this code into a Spring Boot 1.x application. The TomcatMetrics class asks Tomcat for it specifically, so it shouldn't be too too hard to pull that into a Spring Boot 1.x actuator.

这篇关于监控 Spring Embedded Tomcat 指标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆