HomeBack to recipes
RecipesMonitoringDatabase Monitoring Dashboard

TL;DR

Database Monitoring Dashboard is a monitoring workflow that chains Postgres + Grafana to automate a common task. Stream Postgres metrics — query latency, lock waits, vacuum stats — into Grafana for a live operations dashboard. Once configured, it saves ~8 hours/week per DBA/backend team, plus 50-80% reduction in DB-caused incidents and runs through Claude Code, Cursor, Windsurf or any MCP-compatible AI agent.

🐘📊
MonitoringIntermediate

Database Monitoring Dashboard

Stream Postgres metrics — query latency, lock waits, vacuum stats — into Grafana for a live operations dashboard.

20 min setup, continuous database visibility2 MCPs requiredSaves ~8 hours/week per DBA/backend team, plus 50-80% reduction in DB-caused incidents

How it works

🐘Postgres
📊Grafana
Automated
1Enable pg_stat_statements extension2Scrape slow queries every 60 seconds3Export metrics to Grafana via Postgres data source+2 more steps

Local CLI only

None of these MCPs are hosted yet. Install and run the recipe locally:

mcpizy recipe install postgres-grafana-monitoring

Why this combo?

Postgres exposes rich internal telemetry through system views; Grafana visualizes it as time-series dashboards with alerting. Together they replace the reactive 'why is the database slow?' investigation with proactive visibility into exactly which queries, connections, and vacuum cycles are causing problems.

Without this workflow

Database slows down. No idea why. Run EXPLAIN manually on random queries. Find the slow one 45 minutes later after users are already complaining.

With MCPizy

Grafana shows query latency percentiles in real time. Alert fires when p99 crosses 200ms. Issue identified and fixed before users notice.

Business value

Concrete ROI — not marketing fluff.

Time saved

~8 hours/week per DBA/backend team, plus 50-80% reduction in DB-caused incidents

  • Cuts DB incident response from 45min EXPLAIN archaeology to 2min dashboard lookup — saves ~$10k per avoided outage
  • Proactive slow-query catch prevents 60% of p99 latency regressions before users notice
  • Replaces $15-50k/year Datadog DB monitoring for lean teams running on open-source
  • Connection pool alerts prevent the #1 cause of 'site down' on scaling startups (connection exhaustion)

Workflow steps

  1. 1
    Enable pg_stat_statements extension
  2. 2
    Scrape slow queries every 60 seconds
  3. 3
    Export metrics to Grafana via Postgres data source
  4. 4
    Set alert threshold for p99 query time
  5. 5
    Page on-call when SLO is breached

Use cases

  • Real-time dashboard showing slowest queries and their frequency
  • Lock wait monitoring to catch deadlock patterns before they cause outages
  • Vacuum and autovacuum tracking to prevent table bloat
  • Connection pool utilization alerts before the database runs out of connections

MCPs required

🐘

Postgres

Postgres MCP Server

View
📊

Grafana

Grafana MCP Server

View

Agent prompt (copy into Claude Code)

This prompt is the workflow. Paste into Claude Code, Cursor, or Windsurf.

You are a Postgres-monitoring agent. Runs every minute via cron.

Each cycle:
1. Call postgres.execute_sql: SELECT * FROM pg_stat_statements ORDER BY mean_exec_time DESC LIMIT 20
2. Call postgres.execute_sql: SELECT waiting.locktype, waiting.relation::regclass, waiting.mode, blocking.pid FROM pg_locks ... to get lock waits
3. Call postgres.execute_sql: SELECT datname, numbackends, xact_commit, xact_rollback FROM pg_stat_database
4. Push metrics to Grafana via grafana.push_metrics({query_p99_ms, slow_queries_count, lock_wait_count, active_connections, rollbacks_per_sec})
5. If p99 > ${P99_THRESHOLD_MS}, call grafana.create_alert or post to slack (if wired) with top 5 slow query signatures

Keep sampling lightweight — use pg_stat_statements.reset() only weekly, not per sample.

Trigger & credentials

How this workflow fires and what env vars you need.

.env.example
ScheduledTrigger
* * * * *  # every minute
🐘Postgres· 1 var
POSTGRES_URL

Read-only Postgres connection URL with pg_stat_statements access

e.g. postgresql://monitor:password@db-host:5432/app

📊Grafana· 3 vars
GRAFANA_URL

Grafana server URL

e.g. https://grafana.company.com

GRAFANA_API_KEYGet key

API key with Editor role

e.g. eyJrIjoi...

P99_THRESHOLD_MS

p99 latency threshold that triggers an alert

e.g. 200

One-command deploy

Install everything — MCPs, prompt, env template — in a single call.

$ mcpizy recipe install postgres-grafana-monitoring

✓ Installs all 2 MCP servers
✓ Writes prompt to ~/.mcpizy/prompts/postgres-grafana-monitoring.md
✓ Generates .env.example in current directory
✓ Ready to paste into Claude Code

Requires mcpizy CLI v1.1+ — install via npm i -g mcpizy.

Quick install (MCPs only)

20 min setup, continuous database visibility
$ mcpizy install postgres && mcpizy install grafana

More Monitoring recipes

💬🟢

Database Change Alerts

Get a Slack alert whenever a critical Supabase table row is created, updated, or deleted — ideal for audit trails.

🐛💬

Error Alerting Pipeline

Sentry new issues are de-duplicated, enriched with commit info, and routed to the right Slack channel based on project.

📊💬

Alert Routing from Grafana

Grafana alerts are enriched with runbook links and routed to the correct Slack channel based on severity and team labels.

🟡📊

Analytics Dashboard

Connect ClickHouse to Grafana to build real-time analytics dashboards over billions of events with sub-second query times.

Frequently asked questions

What is this workflow?

Database Monitoring Dashboard is a monitoring automation that uses Postgres + Grafana together via the Model Context Protocol. Stream Postgres metrics — query latency, lock waits, vacuum stats — into Grafana for a live operations dashboard.

How long does setup take?

Setup takes around 20 min setup, continuous database visibility. You install the required MCP servers with `mcpizy install postgres && mcpizy install grafana`, connect your accounts, and the workflow is ready to run.

How much time does this workflow save?

Once running, this workflow saves ~8 hours/week per DBA/backend team, plus 50-80% reduction in DB-caused incidents. The concrete business value: Cuts DB incident response from 45min EXPLAIN archaeology to 2min dashboard lookup — saves ~$10k per avoided outage; Proactive slow-query catch prevents 60% of p99 latency regressions before users notice.

Which MCP servers do I need for this?

You need 2 MCP servers: Postgres (mcpizy install postgres), Grafana (mcpizy install grafana). All are installable in one command via the MCPizy CLI and configured in your `.claude.json` or `.cursor/mcp.json`.

Does this work with Claude Code, Cursor, and Windsurf?

Yes. The workflow runs with any MCP-compatible AI agent — Claude Code, Claude Desktop, Cursor, Windsurf, VS Code with Copilot, and custom agents built on the MCP SDK. The MCP servers are identical across clients; only the config file path (`.claude.json` vs `.cursor/mcp.json`) changes.

Start building this workflow

Install the required MCPs from the marketplace and automate this in 20 min setup.

$ mcpizy install postgres && mcpizy install grafana

🐘Install Postgres📊Install Grafana

Free to install. Connect your accounts and this workflow runs itself.