Springboot (20): Monitoring the Spring-boot service with Spring-boot-admin

Source: Internet
Author: User
Tags spring boot actuator

The previous article "Springboot (19): Using the spring boot Actuator Monitoring app" describes the use of Spring boot actuator, and Spring boot actuator provides monitoring of a single spring boot. Information includes: Application status, memory, threads, stacks, and more, and more comprehensive monitoring of the entire life cycle of the spring boot application.

However, there are some problems with this monitoring: first, all the monitoring needs to call a fixed interface to view, if the full view of the application state needs to call many interfaces, and the interface returned by the JSON information is not convenient for operators to understand; second, if the Spring boot application cluster is very large, Each application needs to invoke a different interface to view the monitoring information, and the operation is cumbersome and inefficient. In this context, another open source software was born:Spring Boot Admin.

What is Spring Boot Admin?

Spring Boot Admin is an open source software for managing and monitoring spring boot applications. Each application is considered a client, and is registered with the Admin server via HTTP or using Eureka, and the Spring Boot Admin UI section uses ANGULARJS to present the data to the front end.

Spring Boot Admin is a monitoring tool for UI beautification encapsulation of the actuator interface for Spring-boot. He can: Browse through the list of all monitored spring-boot items, detailed health information, memory information, JVM information, garbage collection information, various configuration information (such as data sources, cache lists, and hit ratios), and can also directly modify the level of logger.

This article shows you how to use Spring boot admin to monitor the spring boot application.

Monitoring monomer applications

This section shows you how to use Spring boot admin to monitor a single spring boot application.

Admin Server Side

Project Dependencies

<dependencies>  <dependency>    <groupId>de.codecentric</groupId>    <artifactId>spring-boot-admin-server</artifactId>    <version>1.5.6</version>  </dependency>  <dependency>    <groupId>de.codecentric</groupId>    <artifactId>spring-boot-admin-server-ui</artifactId>    <version>1.5.6</version>  </dependency></dependencies>

Configuration file

server.port=8000

The server port is set to: 8000.

Start class

@Configuration@EnableAutoConfiguration@EnableAdminServerpublicclass AdminServerApplication {  publicstaticvoidmain(String[] args) {    SpringApplication.run(AdminServerApplication.class, args);  }}

After completing the above three steps, start the server side, browser access http://localhost:8000 can see the following interface:

Sample code

Admin Client Side

Project Dependencies

<dependencies>  <dependency>    <groupId>de.codecentric</groupId>    <artifactId>spring-boot-admin-starter-client</artifactId>    <version>1.5.6</version>  </dependency></dependencies>

Configuration file

server.port=8001spring.boot.admin.url=http://localhost:8000  

- spring.boot.admin.url Configure the address of the admin server
- management.security.enabled=false Turn off security verification

Start class

@SpringBootApplicationpublicclass AdminClientApplication {  publicstaticvoidmain(String[] args) {    SpringApplication.run(AdminClientApplication.class, args);  }}

After the configuration is complete, start the client service and re-access the service: http://localhost:8000 you can see information about the client.

The home page will show the various services being monitored, click on the details to see the specific monitoring information of a service

As you can see, Spring boot admin Displays the application's information graphically, mostly from the interface provided by spring boot actuator.

Micro-Service Monitoring

If we are using a single Spring boot application, we need to configure the address information for the admin server in each of the monitored apps, and if the app is registered in Eureka, it doesn't need to be configured for each application, Spring boot Admin automatically crawls information about your app from the registry.

Here is a demonstration using four sample projects:

    • Spring-boot-admin-server Admin Server Side
    • Spring-cloud-eureka Registration Center
    • Spring-cloud-producer application One, Admin client side
    • Spring-cloud-producer-2 application Two, Admin client side

First start the registry Spring-cloud-eureka, if the Eureka do not know the classmate can view this article Springcloud (ii): Registry Eureka

Server Side

Example Project: Spring-boot-admin-server

Project Dependencies

