A practical tutorial on Spring boot application monitoring

Source: Internet
Author: User

Tag: Run the Access test event blank to avoid the annotation system telling

Overview

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.

We've talked about the visual monitoring of Docker containers, that is, monitoring the operation of the container, including CPU usage, memory consumption, network conditions, and disk space, and a range of information. In the same way, when using springboot as the instantiation Technology of micro-service unit, one of the unavoidable problems is how to monitor the health data of the application in real time, such as: Heath, running index, log information, thread condition and so on. This paper makes a little research on this problem and records the experiment process.

Getting Started with: Actuator plugins

The Actuator plugin is a service provided by Springboot native that can be used to output many endpoint information in an application by exposing endpoint routing. Real Combat!

Add Dependencies in Pom.xml:

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

After you start the Spring boot application, you can get some status information for the app as long as you enter the endpoint information in the browser.

Common endpoints are listed below, you can try it out in detail:

    • /info Application Basic Information
    • Health information of/health
    • /metrics Operating Indicator
    • /ENV environment variable Information
    • /loggers Log Related
    • /dump Thread-related information
    • /trace Request Call Trajectory

Of course, only/health and/info endpoints can be used at this time, and others cannot be accessed because of permissions issues. If you want to access the specified endpoint, you can add related configuration items to the YML configuration, such as the/metrics endpoint, which needs to be configured:

?
123 endpoints: metrics: sensitive: false

At this point the browser accesses the/metrics endpoint to get information such as the following:

?
1234567891011121314151617181920212223242526272829 { "mem": 71529, "mem.free": 15073, "processors": 4, "instance.uptime": 6376, "uptime": 9447, "systemload.average": -1.0, "heap.committed": 48024, "heap.init": 16384, "heap.used": 32950, "heap": 506816, "nonheap.committed": 23840, "nonheap.init": 160, "nonheap.used": 23506, "nonheap": 0, "threads.peak": 25, "threads.daemon": 23, "threads.totalStarted": 28, "threads": 25, "classes": 6129, "classes.loaded": 6129, "classes.unloaded": 0, "gc.copy.count": 74, "gc.copy.time": 173, "gc.marksweepcompact.count": 3, "gc.marksweepcompact.time": 88, "httpsessions.max": -1, "httpsessions.active": 0}

Of course, you can also turn on all endpoint permissions, just configure the following:

?
12 endpoints: sensitive: false

Because the Actuator plugin provides limited monitoring capabilities, and the UI is rudimentary, a more mature tool is needed

Spring Boot Admin Monitoring System

The SBA is a more evolved step based on actuator, a monitoring tool for the UI beautification package for the actuator interface. Let's experiment.

Start by creating a spring Boot Admin server project as a service side
The following dependencies are added to the pom.xml:

?
1234567891011 <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server</artifactId> <version>1.5.7</version></dependency><dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server-ui</artifactId> <version>1.5.7</version></dependency>

The spring Boot Admin is then enabled by adding annotations on the main class of the application

?
12345678 @EnableAdminServer @SpringBootApplication Code class= "Java keyword" >public class springbtadminserverapplication {  &NBSP; Public static void main (string[] args) { &NBSP; springapplication.run (springbtadminserverapplication. class &NBSP; } }

Start the program and the browser opens localhost:8081 view the Spring Boot admin Main Page:

Spring Boot Admin Main Page

At this point the application column is empty, waiting for the application to be monitored to join

Create a spring boot app to monitor

The following dependencies are added to the Pom.xml

?
12345 < dependency > &NBSP; < groupid >de.codecentric</ groupid > &NBSP; < artifactid >spring-boot-admin-starter-client</ artifactid > &NBSP; < version >1.5.7</ version > </ dependency >

Then add the following configuration in the YML configuration to register the app with the admin server:

?
123456 spring: boot: admin:  url: http://localhost:8081  client:  name: AdminTest

When the client application starts, the Admin service immediately pushes the message and tells you that Admintest is online:

Apply a live Push message

At this point go to the admin main interface to see, found that the client application has indeed been registered:

The client app is registered

View Detail

Detail information

View Metrics

Metrics information

View enviroment

enviroment Information

View JMX

JMX Information

View Threads

Threads Information

View Trace and details

Trace Information

Click the top journal to see the event changes for the monitored application:

Event change information for Applications

You can see clearly in the diagram that the app jumps from the Registration→unknown→up state.

All the endpoint information provided by the actuator plug-in is then tried all over the SBA.

Reference documents

http://codecentric.github.io/spring-boot-admin/1.5.7/

A practical tutorial on Spring boot application monitoring

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.