Spring Boot - Spring Boot advanced three SpringBoot actuator Application Monitoring

First, monitoring and management

First let us look at what the monitoring center?

Service status for micro services including http request resources, server memory change (heap memory, threads, log management, etc.), testing services to configure the connection address is available (analog access, lazy loading conditions), the statistics now how many bean ( is spring container bean), statistical spring MVC's @ResultMapping (http Interface statistics).

Spring Boot provides two monitoring center:

  • Actuator monitoring applications: no interface, return json format;

  • AdminUi: Actuator bottom is used to monitor the application, to achieve the visual interface;

1, Actuator monitoring applications

Actuator Spring Boot is an additional feature that helps you monitor when the application production environment and management applications. You can use a variety of regulatory http request, the audit, the operation of collecting applications, especially very meaningful for micro-management services.

2, New Project

Create a new project springboot-actuator, add dependencies:

 <-!   Spring Starter-Boot-parent-dependent information integration with third party common frame (various kinds of information lead) -> 
    < parent > 
        < the groupId > org.springframework.boot </ the groupId > 
        < the artifactId > Spring-boot - parent-Starter </ artifactId > 
        < Version > 2.2.2.RELEASE </ Version > 
    </ parent > 


    < the Dependencies > 
        <-!   the Spring-the Boot-Starter-Web is a Web MVC Spring Boot integrate the Spring   -> 
        <!-   corresponds to the third party used Maven dependent information in the parent project a good package, use Spring Boot provided Jar package dependency information associated Integration ->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!--  actuator监控中心  -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

    </dependencies>

New Package com.goldwind.controller, create IndexController.java in the package:

package com.goldwind.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: zy
 * @Description: 控制器
 * @Date: 2020-2-7
 */
@RestController
public class IndexController {

    @RequestMapping("/index")
    public String index(){
        return "index";
    }
}

New application.yml file in src / java / resources:

# Enable the following configuration of all monitoring endpoints, by default, these endpoints are disabled; 
Management: 
  Endpoints: 
    Web: 
      Exposure: 
        the include: "*"

Run the program, visit http: // localhost: 8080 / actuator / mappings can see which API currently supports the request:

The role of the endpoint, spring-boot-starter-actuator module natively endpoint may be divided into three categories:

  • Application configuration class: class obtain configuration information is closely related to the Spring Boot application application loading the application configuration, environment variables, automated configuration reports;
  • Metrics categories: acquisition application is running for metrics monitoring, information such as memory, thread pool information, HTTP requests statistics;
  • Operation control class: Providing the close of the application and other operations based functions;

We introduce a few common primary endpoint, by actuator / + endpoint names can get the appropriate information:

path

effect

/actuator/beans

For a complete list of all Spring bean display applications.

/actuator/configprops

Display all configuration information.

/actuator/env

Display all environment variables.

/actuator/mappings

Show all @RequestMapping the url finishing list.

/actuator/health

Display application health information up for success down failure

/actuator/info

View Custom Application Information

More information is available blog: SpringBoot Actuator Application Monitoring .

Guess you like

Origin www.cnblogs.com/zyly/p/12273086.html