I am trying to add the Spring Boot actuator on an existing project using Jetty, and I was wondering if it's possible at all, because despite adding the library to the project
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
And enabling those endpoints in the application properties:
endpoints.health.sensitive=false
endpoints.health.enabled=true
management.security.enabled=false
management.endpoints.web.exposure.include=*
And even forcing the endpoints to one specific port:
management.server.port=9001
There's no way I can reach them.
I can definitely see that the endpoints are mapped though:
[2022-10-26 15:00:37] org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping INFO : Mapped "{[/health || /health.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(javax.servlet.http.HttpServletRequest,java.security.Principal) (AbstractHandlerMethodMapping.java:543)
The question is, where they have been mapped, cause I tried every port, and I can't find those endpoints.
Related
I am trying to integrate config-server service into my spring boot application with multiple services. After adding the changes for config server I am getting below error
APPLICATION FAILED TO START
Description:
No spring.config.import property has been defined
Action:
Add a spring.config.import=configserver: property to your configuration.
If configuration is not required add spring.config.import=optional:configserver: instead.
To disable this check, set spring.cloud.config.enabled=false or
spring.cloud.config.import-check.enabled=false.
I have already tried adding dependency for bootstrap as below
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
But it did not work
Can someone tell me how to integrate config server in spring boot application?
I am trying to expose additional actuator endpoints in my Spring Boot 2.3 service. Attempting to add endpoints such as the prometheus and metrics for monitoring. But for some reason, the exposed endpoints are locked to the default loggers,health,info.
For some background, within the org, there is a parent Spring dependency which automatically brings all of the Spring essentials, as well as some generic code useful within the org. I use this dependency in many of my other projects and was able to expose these additional actuator endpoints successfully. However, in this project with multiple artifacts, I am unable to edit the default exposed actuator endpoints.
Printing the configurableEnvironment post init always shows the exposure property as follows
management.endpoints.web.exposure.include = loggers,health,info
This is after trying to override this property to an expanded list (loggers,health,info,Prometheus,metrics) using below methods:
Enabling specific endpoint via management.endpoint.metrics.enabled: true
Specifying these values in application.yaml
Passing this as a Command line arguement Dmanagement.endpoints.web.exposure.include=loggers,health,info,prometheus,metrics
Using mvn dependency:tree To exclude any transitive actuator dependencies
I don’t believe its due to the org’s parent pom, likely due to another dependency we are using. But due to the size of this project, it is quite hard to remove dependencies to test. Is there any way to track down where these properties are set. Or perhaps additional ways to force exposure of the additional endpoints I want?
——
Actuator config
management:
endpoints:
web:
exposure:
include: metrics,prometheus,info,health,logging
endpoint:
env:
enabled: true
metrics:
enabled: true
info:
enabled: true
health:
enabled: true
show-details: always
beans:
enabled: true
caches:
enabled: true
threaddump:
enabled: true
prometheus:
enabled: true
Actuator info
{"_links":{"self":{"href":"http://localhost:9050/actuator","templated":false},"health":{"href":"http://localhost:9050/actuator/health","templated":false},"health-path":{"href":"http://localhost:9050/actuator/health/{*path}","templated":true},"info":{"href":"http://localhost:9050/actuator/info","templated":false},"loggers":{"href":"http://localhost:9050/actuator/loggers","templated":false},"loggers-name":{"href":"http://localhost:9050/actuator/loggers/{name}","templated":true}}}
Your question lacks some background, like your pom.xml or build.gradle files and full application.yml config.
I will go through the basic steps, which you may have missed.
Firstly, please make sure that you've included the Prometheus dependency:
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>
Also, don't forget that some metrics require the AOP dependency (like custome timers, for example):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
To enable the Prometheus metrics exposure, you should specify such configuration in your application.yml file (it seems like you did it correctly, but let's list it here for the full picture):
management:
endpoints:
web.exposure.include: health, info, prometheus
To verify that the Prometheus endpoints were exposed, please use the GET request to this URL: http://localhost:8080/actuator/prometheus
If those steps don't help you resolve your issue, please add more details to your question.
I am trying to enable the actuator endpoints on the same port as the application port (specified in the application.properties file by the server.port=8080) but for some reason, it does not work. When I run the application, I can get back the response from the application but not from the actuator endpoints. I can see the logs mention the endpoints being exposed beneath base path '/actuator' as shown in the screenshot below. But when I try to hit the actuator URL, it gives a 404.
URL, not working:
http://localhost:8080/actuator
http://localhost:8080/actuator/health
http://localhost:8080/actuator/info
However, if I specify a separate port in application.properties for the actuator endpoints with the property (management.server.port=9000) then it works fine.
URL, that's working:
http://localhost:9000/actuator
http://localhost:9000/actuator/health
http://localhost:9000/actuator/info
The only difference is about the port number but from what I read in the spring documentation, the actuator endpoints should by default be enabled on the application port if we don't specify the management.server.port.
Can someone please explain what am I missing here?
PS: The application run logs are exactly the same with or without specifying the management.server.port, hence, this one screenshot is without specifying the management port.
Also, I tried giving the same port number for both the property (server.port and management.server.port) but the same problem occurs. The application works on that port but the actuator endpoints do not.
I am using the spring-boot version 2.0.6
These are the contents of my application.properties file:
camel.springboot.main-run-controller=true
camel.springboot.name=AppName
camel.rest.data-format-property.prettyPrint=false
camel.component.servlet.mapping.context-path=/*
server.port=8080
management.server.port=9000
management.endpoint.health.show-details=always
management.endpoint.beans.enabled=true
logging.level.org.springframework = INFO
logging.level.org.apache.camel.spring.boot = INFO
logging.level.org.apache.camel.impl = DEBUG
Here are the dependencies in pom.xml:
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-servlet-starter</artifactId>
</dependency>
</dependencies>
Regarding the Spring Boot Actuator documentation
Exposing management endpoints by using the default HTTP port is a
sensible choice for cloud-based deployments. If, however, your
application runs inside your own data center, you may prefer to expose
endpoints by using a different HTTP port.
it serves the Actuator using the default HTTP port (which is 8080). I did a quick check and could confirm this with Spring Boot 2.1.X and 2.2.X.
Try to remove the management.port from your config and if this does not work then the problem might come from an additional (custom) configuration in your application.
Remove management.server.port=9000, this property overrides server.port=8080.
Please set the below in application.properties file
management.endpoints.enabled-by-default=true
management.endpoints.web.exposure.include=*
I had the same problem, what was causing this for me was a conflict between the context I declared for camel and the one being used for spring actuator.
So, at application.yml I had these 3 contexts:
server: servlet: context-path: myservercontext/v1
camel: component: servlet: mapping: contextPath: /*
management: endpoints: web: base-path: "/"
I think after the request hits the server it gets lost on this ambiguity so i solved it by changing these contexts to:
server: servlet: context-path: myservercontext/v1
camel: component: servlet: mapping: contextPath: /camel/*
management: endpoints: web: base-path: "/"
This worked out nicely for me since all my resources where grouped under "/camel" anyway but as I tested I found out this also works:
server: servlet: context-path: myservercontext
camel: component: servlet: mapping: contextPath: /v1/*
management: endpoints: web: base-path: "/"
Just note that in this last scenario the health route won't be under "v1".
I would never have figured out the cause of this problem if it wasn't for this question, even if it wasn't solved yet, so I thank you a lot for posting this and hope my solution will manage to help others ^^
I went via almost all docs and all but not able to get grip on this mysterious stuff.
so my question - Can I use my standalone spring boot app to monitor health and other metrics of my app via http jmx url? Do I need to configure something else for this?
I have added below dependency in boot app.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
</dependency>
I have also configured below properties in my config file.
management.endpoints.web.exposure.include=*
management.endpoints.jmx.unique-names=true
management.server.port=8080
management.server.ssl.enabled=false
When I try to hit URL : http://localhost:8080/actuator/jolokia/health I am not able to see any results.
Also tried adding custom end point like below but not working.
#Endpoint(id="mypoint")
#Component
public class myPointEndPoint {
#ReadOperation
public String mypoint(){
return "Hello" ;
}
with additional property
management.endpoint.mypoint.enabled=true
The problem is the url you are trying to invoke.
First, retrieve the possible mbeans with: http://localhost:8080/actuator/jolokia/list
When you take a look at the Health mbean, you must provide the unique name and the operation (op).
In my case, it looked like: http://localhost:8080/actuator/jolokia/exec/org.springframework.boot:type=Endpoint,name=Health,identity=4200098/health
Also check the Jolokia documentation: https://jolokia.org/reference/html/index.html
I'm writing spring boot application, which using spring configuration, deployed on pivotal cloud foundry and exposed by Netflix Eureka as discovery serivce / load balancer.
I have created a bean as followed:
#Component
#ConfigurationProperties("config")
#RefreshScope
#Data
public class GeneralProperties {
private boolean ignoreEvent;
}
When calling to the application route that Eureka exposed with /refresh after changing the actual property in the configuration repository, the value that annotated by #refreshScope was changed (end in the response status the field exsiting), which means it's working correctly.
The issue starts when running multiple instances of the same application on the cloud, and calling to the /refresh.
The route that beeing used is the one that exposed by Eureka, which using it's load balancer to route the call to one of the available instances.
It leads to unexpected results that not all the instances are getting updated with the latest change in the property.
Any suggestions how to apply the change on all instances?
You should use Spring Cloud Bus in such a case.
The idea behind this framework is to bind all your application instances to a topic in a message broker (RabbitMQ or Apache Kafka).
Add the following dependency to your pom.xml:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-bus-parent</artifactId>
<version>1.3.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
</dependencies>
In the above example I added a dependency on amqp which is RabbitMQ. You'll also need to bind your application to the RabbitMQ, in PCF it's easy since it's built in to the platform.
When you need to refresh, you should invoke:
POST /bus/refresh
This would trigger an event to a topic that all instances of your application are listening to, and as a result - all instances would refresh their bean configuration.
Good luck.