DEV Community

Vigilmon
Vigilmon

Posted on

How to Monitor Apps Using Prisma ORM with Vigilmon

How to Monitor Apps Using Prisma ORM with Vigilmon

Prisma is the most popular ORM in the Node.js and TypeScript ecosystem. It simplifies database access and provides type-safe queries. But a Prisma-powered app can fail in ways that don't show up in logs until a user hits a broken endpoint — connection pool exhaustion, migration failures, or database unreachability.

What Can Go Wrong with Prisma?

  • Database connection failures: The database server is unreachable
  • Connection pool exhaustion: Too many concurrent queries
  • Migration drift: Database schema out of sync with Prisma schema
  • Query timeouts: Slow queries causing health check timeouts

External monitoring surfaces these issues before users encounter 500 errors.

Add a Prisma Health Route

Express.js:

import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

prisma.$connect().catch((e) => {
  console.error("Failed to connect to database:", e);
  process.exit(1);
});

app.get("/health", async (req, res) => {
  try {
    await prisma.$queryRaw`SELECT 1`;
    res.json({ status: "ok", database: "connected", orm: "prisma" });
  } catch (error) {
    res.status(503).json({
      status: "error",
      database: "disconnected",
      message: error instanceof Error ? error.message : "Unknown error",
    });
  }
});
Enter fullscreen mode Exit fullscreen mode

NestJS:

@Controller("health")
export class HealthController {
  constructor(private readonly prisma: PrismaService) {}

  @Get()
  async check() {
    try {
      await this.prisma.$queryRaw`SELECT 1`;
      return { status: "ok", database: "connected" };
    } catch (error) {
      throw new HttpException(
        { status: "error", database: "disconnected" },
        HttpStatus.SERVICE_UNAVAILABLE
      );
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Next.js (App Router):

// app/api/health/route.ts
import { prisma } from "@/lib/prisma";
import { NextResponse } from "next/server";

export const runtime = "nodejs";

export async function GET() {
  try {
    await prisma.$queryRaw`SELECT 1`;
    return NextResponse.json({ status: "ok", database: "connected" });
  } catch (error) {
    return NextResponse.json({ status: "error" }, { status: 503 });
  }
}
Enter fullscreen mode Exit fullscreen mode

Add to Vigilmon

  1. Log in at vigilmon.online
  2. Click + Add Monitor
  3. URL: https://your-app.com/api/health
  4. Check interval: 1 minute
  5. Expected status: 200

Monitor Migrations in CI/CD

# GitHub Actions
- name: Run database migrations
  run: npx prisma migrate deploy
  env:
    DATABASE_URL: ${{ secrets.DATABASE_URL }}

- name: Verify database connection
  run: node -e "const {PrismaClient}=require('@prisma/client');const p=new PrismaClient();p.$queryRaw`SELECT 1`.then(()=>{console.log('OK');p.$disconnect();}).catch(e=>{console.error(e);process.exit(1);})"
  env:
    DATABASE_URL: ${{ secrets.DATABASE_URL }}
Enter fullscreen mode Exit fullscreen mode

Common Issues Caught by External Monitoring

Issue Symptom Vigilmon Alert
DB unreachable /health returns 503 Immediate alert
Connection pool full /health times out Timeout alert
OOM in app No response Timeout alert
Cold start delays Slow first response Latency alert

Checklist

  • [x] /health endpoint with SELECT 1 check
  • [x] Returns 503 on Prisma connection error
  • [x] Vigilmon monitor on /health endpoint
  • [x] Alert channels configured (Slack + email)
  • [x] prisma migrate deploy in deployment pipeline

Prisma handles the query layer beautifully — pair it with Vigilmon for operational visibility that ensures users always reach a working app.


Vigilmon — free uptime monitoring for Prisma-powered apps and any HTTP endpoint.

Top comments (0)