Wednesday, April 29, 2020

Spring Boot Actuator

Spring boot Actuator provides many feature to monitor and manage your Spring boot application when deploying to production.There is following two way to monitor your application as below.

Definition of Actuator: Actuator is a manufacturing term that is monitoring our application, generating loggers, showing application health, showing database status etc.

Enabling Production ready feature: To Enable spring boot actuator we have to add maven dependency "spring-boot-starter-actuator"  as shown below.

<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> </dependencies>

Note: I have shown maven example in my blog. you can use gradle as well.

Endpoints: Using actuator endpoints we can monitor and interact with our application in efficient way. Spring boot provides a number of built in endpoints, we can use that endpoints. We can enable and disable the endpoints accordingly.

Some important endpoints for spring actuator is as shown below:


EndpointDescription
/health
To Show the application health.
/beans
Shows complete spring beans information. 
/loggers
Shows configuration of loggers.
/env
Shows list of environment variable of the application. 
/info
Shows spring application information.
/mactrics
Shows matcics of the current spring boot application. Ex. free memory, used memory etc. 
/mapping
Shows list of @RequestMapping  paths.
We can enable and disable individual endpoints as well.

Syntax to enable endpoint: management.endpoint.<endpoint name>.enable = true
Syntax to disable endpoint: management.endpoint.<endpoint name>.enable = false

We can disable all endtpoints by default as well.
Syntax to disable all endpoints: management.endpoints.enabled-by-default = false

if you are using the YML file then use the below format to provide the configuration.
management: endpoints: web: exposure: include: "*"

We can Expose the endponts using following two ways:
  1. Using HTTP Endpoints
  2. Using JMX
we can use exclude and include properties to expose the endpoints.


Property NameDefault value
management.endpoints.jmx.exposure.exclude
*
management.endpoints.jmx.exposure.include
*
management.endpoints.web.exposure.exclude
*
management.endpoints.we.exposure.include
info, health
Note: The include property exposed the endpoints that we will use. and exclude property will prevent to expose the endpoints.
    HTTP Endpoints: HTTP endpoint include web endpoint. Http tracing provides the information about request and response exchange through web application. Using HTTP tracing, we can only access "/actuator/health" and "/actuator/info" over the HTTP protocol for the security reason.

    JMX: Using JMX we can access other endpoints such as "/actuator/beans", "/actuator/auditevents" etc. JMX(Java Monitoring and Management Console) can be found under JDK_HOME/bin directory. To Start Jconsole use the below step.
    • Open command prompt.






    • Navigate to the JDK_HOME/bin directory.
    • Execute JConsole.exe. 
    • Once you will type the JConsole.exe and press Enter then below popup will open.
    • Select Local process and select you application main class as below and press connect. Before executing above command make sure your application is up and running.
    • After pressing connect button if you are facing some issue as below then proceed with insecure connection.
    • After successful connection you will see the below popup.


    • After connecting it will open a popup with MyBean property in left panel in tree view as below.



    • By exploring the endpoints you will get details of all endpoints that you wish. for example, take an example for beans. So click on Beans => Select operation => beans. Once you will click on beans you will find java.util.Map along with the bean on the top of the operation invocation window as below.

      • By clicking on beans button you will get operation value as below.
      • you can see the operation value by pressing CTRL+A then copy all text by CTRL+C and then copy to the notepad++ where you can see all the beans operation. 

      Demo with spring boot application.

      To create Spring boot application using actuator follow the below steps.
      • Create spring boot application and import into you IDE. To create application got to https://start.spring.io/ and complete the below information.
      • Import the application into IDE.
      • Now open YML file and add the management configuration as below.
      • Run application and open browser and hit the below URL.
      http://localhost:8080/actuator/health

      • You will get the complete health with details as below.
      You can try with the different different endpoints like:

      You can also see the below output in postman.




      Thanks 
      Avinash Kumar Tiwari

      React JS Tutorial for Beginners

      This blog help you to self learn React JS step by step. In this tutorial react tutorial i have covered how to create  react js application, react crud application using rest api, react components. 

      To work with react JS to create Web application frontend, we have to follow the below steps:
      • First we have to download node js. To download node js please use below link.


      • Select According to the operating system, as I have selected LTS Windows Installer 64 bit.
      •  Download node JS and install.
      • To check the node JS version open command prompt and type npm -v  and then press enter as below.




        •  Run setup to Install Visual studio code.
       Create React Application.

      To create React application follow the below steps:


      • Open command prompt and move to the directory where you want to create application.

      • Type below command to create react application as below

      • As we can see in below screen app is creating. wait for a while.

      • After running successful react application will be created in below directory.


      Import Application to Visual Studio Code Tool.

       To Import follow below step.
      • Open command prompt and move to the application directory and type the below command.

      • After enter Visual studio Code tool will open with created application as below.

      How To Run The react application:
      To Run the default application follow the below steps.

      • Open terminal and type below command as show.

      • Type the below command to run the react application.

      • Compile successfully and application started using default port 3000 as below.

      • We can see the default look of application on web browser as below.
      react js,react,react tutorial,react js tutorial,reactjs,react course,react tutorial for beginners,reactjs tutorial,react api,react js project,learn react,react project,react application,react crud application from scratch,react app tutorial,react app,react components,react crash course,react usestate,reactjs tutorial for beginners