A lightweight custom JDBC connection pool with Micrometer metrics and optional Spring Boot auto-configuration.
⚠️ For real production loads, prefer HikariCP. This project is primarily educational or for controlled environments.
cd custom-jdbc-pool
mvn -q -DskipTests package
import com.codingkiddo.pool.CustomConnectionPool;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.micrometer.prometheus.PrometheusConfig;
import com.codingkiddo.pool.metrics.MetricsHttp;
var reg = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
MetricsHttp.startPrometheusEndpoint(reg, 9090); // scrape http://localhost:9090/metrics
var ds = new CustomConnectionPool.Builder()
.url("jdbc:postgresql://localhost:5432/appdb")
.credentials("appuser", "secret")
.maxPoolSize(16)
.minIdle(4)
.meterRegistry(reg)
.poolName("orders-db")
.build();
Add dependency:
<dependency>
<groupId>com.codingkiddo</groupId>
<artifactId>custom-jdbc-pool</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
application.yaml
:
management:
endpoints.web.exposure.include: "prometheus,health,info"
endpoint.prometheus.enabled: true
metrics.tags.application: demo-app
ck:
datasource:
enabled: true
url: jdbc:postgresql://localhost:5432/appdb
username: appuser
password: secret
pool-name: orders-db
min-idle: 4
max-pool-size: 16
connection-timeout-ms: 2000
idle-timeout-ms: 60000
max-lifetime-ms: 1800000
validation-timeout-seconds: 1
# test-query: SELECT 1
Now Boot will create the pool and expose metrics at /actuator/prometheus
.
version: "3.9"
services:
prometheus:
image: prom/prometheus:latest
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
ports: ["9090:9090"]
grafana:
image: grafana/grafana-oss:latest
ports: ["3000:3000"]
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin
prometheus.yml
(for Spring Boot app on localhost):
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'app'
static_configs:
- targets: ['host.docker.internal:8080'] # Boot app
metrics_path: /actuator/prometheus
Import the provided Grafana dashboard (JSON in your ChatGPT message).