Friday, May 11, 2018

Why do we need Actuator in Spring Boot?

Problem statement: what is actuator in spring boot?
Actuator provides production ready features of spring boot project that helps to monitor and manage application by invoking different HTTP endpoints exposed by spring boot actuator. such as application 
  1. health (active/inactive)
  2. version details (version of branch, date & time of deployment)
  3. logger details
  4. configurations
  5. bean details
  • How do you enable spring boot actuator?
  1. Need to include maven dependency in existing pom.xml file 
  2. spring-boot-starter-actuator
         <dependency>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-starter-actuator</artifactId>
         </dependency>
  • What do you mean by endpoints ?
  1. Endpoints allow you to monitor & interact with the application.
  2. Spring boot provides a number of built-in endpoints and it lets you add your own / custom endpoints.
  3. for example health endpoint provides basic application health information
  4. each individual endpoints can be enabled or disabled by using id, enabled, sensitive property in application.properties file. 
  • What are the default endpoints in Spring Boot?
  1. healthdisplays application health information.
  2. beans - displays a list of all spring beans in your application.
  3. info - displays arbitrary application info.
  4. loggers displays & modifies the configuration of loggers in the application.
  5. threaddump Performs a thread dump.
  6. httptrace - displays HTTP trace information (by default, the last 100 HTTP request-response exchanges).
  7. sessions - Allows retrieval and deletion of user sessions from a Spring Session-backed session store. Not available when using Spring Session’s support for reactive web applications.
  8. shutdown Lets the application be gracefully shutdown.
  9. metrics - displays metrics information of application.
  • If your application is a web application (Spring MVC, Spring WebFlux, or Jersey), you can use the following additional endpoints:
  1. heapdump - Returns a GZip compressed hprof heap dump file.
  • How do you enable endpoints in spring boot?
  1. By default, all endpoints except for shutdown are enabled
  2. to configure enablement of an endpoints, use its management.endpoint.<id>.enabled=true property in application.properties file
  • How do you enable shutdown endpoints ?
management.endpoint.shutdown.enabled=true
  • What are the default exposing endpoints to the WEB (external world)?
  1. health - yes
  2. info - yes
  3. beans - no
  4. loggers - no
  5. threaddump - no
  6. httptrace - no
  7. sessions - no
  8. shutdown  - no
  9. heapdump - no
  10. metrics - no
  • How do you change which endpoints to be exposed to Web or JMX?
  1. using  include and exclude properties
  • Default endpoints ID's exposure are:
  1. management.endpoints.web.exposure.include = health,info
  2. management.endpoints.jmx.exposure.include = *
  • How do you expose all the endpoints over HTTP / web?
  1. * can be used to select all endpoints properties.
  2. example - management.endpoints.web.exposure.include=*
  • How do you expose everything over HTTP / web / external world except  env and  beans  endpoints?
management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.exclude=env,beans
  • How do you ConfigureCustomize existing endpoints in Spring Boot Actuator? 
  1. spring boot actuator allows customize endpoints by using spring properties. simply mention the name of the properties that you want to customize in your application.properties. 
  • How many ways endpoint can be configure / customize in Spring Boot Actuator?
      Three ways or three properties are available:
  1. id - accessed over HTTP
  2. enabled - if true then it can be accessed otherwise not
  3. sensitivity - if true then need the authorization to show crucial information over HTTP
Each endpoint can be customized with properties using the format:
endpoints.[endpoint name].[property to customize]

example:
1 - adding the below properties will customize the /beans endpoints:
     endpoints.beans.id=springbeans
     endpoints.beans.sensitive=false
     endpoints.beans.enabled=true
2 - adding the below properties will customize the /metrics endpoints:
     endpoints.metrics.id=springbeans
     endpoints.metrics.sensitive=false
     endpoints.metrics.enabled=true

No comments:

Post a Comment

How to run standalone mock server on local laptop

 Please download the standalone wiremock server from Direct download section at the bottom of the page.  Download and installation Feel fre...