Ahmet Karakaya
Ahmet Karakaya

Reputation: 10139

Monitoring Springboot 2.0 Tomcat server Thread utilization

I have started my springboot application with following tomcat parameters

-Dserver.tomcat.max-threads=400
-Dserver.tomcat.max-connections=4000

I want to monitor busy thread and busy connection size?

Is there a built-in solution inside springboot? Otherwise Do I need to get mbeans?

Found similar question but solution is not given yet.

Thanks.

Upvotes: 13

Views: 15396

Answers (3)

Wachira
Wachira

Reputation: 388

At first, I use Spring Boot Actuator and Micrometer. But It does not show tomcat thread utilization. So I configured the application.yml like this.

server:
  port: 3200
  address: 0.0.0.0
  tomcat:
    max-threads: 4000
    mbeanregistry:
      enabled: true

I set server.tomcat.mbeanregistry.enabled to true. Then Tomcat threads utilization is shown in /actuator/metrics.

This is my output.

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

Upvotes: 23

Iana Mykhailenko
Iana Mykhailenko

Reputation: 583

You can use Spring Boot Actuator (/metrics endpoint) that gives information about memory, heap, processors, threads, classes loaded, classes unloaded, thread pools, etc.

For example, this endpoint returns:

"threads.peak" : ...,
"threads.daemon" : ...,
"threads" : ...,

Also, you can get a thread dump in case if you need to by using /threaddump endpoint.

Upvotes: 0

BogdanSucaciu
BogdanSucaciu

Reputation: 904

One easy to do this is by using Spring Actuator with Micrometer on top of it. You get instant JMX metrics and you can also declare your own custom ones.

Upvotes: 0

Related Questions