---
id: w3/m10/t003
title: "DB active-connections series: CNPG/Postgres exporter metric on the metrics API"
worker: worker3
status: todo
estimate: 45m
depends_on: []
---

## Objective

Add a live active-connections series for managed Postgres instances to the metrics API.

## Context

- CNPG exposes Postgres metrics (including connection counts) via its built-in `postgres_exporter`-compatible metrics endpoint, scraped by Prometheus per `w1/m4`'s resource-metrics-history pipeline.
- `lego/backend/internal/postgres/` — existing Postgres verbs; `lego/backend/internal/metrics/` — resource-metrics API.

## Steps

1. Query the CNPG cluster's `pg_stat_activity`-derived connection-count metric from Prometheus (or live via `pg_stat_activity` count, consistent with whichever pattern `w1/m25`'s `processes` endpoint uses, if that's landed by then — otherwise query Prometheus directly).
2. Add a `connections` series to the resource-metrics API for Postgres resources (REST/GraphQL/MCP).

## Files

- `lego/backend/internal/metrics/`

## Acceptance criteria

- [ ] A real managed-Postgres instance returns a live active-connections count/series.

## Out of scope

- Per-database connection breakdown — Render's row is instance-level.
