Skip to main content

SDK for monitoring microservice dependencies via Prometheus metrics

Project description

dephealth

SDK for monitoring microservice dependencies via Prometheus metrics.

Features

  • Automatic health checking for dependencies (PostgreSQL, MySQL, Redis, RabbitMQ, Kafka, HTTP, gRPC, TCP)
  • Prometheus metrics export: app_dependency_health (Gauge 0/1), app_dependency_latency_seconds (Histogram), app_dependency_status (enum), app_dependency_status_detail (info)
  • Async architecture built on asyncio
  • FastAPI integration (middleware, lifespan, endpoints)
  • Connection pool support (preferred) and standalone checks

Installation

# Basic installation
pip install dephealth

# With specific checkers
pip install dephealth[postgres,redis]

# All checkers + FastAPI
pip install dephealth[all]

Quick Start

Standalone

from dephealth import DepHealth

dh = DepHealth()
dh.add("postgres", url="postgresql://user:pass@localhost:5432/mydb")
dh.add("redis", url="redis://localhost:6379")

await dh.start()
# Metrics are available via prometheus_client
await dh.stop()

FastAPI

from fastapi import FastAPI
from dephealth_fastapi import DepHealthFastAPI

app = FastAPI()
dh = DepHealthFastAPI(app)
dh.add("postgres", url="postgresql://user:pass@localhost:5432/mydb")

Dynamic Endpoints

Add, remove, or replace monitored endpoints at runtime on a running instance (v0.6.0+):

from dephealth import DependencyType, Endpoint
from dephealth.checks.http import HTTPChecker

# After dh.start()...

# Add a new endpoint
await dh.add_endpoint(
    "api-backend",
    DependencyType.HTTP,
    True,
    Endpoint(host="backend-2.svc", port="8080"),
    HTTPChecker(),
)

# Remove an endpoint (cancels check task, deletes metrics)
await dh.remove_endpoint("api-backend", "backend-2.svc", "8080")

# Replace an endpoint atomically
await dh.update_endpoint(
    "api-backend",
    "backend-1.svc", "8080",
    Endpoint(host="backend-3.svc", port="8080"),
    HTTPChecker(),
)

Synchronous variants are available: add_endpoint_sync(), remove_endpoint_sync(), update_endpoint_sync().

See migration guide for details.

Health Details

details = dh.health_details()
for key, ep in details.items():
    print(f"{key}: healthy={ep.healthy} status={ep.status} "
          f"latency={ep.latency_millis():.1f}ms")

Configuration

Parameter Default Description
interval 15 Check interval (seconds)
timeout 5 Check timeout (seconds)

Supported Dependencies

Type Extra URL Format
PostgreSQL postgres postgresql://user:pass@host:5432/db
MySQL mysql mysql://user:pass@host:3306/db
Redis redis redis://host:6379
RabbitMQ amqp amqp://user:pass@host:5672/vhost
Kafka kafka kafka://host1:9092,host2:9092
HTTP http://host:8080/health
gRPC grpc host:50051 (via FromParams)
TCP tcp://host:port

Authentication

HTTP and gRPC checkers support Bearer token, Basic Auth, and custom headers/metadata:

http_check("secure-api",
    url="http://api.svc:8080",
    critical=True,
    bearer_token="eyJhbG...",
)

grpc_check("grpc-backend",
    host="backend.svc",
    port=9090,
    critical=True,
    bearer_token="eyJhbG...",
)

See quickstart guide for all options.

License

Apache License 2.0 — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dephealth-0.6.0.tar.gz (174.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dephealth-0.6.0-py3-none-any.whl (31.2 kB view details)

Uploaded Python 3

File details

Details for the file dephealth-0.6.0.tar.gz.

File metadata

  • Download URL: dephealth-0.6.0.tar.gz
  • Upload date:
  • Size: 174.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for dephealth-0.6.0.tar.gz
Algorithm Hash digest
SHA256 bfe2c55d56110f7a9375658f81ecfc8ce82c2c92c6858babcaebd30a061281c5
MD5 b7c92b3552485dc39bf0f1967f245248
BLAKE2b-256 5e5284d11892b8fab7c85812508d3ef79f813e92177bf2f9965464a8ee8a7e7e

See more details on using hashes here.

File details

Details for the file dephealth-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: dephealth-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 31.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for dephealth-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4da179f7e182a7240e1f655a507ceca675e4febd3bcd699d31915866c78179ab
MD5 19c953be79af219920fce18c507ff83f
BLAKE2b-256 5bf6ec64625b5612f04eb34979880bf9811da55e075b7c1dea5ed3b698163868

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page