<dependencies>  <dependency>    <groupId>Org.springframework.cloud</groupId>    <artifactId>Spring-cloud-starter-eureka</artifactId>  </dependency>  <dependency>    <groupId>De.codecentric</groupId>    <artifactId>Spring-boot-admin-server</artifactId>    <version>1.5.6</version>  </dependency>  <dependency>    <groupId>De.codecentric</groupId>    <artifactId>Spring-boot-admin-server-ui</artifactId>    <version>1.5.6</version>  </dependency></dependencies>

Increased support for Eureka

Configuration file

server:  port: 8000spring:  application:    name: admin-servereureka:  instance:    leaseRenewalIntervalInSeconds: 10  client:    registryFetchIntervalSeconds: 5    serviceUrl:      defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/management.security.enabled: false

Eureka configuration is added to the configuration file

Start class

@Configuration@EnableAutoConfiguration@EnableDiscoveryClient@EnableAdminServerpublicclass AdminServerApplication {  publicstaticvoidmain(String[] args) {    SpringApplication.run(AdminServerApplication.class, args);  }}

When the above steps are complete, start the server side.

Client Side

Example projects: Spring-cloud-producer and Spring-cloud-producer-2

Project Dependencies

<dependencies>  <dependency>    <groupId>org.springframework.cloud</groupId>    <artifactId>spring-cloud-starter-eureka</artifactId>  </dependency>  <dependency>    <groupId>de.codecentric</groupId>    <artifactId>spring-boot-admin-starter-client</artifactId>    <version>1.5.6</version>  </dependency></dependencies>

Configuration file

server:  port: 9000spring:  application:    name: producereureka:  client:    serviceUrl:      defaultZone: http://localhost:8761/eureka/management:  security:    enabled: false

We found that the configuration file did not add the relevant configuration of the admin server

Start class

@SpringBootApplication@EnableDiscoveryClientpublicclass ProducerApplication {  publicstaticvoidmain(String[] args) {    SpringApplication.run(ProducerApplication.class, args);  }}

Web tier

@RequestMapping("/hello")  publicindex(@RequestParam String name) {      logger.info("request one/two  name is "+name);      return"hello "+name+",this is first messge";  }

The Web tier adds a/hello request method that uses One/two to distinguish which application. Spring-cloud-producer-2 and Spring-cloud-producer code are similar, you can see the sample code.

After completing the above configuration, start the project separately: Spring-cloud-producer and spring-cloud-producer-2, browser access http://localhost:8000 can see the following interface:

You can see that the admin server monitors four instances, including the server itself, the registry, and two producer. Note the admin server automatically fetches all instance information from the service center and monitors it. Click Detail to see the monitoring information for a particular example.

Sample code

Email alerts

Spring Boot Admin Shows all the application information in the micro-service in the background, so it is very convenient for us to monitor and govern the micro-service overall. But our operators are not able to stare at the background 24 hours a day, so if the service is abnormal, there is a corresponding message alarm is too good, in fact, Spring Boot Admin also gave support.

We have modified the example project Spring-boot-admin-server above.

Add dependency

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

Added starter packets sent by mail

Configuration file

spring:  mail:    host: smtp.qq.com    username: [email protected]    password: xxxx    properties:      mail:        smtp:          auth: true          starttls:            enable: true            required: true  boot:    admin:      notify:        mail:          from: [email protected]          to: [email protected]# http://codecentric.github.io/spring-boot-admin/1.5.6/#mail-notifications

Add messages to the configuration file: Sender, recipient, protocol, mobile authorization code, etc. For spring boot mail, refer to Springboot (10): Mail Service

After the configuration is complete, restart the project Spring-boot-admin-server, so that the admin server has the function of the message alarm, by default, the admin server to the Eureka service on the downline are monitored, When the service is offline we will receive the following email:

Of course, this is only the most basic mail monitoring, in the actual use of the process, we need to according to our situation on the message alarm content customization, such as monitoring the use of heap memory, when reaching a certain percentage of the time to alarm.

Sample code

Reference

Spring Boot Admin Reference Guide

Springboot (20): Use Spring-boot-admin to monitor the Spring-boot service

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.