[Springboot] with Springboot Admin monitor your micro-service applications

1 Introduction

At present, the popular micro-services, the size of companies competing imitation, the single application split to pieces. More services, more instances running, operation and maintenance personnel to the pressure is even greater. If there are more than a dozen applications, just do Health Check has been a time-consuming enough. Smart Springboot provides Actuator interface, you can get very good use of inside information, but for a large number of services can not do anything.

Thanks to the power of the open source community, we have Springboot Admin . It monitors all applications registered in the service discovery up functions include health checks, JVM memory, INFO information, obtain the thread stack and stack information, reminders (e-mail, Slack, nails, custom ...) and so on. In short, it provides a very rich monitoring capabilities, reduce operation and maintenance personnel tasks.

file

Currently Springboot Admin (later referred to SBA latest version) for 2.2.0, this article demonstrates the use of the version.

Dual monitor mode 2

Client monitoring using SBA has two modes, one is the introduction of the Client- spring-boot-admin-starter-clientreliance, good Server configuration address information on it. Another model is to register all the Client-side service discovery (Eureka) to component, while the Server side also registered, so you can monitor all Server-side Client-side up.

The second model is more convenient, do not rely on the Client are added, the examples that follow use the second mode.

The server needs to be added dependent dependent SBA and Eureka Client, as follows:

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

Profile configuration information is as follows:

server.port=9000
spring.application.name=admin-monitor-service
eureka.client.service-url.defaultZone=http://localhost:8761/eureka/
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true

Micro-monitoring service can start after the (of course, Eureka and other Client also need to start and register), the effect is as follows:

file

The figure above shows a total of four applications are monitored:

A ADMIN-MONITOR-SERVICE, i.e. SBA itself;

There are two DATA-SERVICE, database operations for services;

There is a GATEWAY, gateway services, namely Zuul.

Can see the name of the service, you can still see its version number.

3 protecting your SBA

3.1 Server protection

Now enter the SBA launched directly address can access, no password, which is obviously unsafe. SBA is also a Springboot nature of Web applications, security and access control can be done with Spring Security.

Spring Security dependency added as follows:

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

Configuring user and password:

spring.security.user.name=admin
spring.security.user.password=admin

After restarting the application, you need a password to access the landing, as follows:

file

Spring Security is actually stronger than this, we can configure the more sensitive information is protected, such as access to HeamDump files, log level changes and so on.

Note: Even with the above measures, we can not guarantee the safety Server. To be more safe to use SBA, by adding SSL, it runs over https.

3.2 Protection Client

Currently we have put all Endpoints Client are exposed, and this is very dangerous, we can select the exposure information needs. In addition, we can also set the Client account password protection, only those with the correct account password, Server-side before they can get permission to monitor.

4 monitoring

SBA provides a wealth of monitoring functions for us, we chose a few to show it.

4.1 Health Check and see details

SBA will monitor whether health services, including applications and application components, such as database connections.

file

  • INFO Information

FIG info information there on, this is a custom configuration is very convenient, as the version number of the configuration code and the like.

info.author=Larry Deng
info.version=1.0.3
  • Beans

You can view all the beans information.

  • Configuration Properties

View the current application configuration information used.

  • Scheduled Tasks

Check the timing of scheduled tasks being used.

4.2 log Loggers

Show the current log level, the more powerful is that it can be adjusted in real time log level, without having to change log4j2 profile, do not restart. When there are issues that need more detailed log, and very convenient.

file

4.3 JVM information (threads and memory)

You can view real-time status of each thread, and can download Thread Dump files to facilitate fault analysis time. Similarly, Heap Dump file can be downloaded, while holding high memory, not GC, can be used to analyze.

file

4.4 Other

Mappings can view Endpoints path and return type and the like methods.

Caches can view the cache used by the application, and can operate as empty the cache.

5 powerful reminders

While the SBA provides a powerful monitoring capabilities, but has been staring at the screen to manually too inefficient a. To this end, SBA provides a powerful reminder feature that an alarm in the event of service status changes. Supported reminders are:

  • Email
  • PagerDuty
  • OpsGenie
  • HipChat
  • Slack
  • Let's Chat
  • Telegram

Wait.

It also supports custom, allowing the integration of richer reminders, such as text messages, phone.

5.1 e-mail alert

In order to prevent too much space, just below show how to use e-mail alert function, others refer to the user manual.

Add a mail-dependent:

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

Configuration parameters:

spring.mail.host=smtp.example.com
spring.mail.username=smtp_user
spring.mail.password=smtp_password
[email protected]

Mail alert other configuration items:

file

5.2 custom alerts

Custom alerts is very simple, as long as the interface to achieve Notifier on the line, would have a direct inheritance AbstractEventNotifieror AbstractStatusChangeNotifiertwo classes. In the process of logic doNotifyimplementations.

public class CustomNotifier extends AbstractEventNotifier {
  private static final Logger LOGGER = LoggerFactory.getLogger(LoggingNotifier.class);

  public CustomNotifier(InstanceRepository repository) {
    super(repository);
  }

  @Override
  protected Mono<Void> doNotify(InstanceEvent event, Instance instance) {
    return Mono.fromRunnable(() -> {
      if (event instanceof InstanceStatusChangedEvent) {
        LOGGER.info("Instance {} ({}) is {}", instance.getRegistration().getName(), event.getInstance(),
            ((InstanceStatusChangedEvent) event).getStatusInfo().getStatus());
      }
      else {
        LOGGER.info("Instance {} ({}) {}", instance.getRegistration().getName(), event.getInstance(),
            event.getType());
      }
    });
  }
}

Summary 6

SBA is very strong, difficult to complete an article, you can refer to the user manual .

In addition, service discovery is not necessary to use Eureka, as Nacos also supported. Use only the SBA is not enough, for the monitoring of log, you can use ELK, this is a digression, free again after finishing it.


Welcome to public concern number < pumpkin slow, said >, you will continue to update ...

file

Welcome Gabor main micro-letters, make a point of the Friends of praise, ha ha ...

file

More books, more sharing; and more writing, more than finishing.

Guess you like

Origin www.cnblogs.com/larrydpk/p/12044660.html