You must know the Druid monitoring distributed solution

What is Druid Monitor

Druid is a very powerful database connection pool, but its power is not only reflected in the speed of data access and connection management as a high-performance connection pool, it has a built-in powerful monitoring tool: Druid Monitor . Not only can monitor data sources and slow queries, but also monitor web applications, URI monitoring, Session monitoring, Spring monitoring, etc.

  • ip:port/druid/sql.html

Welfare Welfare Welfare Free to receive Java architecture skills map Note that it is free to send

Get the required +V for free

What is Druid Admin

  • As mentioned above, Druid Monitor provides powerful monitoring capabilities, but currently it is only for monitoring a single service instance . In the micro-services architecture [1] increasingly popular nowadays, have the same service may have N instances, monitored dimension needs to rise to the cluster .

  • After the official version of druid 1.2.1, the druid-admin[2] module is provided to solve the problem of cluster monitoring.

  • As shown in the figure below, we can dynamically switch the service name on the original monitoring cluster to achieve a monitoring entry and realize the monitoring switching of different services .

Spring Cloud Stater package

  • The official druid-admin is currently under development and cannot be directly compiled and run (depending on package error, java11 not supported, etc.).

  • druid-admin itself is a directly runnable web service, which is not very friendly to existing services and cannot do the plug and play of spring boot admin[3]

  • Therefore, based on the above problems, the author made relevant modifications to druid-admin and directly extracted it into a spring boot starter and introduced it for use.

1. Increase dependence

  <dependency>
   <groupId>com.pig4cloud.plugin</groupId>
   <artifactId>spring-cloud-starter-druid-monitor</artifactId>
   <version>0.0.1</version>
  </dependency>


  <!--注册中心客户端(支持 nacos/eureka/consul)-->
  <dependency>
   <groupId>com.alibaba.cloud</groupId>
   <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
  </dependency>
复制代码

2. Access to the registry and list of services to be monitored

spring:
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848

# druid-admin 需要监控的列表
monitor:
  applications:
    - pigx-upms-biz
    - pigx-auth
复制代码

3. The target service exposes the druid monitoring endpoint

spring:
  datasource:
    druid:
      stat-view-servlet:
        enabled: true
        allow: ""
        url-pattern: /druid/*
复制代码

4. Visit druid-admin to view cluster monitoring

  • ip:port/druid/sql.html

Integrate Spring Boot Admin

  • Introduce the above dependencies and add the following configuration

spring:
  boot:
    admin:
      ui:
        external-views:
          - label: "SQL监控"
            url: /druid/sql.html
            order: 2000
复制代码

Use restrictions

  • Since the login verification of druid monitor is based on session design, it is not applicable to stateless microservices. It is recommended to directly expose all druid-related endpoints and unify interface permissions through the front gateway.

  • The current instance monitoring data is stored in the corresponding memory, and is only displayed after being summarized by each instance during viewing, and will be persisted later.

 

Guess you like

Origin blog.csdn.net/yuandengta/article/details/109200751