How can I get the current number of client request threads in spring boot embedded tomcat? - spring

I'd like to get the current number of active client request threads in a spring boot app using embedded tomcat so that I can expose it over actuator's metrics endpoint. I'm not looking for active sessions, but active request processing threads. Preferably, I'd like to get this data per connector as well.
Does anyone have any ideas on a good way to get at this information in spring boot?

I don't know if this is what you are looking for, but you can get serveral values like that via JMX. You can start you current Spring Boot app and open Java Mission Control ([JDK directory]/bin). Open MBean browser and have a look at Tomcat->Thread Pool->[ConnectorName]:
You can get those values programmatically, too.

Related

Spring Integration with Spring Boot - High Availability

A spring integration project pulls emails from Exchange Server using imap-idle-channel-adapter; it transforms the message; it invokes some SOAP webservices and persists data in DB using Spring Boot and JPA. All works fine.
This needs to be deployed in a four-weblogic-server cluster environment.
Could someone please help with some hints on what needs to be done? Is there any configuration needed?
As long as your logic is just like you show and there is no any more endpoints polling shared resource, your are good so far do nothing more. The mail API has built-in feature to mark messages in the box as read or at least seen, so other concurrent session won’t poll those messages again.

Spring Actuator Metrics generate logs

I'm trying to get micrometer metrics data to Splunk. Each metric endpoint gives the current value of a metric, so I would need Splunk to send a http request to my application periodically, or I can write the metric values to a log file periodically.
So how do I get my application to write the metric values to logs?
If you are in spring boot 2.x and Micrometer is of version 1.1.0+ you can create a bean of
periodic (1 minute) special logging registry see (https://github.com/micrometer-metrics/micrometer/issues/605)
#Bean
LoggingMeterRegistry loggingMeterRegistry() {
return new LoggingMeterRegistry();
}
This is by far the easiest way to log everything via logging system.
Another alternative is creating a scheduled job that will run some method on a bean with injected metering registry that will iterate over all the metrics (with possibly filtering out the metrics that you won't need) and preparing the log of your format.
If you think about this, this is exactly what the metrics endpoint of spring boot actuator does, except returning the data via http instead of writing to log.
Here is an up-to-date implementation of the relevant endpoint from the spring boot actuator source

Spring boot graphite network information

I am setting up graphite / grafana for my spring boot application. I am trying to find how to get network information like bytes in / out (network stats). Can someone tell me how I could derive this information? I am using tomcat as boot server
See meter name tomcat.global.received and tomcat.global.sent which come from Tomcat JMX Bean GlobalRequestProcessor's bytesReceived and bytesSent attributes respectively.
See also the relevant part of code in Micrometer.

Check MongoDB Status with Spring Boot

How do I check, if the connection to the MongoDB is active (without using the actuator project) if just a MongoRepository is used, which hides the connection?
If mongodb connection is inactive then spring boot application will throw errors which can be checked in logs.
Ideally actuator project is best way to check the status.
You can also check the status by creating your own controller method lets say ping and in implementation write some operation like MongoRepository.findAll() if it returns positive value it is in active state.

Send feedback to spring from jbpm process

My application is written in Spring Framework 3.x.x. In my application I want to integrate the JBPM5.x processes using its REST API. I have done this thing but I want to send feedback like simple message to my spring application so that I'm able to know what will be the status of my process on the exit of the process. I'm not able to find any way to send this kind of feedback using REST API.
Please give the right direction for it, or give any other way to integrate Spring and JBPM so that my Spring application and JBPM process can be run in different application container instances (same application server but two different instances).
Not sure the REST api would be capable of handling something like that, it is basically some stateless API to get / send information, but doesn't handle async notifications.
What I would recommend is registering a custom process listener to the engine that will be notified when a process is completed, at that point you can do whatever you want, like for example send a JMS message or any other type of async message that could be picked up by your application.
This information is probably already stored in the history log as well. So if your Spring application could take advantage of that, that might be an option as well.

Resources