Skip to content

codingkiddo/custom-jdbc-pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

custom-jdbc-pool

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.

Build

cd custom-jdbc-pool
mvn -q -DskipTests package

Plain Java usage

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();

Spring Boot (3.x)

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.

Prometheus & Grafana (docker-compose)

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).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published