Backend Development 6 min read

How to Integrate Druid Monitor with Spring Cloud: A Step‑by‑Step Guide

This article explains what Druid Monitor and Druid Admin are, why cluster‑level monitoring is needed in microservice architectures, and provides a complete Spring Cloud starter implementation with configuration examples, code snippets, and usage limitations.

Java Architecture Diary
Java Architecture Diary
Java Architecture Diary
How to Integrate Druid Monitor with Spring Cloud: A Step‑by‑Step Guide

What is Druid Monitor

Druid is a powerful database connection pool that includes a built‑in monitoring tool called Druid Monitor, which can monitor data sources, slow queries, web applications, URI, session, Spring, and more.

ip:port/druid/sql.html

What is Druid Admin

As mentioned, Druid Monitor only monitors a single service instance. In the increasingly popular microservice architecture, the same service may have N instances, so monitoring needs to be at the cluster level.

Since Druid 1.2.1, the official project provides a druid-admin module to solve cluster monitoring.

The diagram shows that the monitoring cluster can dynamically switch service names, achieving a single monitoring entry for different services.

Spring Cloud Starter Packaging

The current official druid-admin is still under development and cannot be compiled or run directly due to dependency errors and lack of Java 11 support.

druid-admin itself is a standalone web service, which is not friendly to existing services and cannot provide the plug‑and‑play experience of Spring Boot Admin.

Therefore the author modified druid-admin, extracting it into a Spring Boot starter for immediate use.

1. Add Dependency

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

<!-- Registration center client (supports nacos/eureka/consul) -->
<dependency>
  <groupId>com.alibaba.cloud</groupId>
  <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>

2. Register Discovery Center and Services to Monitor

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

# druid-admin monitoring list
monitor:
  applications:
    - pigx-upms-biz
    - pigx-auth

3. Expose Druid Monitoring Endpoint in Target Services

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

4. Access druid-admin to View Cluster Monitoring

ip:port/druid/sql.html

Integrate with Spring Boot Admin

After adding the above dependencies, add the following configuration.

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

Usage Limitations

Because Druid Monitor’s login validation is session‑based, it is not suitable for stateless microservices; it is recommended to expose all Druid endpoints and control permissions via a front‑gate.

Currently, monitoring data is stored in memory per instance and aggregated only when viewed; persistence will be added later.

References

[1] Microservice architecture: https://gitee.com/log4j/pig

[2] druid-admin: https://github.com/alibaba/druid/tree/master/druid-admin

[3] spring boot admin: https://github.com/codecentric/spring-boot-admin

javamonitoringMicroservicesSpring BootSpring CloudDruid
Java Architecture Diary
Written by

Java Architecture Diary

Committed to sharing original, high‑quality technical articles; no fluff or promotional content.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.