Skip to content

HikariCP

Collect HikariCP related Metrics information

Configuration

DataKit Collector Collection

  • Enable statsd collector

Enter the DataKit installation directory under conf.d/statsd, copy statsd.conf.sample to statsd.conf

cp prom.conf.sample master.conf

  • Enable ddtrace collector

Enter the DataKit installation directory under conf.d/ddtrace, copy ddtrace.conf.sample to ddtrace.conf

cp ddtrace.conf.sample ddtrace.conf

  • Execute the following command to restart Datakit
datakit service -R

Client Configuration

Take a Java Demo application as an example, collecting Druid connection pool Metrics and APM traces.

  1. The connection pool configuration in the Demo project is as follows:
spring.datasource.url=jdbc:mysql://xx.xxx.xx.xxx:3306/test?useSSL=false&useLegacyDatetimeCode=false&allowPublicKeyRetrieval=true
spring.datasource.username=***
spring.datasource.password=*****
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.maximum-pool-size=10
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.idle-timeout=300000
spring.datasource.hikari.max-lifetime=1800000
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.pool-name=HikariCP
spring.datasource.hikari.register-mbeans=true
  1. Configure JMX

  2. Download the Guance version of dd-java-agent.jar

wget -O dd-java-agent.jar 'https://static.guance.com/dd-image/dd-java-agent.jar'
  • Create a hikaricp.yaml file with the following content:
init_config:

instances:
  - jvm_direct: true
    name: hikari-slick-monitoring
    collect_default_jvm_metrics: false
    collect_default_metrics: false
    refresh_beans: 60
    conf:
      - include:
          bean_regex: "com.zaxxer.hikari:type=Pool \\((.*)\\)"
          tags:
            pool: $1
          attribute:
            ActiveConnections:
              metric_type: gauge
              alias: hikaricp.connections.active
            IdleConnections:
              metric_type: gauge
              alias: hikaricp.connections.idle
            TotalConnections:
              metric_type: gauge
              alias: hikaricp.connections.total
            ThreadsAwaitingConnection:
              metric_type: gauge
              alias: hikaricp.connections.pending
      - include:
          bean_regex: "com.zaxxer.hikari:type=PoolConfig \\((.*)\\)"
          tags:
            pool: $1
          attribute:
            MaximumPoolSize:
              metric_type: gauge
              alias: hikaricp.pool.size.max
            IdleTimeout:
              metric_type: gauge
              alias: hikaricp.idle.timeout
            MaxLifetime:
              metric_type: gauge
              alias: hikaricp.max.lifetime
            MinimumIdle:
              metric_type: gauge
              alias: hikaricp.min.idle
            ConnectionTimeout:
              metric_type: gauge
              alias: hikaricp.connections.timeout
            ValidationTimeout:
              metric_type: gauge
              alias: hikaricp.validation.timeout
            LeakDetectionThreshold:
              metric_type: gauge
              alias: hikaricp.leak.detection.threshold
  • Adjust the startup command
java \
-javaagent:/xxx/dd-java-agent.jar \
-Ddd.agent.port=9529 \
-Ddd.service=demo \
-Ddd.jmxfetch.check-period=1000 \
-Ddd.jmxfetch.enabled=true \
-Ddd.jmxfetch.config.dir=/xxx/ \
-Ddd.jmxfetch.config=hikaricp.yaml \
-jar xxxx.jar 

Where -Ddd.jmxfetch.config.dir=/xxx/ is the directory where the hikaricp.yaml configuration file is located.

Metrics

HikariCP Measurement

HikariCP Metrics are located under the hikaricp Measurement set. Below is an introduction to the relevant Metrics of HikariCP.

Metrics Description Usage Unit
connections_active The number of currently active database connections Indicates the number of connections being used by the application count
connections_idle The number of currently idle database connections Indicates the number of unused, idle connections count
connections_pending The number of requests waiting to acquire a connection If this value is high, it may indicate that the size of the connection pool is insufficient to meet current concurrency demands count
connections_total The total number of database connections in the current connection pool Includes both active and idle connections count
idle_timeout The maximum survival time for idle connections A configuration item; when a connection's idle time exceeds this value, the connection pool will close it ms
leak_detection_threshold Connection leak detection threshold A configuration item; if a connection is occupied for longer than this threshold, the connection pool will consider there may be a connection leak and issue a warning ms
max_lifetime The maximum lifecycle of a connection A configuration item; the total survival time from creation to closure of a connection cannot exceed this value ms
min_idle Minimum number of idle connections in the connection pool A configuration item; the connection pool ensures at least this many idle connections to quickly respond to new requests count
pool_size_max Maximum number of connections allowed in the connection pool A configuration item; this value limits the size of the connection pool, preventing too many connections from consuming excessive resources count
validation_timeout Connection validation timeout A configuration item; during the acquisition of a connection from the connection pool, the connection pool validates the validity of the connection. If the validation time exceeds this value, it is considered a failed validation ms
connections_timeout Connection timeout A configuration item; the maximum wait time to establish a connection ms

Feedback

Is this page helpful? ×