Skip to content

Druid

Collect Metrics related to Druid database connection pool.

Configuration

Expose Metrics related to Druid database connection pool through JMX, and read them through DDTrace. DDTrace reports the data through its internal statsd module.

1. Download DDTrace

wget -O dd-java-agent.jar 'https://truewatch.com/dd-image/dd-java-agent.jar'

2. Configure Druid JMX

Create a new file druid.yaml with the following content:

init_config:
  is_jmx: true
  collect_default_metrics: true

instances:
  - jvm_direct: true
    name: duird-DruidDataSource-monitoring
    collect_default_jvm_metrics: false
    collect_default_metrics: false
    refresh_beans: 60
    conf:
      - include:
          bean_regex: "com.alibaba.druid:type=DruidDataSource,id=\\d+"
          tags:
            pool: druid
          attribute:
            MaxActive:
              metric_type: gauge
              alias: druid.max_active
            ConnectCount:
              metric_type: gauge
              alias: druid.connect_count
            WaitThreadCount:
              metric_type: gauge
              alias: druid.wait_thread_count
            ActivePeak:
              metric_type: gauge
              alias: druid.active_peak
            InitialSize:
              metric_type: gauge
              alias: druid.initial_size
            ConnectErrorCount:
              metric_type: gauge
              alias: druid.connect_error_count
            ActiveCount:
              metric_type: gauge
              alias: druid.active_count
            CloseCount:
              metric_type: gauge
              alias: druid.close_count
            PoolingCount:
              metric_type: gauge
              alias: druid.pooling_count
            RecycleCount:
              metric_type: gauge
              alias: druid.recycle_count
            CreateCount:
              metric_type: gauge
              alias: druid.create_count
            DestroyCount:
              metric_type: gauge
              alias: druid.destroy_count
            CommitCount:
              metric_type: gauge
              alias: druid.commit_count
            RollbackCount:
              metric_type: gauge
              alias: druid.rollback_count              
            MaxWait:
              metric_type: gauge
              alias: druid.max_wait
            MinIdle:
              metric_type: gauge
              alias: druid.min_idle
            MaxIdle:
              metric_type: gauge
              alias: druid.max_idle

3. Adjust Startup Command

java \
-javaagent:/xxx/dd-java-agent.jar \
-Ddd.agent.port=9529 \
-Ddd.service=<application-name> \
-Ddd.jmxfetch.check-period=1000 \
-Ddd.jmxfetch.enabled=true \
-Ddd.jmxfetch.config.dir=/xxx/ \
-Ddd.jmxfetch.config=druid.yaml \
-jar xxxx.jar 

4. DataKit Collector Configuration

Since Druid Metrics are mainly processed and reported through DDTrace, enabling DDTrace will simultaneously collect APM and Metrics data. Therefore, two collectors need to be enabled.

  • Enable ddtrace collector

cd /usr/local/datakit/conf.d/ddtrace cp ddtrace.conf.sample ddtrace.conf

  • Enable statsd collector

cd /usr/local/datakit/conf.d/statsd cp statsd.conf.sample statsd.conf

  • Restart DataKit
systemctl restart datakit

Metrics

Measurement druid

Metric Description Unit
active_count The number of connections currently in use. count
active_peak The historical peak of active connections. count
close_count The number of connections that have been closed. count
commit_count The number of transactions committed. count
connect_count The total number of connections successfully established. count
connect_error_count The number of failed connection attempts. count
create_count The number of connections created. count
destroy_count The number of connections destroyed. count
initial_size The number of connections created when the connection pool is initialized. count
max_active The maximum number of active connections allowed in the connection pool. count
max_idle The maximum number of idle connections allowed in the connection pool. count
max_wait The maximum wait time to obtain a connection from the connection pool. ms
min_idle The minimum number of idle connections allowed in the connection pool. count
pooling_count The number of currently idle connections. count
recycle_count The number of connections recycled. count
rollback_count The number of transactions rolled back. count
wait_thread_count The number of threads currently waiting to obtain a connection. count