What is acuator endpoints, what is the purpose of it?
Upon developing the application, post completion of the testing, we cannot deliver the application into production environment, because inorder to monitor and manage the application in the production we need few/additional endpoints through using which we can gather the statistics of the application like
1. health
2. metrics
3. threaddumps
4. info
etc
instead of developers building these additional endpoints, that inccurs more time, efforts, cost and delay in delivery of the application the spring boot has provided actuator endpoints.
The actuator endpoints are pre-built and packaged endpoints that can be quickly configured and integrated aspart of the applications to get the application ready for production deployment.
development to production-grade application can be built using spring boot actuator.
-> Actuator is one of the powerful feature introduced in Spring Boot.
-> Actuators are used to monitor and manage our application.
-> Actuators are giving Production ready features for our boot application.
There are around 16 endpoints are provided by spring boot actuator.
1. /info = provides information about the spring boot application like, author, version, description, changelog etc
2. /health = to check the health of the application
3. /env = to see all the environment variables of the environment/machine on which our application is running.
4. /beans = list down all the bean definitions that are part of the ioc container of the application
5. /configprops = all the configuration properties that are loaded into the env object of the ioc container are being listed using this endpoint
6. /threaddump = shows the jvm threaddumps
7. /metrics = memory, cpu usage statistics
8. /loggers = to see the loggers enabled and their logging levels
9. /logfile = to browse the logfile of the application
10. /shutdown = to shutdown the application remotely. by default shutdown endpoint is disabled for security reasons.
11. /conditions = shows the auto-configuration conditions
12. /caches = displays all the caches available in the application
13. /httptrace = display all the httpTrace
15. /mappings = display all the requestURLS that are exposed aspart of our application
16. /quartz = displays all the quartz beans
17. /startup = shows the startup steps data
All these endpoints are accessible by using the prefix as "/actuator/endpoint". By default these endpoints are not enabled/exposed even we add the spring-boot-starter-actuator dependency.
These endpoints are exposed in 2 ways:
1. jmx endpoints (java management extension)
The JMX technology is native to java programming language, due to this it offers efficient and light-weight management extensions to java-based applications. Since the actuator endpoints are designed for monitoring, managing and administering an boot application the boot team has exposed these endpoints by using jmx technology.
2. http endpoints (web)
The boot actuator endpoints are even built and exposed on http protocol, to support inter-operability and integration.
To make use of these endpoints we need to enable them and expose them. by default all the endpoints are enabled expect shutdown endpoint, here enabled means the endpoint is shipped or included aspart of your application but it is not exposed or accessible. We need to explicitly expose them to make them accessible.
=> To work with actuators we have to use 'spring-boot-starter-actuator' dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
-> We can see actuator exposed endpoints using below URL
URL : http://localhost:8080/actuator
Note: /health is a default endpoint which we can access directly.
-> We can expose other actuator endpoints using below property
application.yml
++++++++++
management:
endpoints:
web:
exposure:
include: '*'
Note: To expose endpoints using application.properties we will use below property.
management.endpoints.web.exposure.include=*
Working with shutdown
+++++++++++++++++
-> IT is used to stop our application.
-> We need to enable this manually.
-> It is binded to http post request.
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
shutdown:
enabled: true
How to enable/disable and expose an endpoint?
We need to write properties in application.yml|properties to make these endpoints enable and expose as below.
by default all the endpoints are enabled except shutdown, lets us say we want to disable all the endpoints and want to enable specific endpoints only for our application, this can be done as below.
management.endpoints.enabled-by-default=false // all the endpoints will be disabled
now we can enable individual endpoints using:
management.endpoints.info.enabled=true
management.endpoints.health.enabled=true
management.endpoints.shutdown.enabled=true
with this we enabled the endpoints but those are not exposed, unless those are exposed those will not become accessible. We can expose these endpoints using 2 protocols either using jmx or http/web endpoints
By default all the endpoints are exposed through jmx technology, but when it comes to http/web endpoints only 2 of them are exposed by default.
1. healthcheck
2. info
so if we want to expose webendpoints we need to manually expose them by writing the below configuration
management.endpoints.jmx.exposure.include=endpointNames (separated by comma)
management.endpoints.jmx.exposure.exclude=
management.endpoints.web.exposure.include=
management.endpoints.web.exposure.exclude=
For eg.. if we want to enable and expose metrics/threaddumps endpoint through web, then we need to write the below configuration.
management.endpoints.enabled-by-default=false
management.endpoints.metrics.enabled=true
management.endpoints.threaddumps.enabled=true
mangament.endpoints.web.exposure.include=metrics,threaddumps
if we want to expose all the endpoints we can write the property with value as "*"
management.endpoints.web.exposure.include=*
How to change the port on which the management endpoints are exposed?
we can change the port on which the management endpoints are exposed by using
management.server.port=8889
then we can access the management endpoints using http://localhost:8889/actuator
when we change the management endpoint port to a different port other than the application server port, then the application will be started on 2 tomcat servers.
How to change the default base-path over which the actuator endpoints are accessible?
by default the management endpoints are exposed using a prefix : /actuator and we can change this using
management.endpoints.web.base-path=/management
Comments
Post a Comment