Let’s talk tech. In this post, we outline how to set up the profiling of an RWS Spring Boot Micro Service for monitoring the memory, threads, classes, and MBeans.
What is Profiling?
Profiling is the process of analyzing your application’s memory consumption, CPU usage, frequency of function calls, cache monitoring, and more! It’s essentially a way of peeking under the hood and seeing what’s inside your application’s performance.
Why Do We Need Profiling?
Ensuring that your application is running smoothly and within its infrastructure limits is always something we strive for as architects. With profiling you can measure several metrics and understand which parts of your logic need attention and which areas of the infrastructure need increasing, or even decreasing, therefore reducing overall costs.
Setting up profiling consists of two parts:
- Configuring the microservice for JMX remote management
- Connecting to the JMX management from the JConsole application (or any other JMX enables monitoring application).
Note: This does impact performance, so it should not be used in a production scenario.
Setup
Complete this section in the order presented.
Configuring JMX Remote Management on the Micro Service
- Open the start.sh of your microservice
- Add the following entries to the JVM_OPTIONS
- Dcom.sun.management.jmxremote
- Djava.rmi.server.hostname=<server ip address>
- Dcom.sun.management.jmxremote.port=<port of your choice>
- Dcom.sun.management.jmxremote.rmi.port=<same port as above>
- Dcom.sun.management.jmxremote.ssl=false
- Dcom.sun.management.jmxremote.authenticate=false
- Restart the microservice
We’d recommend removing this configuration once you’ve finished monitoring.
Optionally, add the “authenticate” value depending on your authentication requirements. Additional information on providing authentication credentials can be found in the official JMX documentation.
Connect JConsole to Your Micro Service
- Navigate to /Contents/Home/Bin under your JDK folder
- Run the jconsole application
- Under New Connection -> Remote Process enter the host of the server your microservice runs on and the port you configured for your JMX management
- Click Connect
Now you can view the stats of your microservices. Note that MBeans allow us to monitor the addition/usage/invalidation of the EhCache. Click the tab and expand the Ehcache section to view the details.
Tip: Why not try connecting with the more powerful VisualVM? Simply install the tool and connect just like you did with JConsole.
Firewall
Update your firewall to allow TCP for the port you configured.