I am developing a TCP socket server application in java using Spring Boot. Eventhough, I am not using the spring-boot-starter-web dependency, I still would like to benefit from the actuator endpoint to monitor the application using external monitoring tool like prometheus.
A minimal equivalent application would be:
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.7</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
DemoApplication.java
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
SpringBootConsoleApplication.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
@Component
public class SpringBootConsoleApplication
implements CommandLineRunner {
private static Logger LOG = LoggerFactory
.getLogger(SpringBootConsoleApplication.class);
@Override
public void run(String... args) throws InterruptedException {
LOG.info("EXECUTING : command line runner");
int i = 0;
while(true) {
LOG.info("iteration: {}", i++);
Thread.sleep(1000);
}
}
}
application.yml
spring:
jmx:
enabled: true
management:
endpoints:
jmx:
unique-names: true
exposure:
include: '*'
web:
exposure:
include: '*'
health:
show-details: always
Using jconsole, I can get the actuator data via JMX, but how to get them from the actuator rest endpoint?
Are there some missing (or unnecessary) config in the application.yml
or missing dependencies?
I have read the other posts:
- how could access actuator endpoints in non-web application
- Spring boot actuator for commandline runner application
without managing to make the rest actuator working on my application.