How to add Spring Boot Actuator to a Spring application? - spring

In the "Bootiful" Applications with Spring Boot Spring One 2014 section(https://www.youtube.com/watch?v=HCyYEVRZISk), Josh mentioned that it is easy to add the Boot Actuator to a Spring (non-bootiful) application. I assume that an Actuator configuration is needed somehow, but can't find how it shall be done.

Just add the starter to your pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
... and the endpoints such as /health will be available.

Related

Spring boot actuator for commandline runner application

I want to enable actuator for health check in PCF for the non web or batch or commandLineRunner spring boot application.
Could some one please share some details to resolve this issue.
Please let me know if any other details required
I tried the below options
Adding actuator dependency
Adding http and jmx related properties
Since localhost:8081/actuator is not accessible could not view endpoints
How to enable url for non web app
add
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
application.properties
spring.jmx.enabled = true
management.endpoints.jmx.exposure.include=*
management.endpoints.jmx.domain=com.example.demomail
management.endpoints.jmx.unique-names=true
run jconsole find your application name then connect.
find Tab MBeans, find com.example.demomail in left tree.
As far as I understand you need to enable the Actuator endpoints.
You must add the Spring Boot Actuator dependency (as you have already done).
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Then in your application.properties file enable HTTP and JMX support (as you have already done).
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
management.endpoint.jmx.exposure.include=*
Now you will have to push your app to PCF and create a binding to a route to create access for the Actuator endpoint/s.
The URL to access the actuator endpoint will be something like this http://<route-url>/actuator/health
In the command line, I would use something like this to return a list of routes and the URL route of the application.
cf curl /v2/apps/<app-guid>/routes

Zipkin server is not showing Microservices trace

I have a Microservice A calling another Microservice B with the following pom.xml and application.properties values:
pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
application.properties
spring.zipkin.base-url=http://localhost:9411/
spring.sleuth.sampler.probability=1.0
spring.zipkin.sender.type=web
spring.zipkin.collector.http.enabled=true
Zipkin server version: zipkin-server-2.12.9
Spring Boot Version: 2.7.5
Spring cloud version: 2021.0.4
Issue is that trace that Microservice A called Microservice B with the trace-ID is not getting displayed in Zipkin.
Any issue?
Trace of Microservices calling chain with trace-ID should be coming in Zipkin server
The problem was that RestTemplate used to call the another service was create as New.
Solution is that create it as a bean and inject it to your code.

Which is the best way for the routs uri in spring boot except zuul and spring cloud gateway

I am upgrading the spring boot 1.3.7.RELEASE to 2.5.12 and spring framework 5.3.18 in my spring boot microservice based project we have upgrade successfully with all service except gateway service when i am unabling t add zuul dependency because its maintenance mode that why we have implemented spring cloud gateway then i am getting below issue.
***************************
APPLICATION FAILED TO START
***************************
Description:
Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway.
Action:
Please set spring.main.web-application-type=reactive or remove spring-boot-starter-web dependency.
Wwhat we need to do implementation for best way?
We have fix the routing issue using the spring cloud gateway.
Please add dependency in the pom.xml
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-gateway</artifactId> </dependency>
bootstrap.yml
spring:main:web-application-type:reactive
Thanks you guys for supporting.

How to enable actuator endpoints which are set in custom starter / library?

I have got custom starter application (library) which has actuator and prometheus dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.5.2</version>
</dependency>
in application.properties
management.endpoints.web.exposure.include=health, info, metrics, prometheus
I am using this starter in my other applications and I want to pass also this exposition of the endpoints from the starter.
Actuator and Prometheus dependecies works in applications but not show selected endpoints in starter. Ofc I can add also line with management.endpoints.web.exposure.include=health, info, metrics, prometheus to my apps but with several apps using this starter I want to pass this once for all and change endpoints only in starter if needed.
Do you have an idea how to expose those endpoints in my app which are set in starter?
Spring Boot v2.3.2 /
Maven 3.6.3
You can pass this as command line args or as ENV vars to your jar, when you start your application.
This way you can pass it to required application, as and when needed w/o updating application.properties.
It will also safeguard against exposing the actuator endpoints when not required, as actuator endpoints reveal sensitive info about the application.
eg. java -Dmanagement.endpoints.web.exposure.include=health, info, metrics, prometheus -jar myapp.jar

How to use zuul in spring cloud without spring boot actuator?

I want to use zuul as a proxy server in my application, but I don't want to use spring boot actuator, I tried to remove it from the dependency as follow:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
<version>${spring-cloud-netflix.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</exclusion>
</exclusions>
</dependency>
However, it will cause some ClassNotFoundException.
I don't need spring boot actuator in my application, but it has so many autoconfiguration in spring boot that will produce many endpoints that I don't want.
Is there any good way to solve this?
The issue has been addressed in spring cloud netflix 1135. It will be available shortly in Brixton.SR2.

Resources