Springboot Application Monitoring and management

Source: Internet
Author: User

Spring Bootapplication monitoring and management

Spring Boot monitoring Core is spring-boot-starter-actuator dependency, after increasing the dependency, spring boot will default to configure some common monitoring, such as JVM monitoring, class loading, health monitoring and so on.

To monitor and manage applications, we only need to add dependencies on the Pom.xml:

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-actuator</artifactId>

</dependency>

If you are using HTTP, you need to add the following dependencies:

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-web</artifactId>

</dependency>

first, monitoring the role of the endpoint:

Depending on the purpose of the endpoint, you can divide the endpoints into three main categories:

Application Configuration classes: Get application-related information such as app configuration, environment variables, automated configuration reports, etc. loaded in the application.

Metric class: Gets the metrics that are used for monitoring during application run, such as memory information, thread information, HTTP requests, and so on.

Operation Control class: Provides operation class functions such as closing the application.

1. Apply the Configuration class:

(1)/autoconfig: Get Automated configuration usage for your app, including candidates for all automation configurations. It also lists whether each candidate matches successfully and why there is no successful match. Positivematches returns an automated configuration that matches successfully, and Negativematches returns a matching unsuccessful automation configuration.

(2)/configprops: Gets the app configuration all configuration properties. Prefix represents the attribute prefix, properties represents the property name and ID, and so on.

(3)/beans: Gets all the beans created in the application. Each bean contains bean, scope, type, resource, dependencies.

(4)/env: Get environment information for your app. Contains environment variables, JVM properties, app configuration properties, parameters, ports, and so on.

(5)/mappings: Returns all controller mapping relationship reports, including the business interface and the monitoring interface.

(6)/info: Get app custom information, default is empty. Can be configured within the application.properties itself.

2. Metric class:

(7)/metrics: Returns information on important metrics such as memory profile, heap memory information, non-heap memory information, thread usage, class statistics for app load and unload, garbage collector details, Tomcat container usage, HTTP request performance metrics, and more.

(8)/health: Get information about the various indicators of the application. You can also customize health monitoring yourself.

(9)/dump: Used to generate a snapshot of the current thread activity.

()/trace: Used to return basic HTTP trace information. Keep the last 100 HTTP request records.

3. operation control class:

(one)/shutdown: It is a direct shutdown of the application's endpoint, which is not the same as the previous endpoint, the preceding endpoint is enabled by default, and it needs to be configured with properties to open the operation. Can be configured to open in Application.properties:

Endpoints.shutdown.enabled=true

4.( -------- )

/HEAPDUMP:SPRINGMVC endpoint, which returns the gzip compressed hprof heap dump file (ending with hprof.gz)

/loggers: Ability to view the log levels of all package classes and to modify them.

/actuator: A list of all endpoints, that is, the list of interfaces for application monitoring.

(/auditevents): Exposes audit event information for the current application.

: Where/shutdown is a POST request, the other is a GET request.

: If the log level is modified, a POST request is required and the JSON (APPLICATION/JSON) data format needs to be transferred. It is tested and found that the Logback log level can be dynamically modified if it is initiated through the Springboot main program entry, if the dynamic modification log level is not valid after packaging runs under Linux.

second, monitoring the management of the endpoint

1. If the above monitoring endpoint is inaccessible, it is possible that your management port is often protected by a firewall and does not need to protect the management endpoint from external exposure. At this point you need to add: application.properties.

Management.security.enabled=false

You can also set individual settings, such as Endpoints.mappings.sensitive=false, to turn off the/mappings security restrictions.

2. Customizing endpoint access paths and access ports

By default, the interface ports that are monitored are consistent with the ports of the business. Like what

server.context-path=/student,server.port=20000

So this time we access the/info monitoring interface URL is: Http://xxx.xxx.xxx.xxx:20000/student/info. If you also have a/info interface inside the business interface, the access path is exactly the same as Http://xxx.xxx.xxx.xxx:20000/student/info, then the information obtained is the information that monitors the endpoint info, which is invalid. What if you want to make it work? Then you can disable the info monitoring endpoint, but if the info endpoint needs to return some information that cannot be disabled, and your business info interface has been called and you don't want to change it, how do you make it work? At this point we can make the following settings in Application.properties:

Management.context-path=/manage

management.port=20001

So what does your access path to your/info monitoring endpoint turn out to be? That's what it should be like:

Http://xxx.xxx.xxx.xxx:20001/manage/info

At this point your business interface is working, and its access path is the one above. The port that changes the access of the endpoint is also for security reasons.

3. Disabling a single endpoint

Endpoints.info.enabled=false Disabling/info Endpoints

4. Open the desired endpoint

Endpoints.enabled=false Disabling all Endpoints

Endpoints.info.enabled=true Open the desired/info endpoint

5. Modify the Endpoint ID

Endpoints.info.id=myinfo

The original access URL is Http://xxx.xxx.xxx.xxx:20000/student/info, then changed to become Http://xxx.xxx.xxx.xxx:20000/student/myinfo

In the 2nd above you want to make the business interface/info valid, you can also change the ID of the monitoring port in this way.

6. Turn off the HTTP endpoint

Management.port=-1

Springboot Application Monitoring and management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.