Monitoring Undertow thread pools
Finding out the runtime metrics of Undertow thread pool can be done through the JMX API. Let’s see how to do it.
Undertow web server is based on XNIO. The XNIO project provides a thin abstraction layer over Java NIO. In particular it provides two core functionalities:
- Channel API
- Management of IO and Worker threads
In terms of notifications, the Channels are notified of events using the ChannelListener API, however in terms of monitoring we will be focusing on the pool of IO threads and Worker threads.
The XNIO worker manages both the IO threads, and a thread pool that can be used for blocking tasks. In general undertow’s non-blocking handlers will run from withing an IO thread, while blocking tasks such as Servlet will be dispatched to the worker thread pool.
By default, there is a “default” worker in the io subsystem:
<subsystem xmlns="urn:jboss:domain:io:1.1">
<worker name="default"/>
<buffer-pool name="default"/>
</subsystem>
This worker is referenced by undertow server through the worker attribute of one listener:
[standalone@localhost:9990 /] /subsystem=undertow/server=default-server/http-listener=default:read-attribute(name=worker)
{
"outcome" => "success",
"result" => "default"
}
The current number of active io threads (IoThreadCount) is not directly exposed through runtime attributes of undertow. In order to find out this metric, and all other relevant metrics such as the WorkerQueueSize, we will need a JMX interface, such as hawtio. (See this tutorial to learn how to install hatwio on WildFly: Getting started with Hawtio to monitor your application server )
As you can see from this picture, the metrics can be collected through the org.xnio ObjectName:

If you want to use REST to access the relevant attributes, then you can reach out for the following URLs:
http://localhost:8080/hawtio/jolokia/read/org.xnio:type=Xnio,provider="nio",worker="default"/IoThreadCount
http://localhost:8080/hawtio/jolokia/read/org.xnio:type=Xnio,provider="nio",worker="default"/CoreWorkerPoolSize
http://localhost:8080/hawtio/jolokia/read/org.xnio:type=Xnio,provider="nio",worker="default"/WorkerQueueSize
Recommended Articles
Enhance Your Java Applications with JBoss Undertow: A Comprehensive Guide
Learn how to embed JBoss Undertow in your applications and leverage its high-performance features for better web server capabilities. #Java #Middleware #CloudNative
Create a Custom Undertow Handler for WildFly using Java
Learn how to create a custom Undertow handler in Java, package it as a WildFly module, and deploy it on WildFly.
Undertow Migration Guide: Mapping JBoss Web Valves to Undertow Handlers
Easily migrate JBoss Web valves to Undertow handlers for improved performance. Learn about key mappings here.
Get Started with Undertow Web Server in WildFly - Master the Boss
Learn how to deploy and use Undertow Web server as a fast and light Java Web server based on non-blocking IO. Deploying Undertow is easy, but setting it up correctly requires understanding of the framework version, dependencies, and configuration.