HikariCP
Collect HikariCP related metrics
Configuration¶
DataKit Collector Collection¶
- Enable the
statsdcollector
Navigate to conf.d/samples under the DataKit installation directory, and copy statsd.conf.sample to statsd.conf
cp prom.conf.sample master.conf
- Enable the
ddtracecollector
Navigate to conf.d/ddtrace under the DataKit installation directory, and copy ddtrace.conf.sample to ddtrace.conf
cp ddtrace.conf.sample ddtrace.conf
- Execute the following command to restart Datakit
Client Configuration¶
Take a Java Demo application as an example to collect Druid connection pool metrics and traces
- 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
-
Configure JMX
-
Download
dd-java-agent
- Create a
hikaricp.yamlfile 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
Here, -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. Here, we mainly introduce the description of HikariCP related metrics
| Metrics | Description | Use Case | Unit |
|---|---|---|---|
connections_active |
Current active database connections |
Indicates the number of connections currently being used by the application | count |
connections_idle |
Current idle database connections |
Indicates the number of connections that are not being used and are in an idle state | count |
connections_pending |
Current number of requests waiting to obtain a connection |
If this value is high, it may indicate that the size of the connection pool is insufficient to meet the current concurrency demand | count |
connections_total |
Total number of database connections in the current connection pool |
Includes both active and idle connections | count |
idle_timeout |
Maximum survival time for idle connections |
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 |
Configuration item, if a connection is occupied for longer than this threshold, the connection pool will consider that there may be a connection leak and issue a warning. | ms |
max_lifetime |
Maximum lifetime of a connection |
Configuration item, the total survival time of a connection from creation to closure cannot exceed this value | ms |
min_idle |
Minimum number of idle connections in the connection pool |
Configuration item, the connection pool will ensure that there are 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 |
Configuration item, this value limits the size of the connection pool to prevent excessive resource consumption by too many connections | count |
validation_timeout |
Connection validation timeout |
Configuration item, when obtaining a connection from the connection pool, the connection pool will validate the connection's effectiveness. If the validation time exceeds this value, the validation is considered to have failed | ms |
connections_timeout |
Connection timeout |
Configuration item, maximum wait time to establish a connection | ms |