Skip to content

Conversation

@Prashant-thakur77
Copy link
Contributor

What does this PR do?

) This PR adds a minimal, opinionated observability layer to the project so we can collect query performance metrics, monitor connection pools, track user activity, expose system health, and provide Prometheus alerting and a starter Grafana dashboard.

What I changed (summary)

Added a Prometheus-backed metrics collector with histograms/counters/gauges and a simple MetricsCollector class.
app/lib/monitoring/metrics.ts
Exposed metrics and health endpoints:
app/api/metrics.ts
app/api/health.ts
DB instrumentation wrapper to measure query duration and status:
app/lib/db/instrumentedQuery.ts
Connection pool monitor to periodically push pool

Related Issue

Closes #80

How to install & test locally

Install runtime dependency and dev types: npm install prom-client npm install --save-dev @types/express @types/node

Note: @types/prom-client does not exist — do NOT try to install it. Instead either upgrade prom-client (recent versions bundle types) or add a minimal declaration file:

Create types/prom-client.d.ts containing: declare module "prom-client";
Run the TypeScript check: npx tsc --noEmit

Wire into your Express app:

Mount metrics and health routers (e.g., app.use(metricsRouter); app.use(healthRouter);)
Wrap DB calls with instrumentedQuery or patch pool.query
Start pool monitor with a getPoolStats function for your DB pools
Verify:

curl http://localhost/:/metrics → should show mcp_ prefixed metrics
curl http://localhost/:/health → should return basic health JSON
Simulate queries and check histogram/counter updates
Notes and important considerations

Protect /metrics in production (network-only access or strip sensitive labels). High-cardinality labels (raw SQL strings, full user IDs) will explode Prometheus series — prefer canonicalized query names and anonymized user IDs.
If prom-client types are missing, add types/prom-client.d.ts as described or update prom-client to a version that ships types.
I included a sample Prometheus rules file for alerting and a small Grafana dashboard JSON as a starting point — adjust thresholds/labels for your environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] No Performance Monitoring and Metrics

1 participant