| Crates.io | dbpulse |
| lib.rs | dbpulse |
| version | 0.8.3 |
| created_at | 2019-04-11 17:08:58.181679+00 |
| updated_at | 2025-11-21 05:48:27.853217+00 |
| description | command line tool to monitor that database is available for read & write |
| homepage | https://github.com/nbari/dbpulse |
| repository | https://github.com/nbari/dbpulse |
| max_upload_size | |
| id | 127339 |
| size | 495,569 |
A lightweight database health monitoring tool that continuously tests database availability for read and write operations. It exposes Prometheus-compatible metrics for monitoring database health, performance, and operational metrics.
Like a paramedic checking for a pulse, dbpulse performs quick vital sign checks on your database. It goes beyond simple connection tests by performing real database operations (INSERT, SELECT, UPDATE, DELETE, transaction rollback) at regular intervals to verify that your database is truly alive and accepting writes, not just accepting connections.
Quick Pulse Check: Is the database responsive and healthy? โ Vital Signs: Latency, errors, read-only status, replication lag ๐ Emergency Indicators: Blocking queries, locked tables, connectivity issues ๐จ
This is particularly useful for:
The tool protects itself from hanging on locked tables using configurable timeouts (5s statement timeout, 2s lock timeout), ensuring the health probe remains responsive.
# PostgreSQL
dbpulse --dsn "postgres://user:password@tcp(localhost:5432)/mydb"
# MySQL/MariaDB
dbpulse --dsn "mysql://user:password@tcp(localhost:3306)/mydb"
# With custom interval and range
dbpulse --dsn "postgres://user:pass@tcp(db.example.com:5432)/prod" \
--interval 60 \
--range 1000 \
--port 9300
Access metrics at http://localhost:9300/metrics
dbpulse [OPTIONS] --dsn <DSN>
| Option | Environment Variable | Description |
|---|---|---|
-d, --dsn <DSN> |
DBPULSE_DSN |
Database connection string (see DSN Format below) |
| Option | Environment Variable | Default | Description |
|---|---|---|---|
-i, --interval <SECONDS> |
DBPULSE_INTERVAL |
30 |
Seconds between health checks |
-p, --port <PORT> |
DBPULSE_PORT |
9300 |
HTTP port for /metrics endpoint |
-l, --listen <IP> |
DBPULSE_LISTEN |
[::] |
IP address to bind to (supports IPv4 and IPv6) |
-r, --range <RANGE> |
DBPULSE_RANGE |
100 |
Upper limit for random ID generation (prevents conflicts in multi-instance setups) |
| N/A | DBPULSE_TLS_CERT_CACHE_TTL |
3600 |
TLS certificate cache TTL in seconds (0 to disable caching) |
The Data Source Name (DSN) follows this format:
<driver>://<user>:<password>@tcp(<host>:<port>)/<database>[?param1=value1¶m2=value2]
Supported drivers: postgres, mysql
# PostgreSQL
postgres://dbuser:secret@tcp(localhost:5432)/production
# MySQL/MariaDB
mysql://root:password@tcp(db.example.com:3306)/myapp
# With custom port
postgres://admin:pass@tcp(10.0.1.50:5433)/metrics_db
# Unix socket (PostgreSQL)
postgres://user:pass@unix(/var/run/postgresql)/mydb
Configure TLS directly in the DSN query string:
| Parameter | Values | Description |
|---|---|---|
sslmode |
disable, require, verify-ca, verify-full |
TLS mode (default: disable) |
sslrootcert or sslca |
/path/to/ca.crt |
CA certificate for server verification |
sslcert |
/path/to/client.crt |
Client certificate (mutual TLS) |
sslkey |
/path/to/client.key |
Client private key (mutual TLS) |
TLS Mode Details:
disable - No encryption (plaintext)require - Encrypted connection, no certificate verificationverify-ca - Verify server certificate against CAverify-full - Verify certificate and hostname match# PostgreSQL with TLS required
dbpulse --dsn "postgres://user:pass@tcp(db.example.com:5432)/prod?sslmode=require"
# PostgreSQL with full certificate verification
dbpulse --dsn "postgres://user:pass@tcp(db.example.com:5432)/prod?sslmode=verify-full&sslrootcert=/etc/ssl/certs/ca.crt"
# MySQL with CA verification
dbpulse --dsn "mysql://user:pass@tcp(db.example.com:3306)/prod?sslmode=verify-ca&sslca=/etc/ssl/ca.crt"
# Mutual TLS (client certificates)
dbpulse --dsn "postgres://user:pass@tcp(db.example.com:5432)/prod?sslmode=verify-full&sslrootcert=/etc/ssl/ca.crt&sslcert=/etc/ssl/client.crt&sslkey=/etc/ssl/client.key"
All options can be set via environment variables:
export DBPULSE_DSN="postgres://user:pass@tcp(localhost:5432)/mydb"
export DBPULSE_INTERVAL=60
export DBPULSE_PORT=9300
export DBPULSE_RANGE=1000
export DBPULSE_TLS_CERT_CACHE_TTL=3600 # Cache TLS certificate for 1 hour (default)
dbpulse # Uses environment variables
TLS Certificate Caching Examples:
# Production: Check certificate every 30 minutes
export DBPULSE_TLS_CERT_CACHE_TTL=1800
# Stable environments: Check once per day
export DBPULSE_TLS_CERT_CACHE_TTL=86400
# Testing: Disable cache (probe every health check)
export DBPULSE_TLS_CERT_CACHE_TTL=0
# Default: Check once per hour (if not set)
# No need to set, 3600 is automatic
Production PostgreSQL with TLS:
dbpulse \
--dsn "postgres://monitor:secret@tcp(prod-db.example.com:5432)/app?sslmode=verify-full&sslrootcert=/etc/ssl/certs/ca-bundle.crt" \
--interval 30 \
--port 9300 \
--range 1000
MySQL Cluster Monitoring:
dbpulse \
--dsn "mysql://healthcheck:pass@tcp(galera-lb.internal:3306)/monitoring" \
--interval 15 \
--listen "0.0.0.0" \
--port 8080
Development Setup:
dbpulse --dsn "postgres://postgres:postgres@tcp(localhost:5432)/test" -i 10 -r 50
dbpulse performs database health checks in a simple, repeating cycle:
All TLS/SSL settings come from the DSN query parameters (no separate flags):
# TLS configuration is in the DSN string
--dsn "postgres://user:pass@host:5432/db?sslmode=verify-full&sslrootcert=/etc/ssl/ca.crt"
The DSN parser extracts sslmode, sslrootcert, sslcert, and sslkey parameters into a TlsConfig struct used for both database and certificate connections.
Every interval (default: 30 seconds), dbpulse performs health checks:
Connection #1 - Database Operations (SQLx):
sslmodepg_stat_ssl or SHOW STATUS LIKE 'Ssl%')Connection #2 - Certificate Inspection (Probe) - CACHED:
DBPULSE_TLS_CERT_CACHE_TTL)host:port combinationBoth connections use the same TLS configuration from the DSN. The probe connection uses a NoVerifier to inspect certificates without validation (actual security happens in Connection #1).
Why two connections? SQLx doesn't expose peer certificates from its internal TLS stream, so certificate metadata must be extracted separately.
Default behavior (1 hour cache):
Customizing cache TTL:
# Check certificate every 30 minutes
export DBPULSE_TLS_CERT_CACHE_TTL=1800
# Check certificate once per day
export DBPULSE_TLS_CERT_CACHE_TTL=86400
# Disable caching (probe every iteration - not recommended)
export DBPULSE_TLS_CERT_CACHE_TTL=0
Performance impact:
Arc<RwLock<HashMap>> for concurrent accessResults are merged and exposed as Prometheus metrics on /metrics:
Every interval, dbpulse performs a quick vital signs check:
INSERT or UPDATE with unique ID and UUIDSELECT to verify written data matchesTimeout Protection:
These timeouts prevent the health probe from hanging on locked tables.
In addition to health checks, dbpulse collects:
pg_last_xact_replay_timestamp(), MySQL: SHOW REPLICA STATUS)All operational metrics use if let Ok(...) pattern - they never fail the health check.
dbpulse exposes comprehensive Prometheus-compatible metrics on the /metrics endpoint.
| Metric | Type | Description |
|---|---|---|
dbpulse_pulse |
Gauge | Binary health status (1=healthy, 0=unhealthy) |
dbpulse_runtime |
Histogram | Total health check duration (seconds) |
dbpulse_iterations_total |
Counter | Total checks by status (success/error) |
dbpulse_last_success_timestamp_seconds |
Gauge | Unix timestamp of last successful check |
dbpulse_database_readonly |
Gauge | Read-only mode indicator (1=read-only, 0=read-write) |
| Metric | Type | Description |
|---|---|---|
dbpulse_operation_duration_seconds |
Histogram | Duration by operation (connect, insert, select, etc.) |
dbpulse_connection_duration_seconds |
Histogram | How long connections are held open |
dbpulse_connections_active |
Gauge | Currently active database connections |
| Metric | Type | Description |
|---|---|---|
dbpulse_rows_affected_total |
Counter | Total rows affected by operation type (insert, delete) |
dbpulse_table_size_bytes |
Gauge | Monitoring table size in bytes |
dbpulse_table_rows |
Gauge | Approximate row count in monitoring table |
dbpulse_database_size_bytes |
Gauge | Total database size in bytes |
| Metric | Type | Description |
|---|---|---|
dbpulse_replication_lag_seconds |
Histogram | Replication lag for replica databases |
dbpulse_blocking_queries |
Gauge | Number of queries currently blocking others |
| Metric | Type | Description |
|---|---|---|
dbpulse_errors_total |
Counter | Total errors by type (authentication, timeout, connection, transaction, query) |
dbpulse_panics_recovered_total |
Counter | Total panics recovered from |
| Metric | Type | Description |
|---|---|---|
dbpulse_tls_handshake_duration_seconds |
Histogram | TLS handshake duration |
dbpulse_tls_connection_errors_total |
Counter | TLS-specific connection errors |
dbpulse_tls_info |
Gauge | TLS version and cipher suite (labels: version, cipher) |
dbpulse_tls_cert_expiry_days |
Gauge | Days until TLS certificate expiration (negative if expired) |
For complete documentation, PromQL examples, and alert rules, see grafana/README.md.
# Database health
dbpulse_pulse
# Success rate
rate(dbpulse_iterations_total{status="success"}[5m]) /
rate(dbpulse_iterations_total[5m]) * 100
# P99 latency
histogram_quantile(0.99, rate(dbpulse_runtime_bucket[5m]))
# Error rate by type
rate(dbpulse_errors_total[5m])
# Connection time
rate(dbpulse_operation_duration_seconds_sum{operation="connect"}[5m]) /
rate(dbpulse_operation_duration_seconds_count{operation="connect"}[5m])
# TLS certificate expiry (days remaining)
dbpulse_tls_cert_expiry_days
# Certificates expiring within 30 days
dbpulse_tls_cert_expiry_days < 30 and dbpulse_tls_cert_expiry_days > 0
- alert: DatabaseDown
expr: dbpulse_pulse == 0
for: 2m
labels:
severity: critical
- alert: HighErrorRate
expr: rate(dbpulse_errors_total[5m]) > 0.1
for: 5m
labels:
severity: warning
- alert: NoRecentSuccess
expr: time() - dbpulse_last_success_timestamp_seconds > 300
for: 1m
labels:
severity: critical
- alert: TLSCertificateExpiringSoon
expr: dbpulse_tls_cert_expiry_days < 30 and dbpulse_tls_cert_expiry_days > 0
for: 1h
labels:
severity: warning
annotations:
summary: "TLS certificate expires in {{ $value }} days"
description: "Database {{ $labels.database }} TLS certificate will expire soon"
- alert: TLSCertificateExpired
expr: dbpulse_tls_cert_expiry_days < 0
for: 5m
labels:
severity: critical
annotations:
summary: "TLS certificate has expired"
description: "Database {{ $labels.database }} TLS certificate expired {{ $value | abs }} days ago"
The monitoring user needs specific permissions for database operations.
PostgreSQL:
-- Create monitoring database
CREATE DATABASE dbpulse;
-- Create monitoring user
CREATE USER dbpulse WITH PASSWORD 'secret';
-- Grant database access
GRANT CONNECT ON DATABASE dbpulse TO dbpulse;
GRANT CREATE ON DATABASE dbpulse TO dbpulse;
-- Grant schema access
\c dbpulse
GRANT USAGE ON SCHEMA public TO dbpulse;
GRANT CREATE ON SCHEMA public TO dbpulse;
-- Allow table creation and operations
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO dbpulse;
MySQL/MariaDB:
-- Create monitoring database
CREATE DATABASE dbpulse;
-- Create monitoring user
CREATE USER 'dbpulse'@'%' IDENTIFIED BY 'secret';
-- Grant specific permissions (recommended)
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON dbpulse.* TO 'dbpulse'@'%';
GRANT REPLICATION CLIENT ON *.* TO 'dbpulse'@'%'; -- For replication lag monitoring
GRANT PROCESS ON *.* TO 'dbpulse'@'%'; -- For blocking query detection
FLUSH PRIVILEGES;
Alternative: GRANT ALL PRIVILEGES
While GRANT ALL PRIVILEGES is simpler, it has security implications:
-- MySQL/MariaDB - NOT RECOMMENDED for production
GRANT ALL PRIVILEGES ON dbpulse.* TO 'dbpulse'@'%';
FLUSH PRIVILEGES;
Constraints and security concerns:
ALTER, INDEX, REFERENCES, LOCK TABLES, and moreMinimal Permissions (if table exists):
If the dbpulse_rw table is already created, only these are needed:
-- PostgreSQL
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE dbpulse_rw TO dbpulse;
-- MySQL
GRANT SELECT, INSERT, UPDATE, DELETE ON dbpulse.dbpulse_rw TO 'dbpulse'@'%';
Connection string with default database:
# PostgreSQL
dbpulse --dsn "postgres://dbpulse:secret@tcp(localhost:5432)/dbpulse"
# MySQL/MariaDB
dbpulse --dsn "mysql://dbpulse:secret@tcp(localhost:3306)/dbpulse"
dbpulse creates and manages a table named dbpulse_rw (or custom name if using multiple instances) with this schema:
PostgreSQL:
CREATE TABLE IF NOT EXISTS dbpulse_rw (
id INT NOT NULL,
t1 BIGINT NOT NULL,
t2 TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
uuid UUID,
PRIMARY KEY(id)
);
CREATE UNIQUE INDEX IF NOT EXISTS idx_uuid ON dbpulse_rw(uuid);
CREATE INDEX IF NOT EXISTS idx_t2 ON dbpulse_rw(t2);
MySQL/MariaDB:
CREATE TABLE IF NOT EXISTS dbpulse_rw (
id INT NOT NULL,
t1 BIGINT NOT NULL,
t2 TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
uuid CHAR(36) CHARACTER SET ascii,
PRIMARY KEY(id),
UNIQUE KEY(uuid),
INDEX idx_t2 (t2)
) ENGINE=InnoDB;
The table is automatically maintained:
Use different table names for multiple monitoring instances:
# Instance 1
dbpulse --dsn "postgres://user:pass@tcp(db:5432)/prod" --range 1000
# Instance 2 (different range = different table name)
dbpulse --dsn "postgres://user:pass@tcp(db:5432)/prod" --range 2000
Container images are automatically published to GitHub Container Registry on each release.
Pull the image:
podman pull ghcr.io/nbari/dbpulse:latest
Run with Docker/Podman:
# PostgreSQL
podman run -d \
--name dbpulse \
-p 9300:9300 \
-e DBPULSE_DSN="postgres://user:password@host.docker.internal:5432/mydb" \
ghcr.io/nbari/dbpulse:latest
# MySQL/MariaDB with TLS
docker run -d \
--name dbpulse \
-p 9300:9300 \
-v /etc/ssl/certs:/etc/ssl/certs:ro \
-e DBPULSE_DSN="mysql://user:pass@tcp(db.example.com:3306)/prod?sslmode=verify-ca&sslca=/etc/ssl/certs/ca.crt" \
-e DBPULSE_INTERVAL=60 \
ghcr.io/nbari/dbpulse:latest
Multi-architecture support:
linux/amd64 - x86_64 architecturelinux/arm64 - ARM64 architecture (AWS Graviton, Apple Silicon, Raspberry Pi)[Unit]
Description=Database Pulse Monitor
After=network.target
[Service]
Type=simple
User=dbpulse
Group=dbpulse
Environment="DBPULSE_DSN=postgres://monitor:secret@tcp(localhost:5432)/prod?sslmode=verify-full&sslrootcert=/etc/ssl/certs/ca.crt"
Environment="DBPULSE_INTERVAL=30"
Environment="DBPULSE_PORT=9300"
ExecStart=/usr/local/bin/dbpulse
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
Save to /etc/systemd/system/dbpulse.service, then:
sudo systemctl daemon-reload
sudo systemctl enable dbpulse
sudo systemctl start dbpulse
sudo systemctl status dbpulse
Run all tests (unit, integration, TLS):
just test
Run individual test suites:
just unit-test # Unit tests only
just test-integration # Integration tests (non-TLS)
just test-tls # TLS integration tests
For detailed documentation, see: