Add minimum total connection threshold for active ratio alerts
All checks were successful
PostgreSQL Compatibility Matrix / PG14 smoke (push) Successful in 8s
PostgreSQL Compatibility Matrix / PG15 smoke (push) Successful in 7s
PostgreSQL Compatibility Matrix / PG16 smoke (push) Successful in 7s
PostgreSQL Compatibility Matrix / PG17 smoke (push) Successful in 7s
PostgreSQL Compatibility Matrix / PG18 smoke (push) Successful in 7s

Introduced `ALERT_ACTIVE_CONNECTION_RATIO_MIN_TOTAL_CONNECTIONS` to reduce false positives by requiring a minimum number of total connections before evaluating the active connection ratio. Updated the logic and description in relevant files for clarity and configurability.
This commit is contained in:
2026-02-12 15:44:30 +01:00
parent 918bb132ef
commit ec05163a04
3 changed files with 13 additions and 2 deletions

View File

@@ -42,6 +42,9 @@ ENCRYPTION_KEY=REPLACE_WITH_FERNET_KEY
CORS_ORIGINS=http://localhost:5173,http://localhost:8080 CORS_ORIGINS=http://localhost:5173,http://localhost:8080
# Target polling interval in seconds. # Target polling interval in seconds.
POLL_INTERVAL_SECONDS=30 POLL_INTERVAL_SECONDS=30
# Active Connection Ratio alert is only evaluated when total sessions
# are at least this number (reduces false positives on low-traffic DBs).
ALERT_ACTIVE_CONNECTION_RATIO_MIN_TOTAL_CONNECTIONS=5
# Initial admin bootstrap user (created on first startup if not present). # Initial admin bootstrap user (created on first startup if not present).
INIT_ADMIN_EMAIL=admin@example.com INIT_ADMIN_EMAIL=admin@example.com
INIT_ADMIN_PASSWORD=ChangeMe123! INIT_ADMIN_PASSWORD=ChangeMe123!

View File

@@ -25,6 +25,7 @@ class Settings(BaseSettings):
encryption_key: str encryption_key: str
cors_origins: str = "http://localhost:5173" cors_origins: str = "http://localhost:5173"
poll_interval_seconds: int = 30 poll_interval_seconds: int = 30
alert_active_connection_ratio_min_total_connections: int = 5
init_admin_email: str = "admin@example.com" init_admin_email: str = "admin@example.com"
init_admin_password: str = "ChangeMe123!" init_admin_password: str = "ChangeMe123!"

View File

@@ -268,7 +268,11 @@ async def _build_standard_rules(db: AsyncSession, target: Target) -> tuple[list[
slowest_query_total = await _latest_query_snapshot_max(db, target.id, "total_time") slowest_query_total = await _latest_query_snapshot_max(db, target.id, "total_time")
active_ratio = None active_ratio = None
if active_connections is not None and total_connections and total_connections > 0: if (
active_connections is not None
and total_connections is not None
and total_connections >= settings.alert_active_connection_ratio_min_total_connections
):
active_ratio = active_connections / total_connections active_ratio = active_connections / total_connections
rollback_ratio_15m, tx_total_15m = await _rollback_ratio_recent( rollback_ratio_15m, tx_total_15m = await _rollback_ratio_recent(
@@ -280,7 +284,10 @@ async def _build_standard_rules(db: AsyncSession, target: Target) -> tuple[list[
_RuleInput( _RuleInput(
key="active_connections_ratio", key="active_connections_ratio",
name="Active Connection Ratio", name="Active Connection Ratio",
description="Share of active sessions over total sessions.", description=(
"Share of active sessions over total sessions. "
f"Only evaluated when total sessions >= {settings.alert_active_connection_ratio_min_total_connections}."
),
category="capacity", category="capacity",
value=active_ratio, value=active_ratio,
warning_threshold=0.70, warning_threshold=0.70,