How to use JMX MBean for HikariCP in Spring boot application? I have a code like this:
@SpringBootApplication
public class App() { ... }
And other class:
@Configuration
public class DatabaseCfg() {
@Bean
@ManagedOperation
public DataSource ds (@Value("${hikari.proprerties}") String config) {
HikariConfig hikariConfig = new HikariConfig(config);
return new HikariDataSource(hikariConfig);
}
In Java Mission Control (or JMX Console) a saw only Datasource managed bean, not JMX MBean for HikariCP (link). Is it possible to add it too?
JMX is automatically enabled by default in a Spring Boot application. As a result, all of the Actuator endpoints are exposed as MBeans. And it sets us up nicely to expose any other bean in the Spring application context as an MBean.
HikariCP is a reliable, high-performance JDBC connection pool. It is much faster, lightweight and have better performance as compare to other connection pool API. Because of all these compelling reasons, HikariCP is now the default pool implementation in Spring Boot 2.
Java Management Extensions (JMX) provide a standard mechanism to monitor and manage applications. By default, Spring Boot exposes management endpoints as JMX MBeans under the org. springframework. boot domain.
Overview. Hikari is a JDBC DataSource implementation that provides a connection pooling mechanism. Compared to other implementations, it promises to be lightweight and better performing.
In Java Mission Control (or JMX Console) a saw only Datasource managed bean, not JMX MBean for HikariCP ( link ). Is it possible to add it too? Show activity on this post. Show activity on this post. I believe on your hikariConfig you need to set a few additional settings. You need to register the MBeans and set a pool name on the configuration.
By default, Spring Boot exposes management endpoints as JMX MBeans under the org.springframework.boot domain. Let's see how to access them via JConsole.
To mark a bean as an MBean in Spring boot, all that is needed is to annotate the class with the @ManagedResource annotation. This will indicate to the JmxAutoConfiguration class that this is a managed bean. In order to expose specific methods to JMX interfaces, the methods should be annotated with the @ManagedOperation annotation.
As a matter of fact, if you try adding com.zaxxer:HikariCP to your project, Eclipse will report that you are overriding the default implementation available in Spring Boot 2 starters: To configure Hikari Connection Pool you can use the application.properties file.
In Spring Boot 2.0+ you can set the register-mbeans property in your application.properties file
spring.datasource.hikari.register-mbeans = true
If you are using an earlier version of Spring Boot you will also have to set the datasource
spring.datasource.type = com.zaxxer.hikari.HikariDataSource
I believe on your hikariConfig you need to set a few additional settings. You need to register the MBeans and set a pool name on the configuration.
HikariConfig hiakriConfig = new HikariConfig(config);
hikariConfig.setRegisterMbeans(true);
kikariConfig.setPoolName("my-pool-1");
Yes you obviously could drive these through the properties as well. I'm not sure if you are including these in your properties file as they are not listed. Also please note you are spelling properties wrong (@Value("${ds.proprerties}") should probably should be (@Value("${ds.properties}") but I'm not sure how you actually have named variables and property files. You may want to double check if that is where you want to set all of the properties.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With