DEV Community

Vigilmon
Vigilmon

Posted on

How to Monitor Your PlanetScale Database with Vigilmon

How to Monitor Your PlanetScale Database with Vigilmon

PlanetScale is a serverless MySQL-compatible database platform with branching and schema change workflows. While PlanetScale manages database infrastructure, your application layer still needs monitoring. Vigilmon helps you detect when your app can't reach PlanetScale and alerts you before users notice.

Why Monitor PlanetScale-Based Apps?

  • Connection pool exhaustion under traffic spikes
  • Branch deployment issues after schema changes
  • Authentication token expiry breaking app connections
  • Application server failures while PlanetScale is fine
  • Slow query degradation causing timeout errors

Step 1: Add a Health Check That Tests PlanetScale

Next.js (App Router)

// app/api/health/route.js
import { db } from '@/lib/db'; // Your PlanetScale client

export async function GET() {
  try {
    // Lightweight query to test PlanetScale connection
    const result = await db.execute('SELECT 1 as ok');

    return Response.json({
      status: 'ok',
      timestamp: new Date().toISOString(),
      database: 'planetscale',
      rows: result.rows.length,
    });
  } catch (error) {
    return Response.json({
      status: 'error',
      database: 'error',
      message: 'Database connection failed',
    }, { status: 503 });
  }
}
Enter fullscreen mode Exit fullscreen mode

With Prisma + PlanetScale

import { prisma } from '@/lib/prisma';

export async function GET() {
  try {
    // Prisma $queryRaw for a lightweight check
    await prisma.$queryRaw`SELECT 1`;
    return Response.json({ status: 'ok', database: 'planetscale' });
  } catch (error) {
    return Response.json({ status: 'error' }, { status: 503 });
  }
}
Enter fullscreen mode Exit fullscreen mode

With Drizzle ORM

import { sql } from 'drizzle-orm';
import { db } from '@/lib/db';

export async function GET() {
  try {
    await db.execute(sql`SELECT 1`);
    return Response.json({ status: 'ok', database: 'planetscale' });
  } catch (error) {
    return Response.json({ status: 'error' }, { status: 503 });
  }
}
Enter fullscreen mode Exit fullscreen mode

Step 2: PlanetScale Connection Setup

For reference, a typical PlanetScale connection setup:

// lib/db.js
import { connect } from '@planetscale/database';

export const db = connect({
  host: process.env.DATABASE_HOST,
  username: process.env.DATABASE_USERNAME,
  password: process.env.DATABASE_PASSWORD,
});
Enter fullscreen mode Exit fullscreen mode

Step 3: Configure Vigilmon

  1. Go to vigilmon.online
  2. New Monitor
  3. Configure:
    • URL: https://your-app.com/api/health
    • Expected status: 200
    • Interval: 1 minute
  4. Add notification channels
  5. Save

Step 4: Monitor After Schema Deployments

PlanetScale's schema branching is powerful but deployments can cause brief query issues. Set your Vigilmon alert threshold to 2 consecutive failures to avoid false alarms during deployments:

  • Threshold: 2 consecutive failures before alerting
  • Recovery: Alert when service recovers

Step 5: SSL Certificate Monitoring

Add SSL monitoring for your app domain:

  • Type: SSL Certificate
  • URL: https://your-app.com
  • Alert: 14 days before expiry

PlanetScale vs Traditional MySQL Monitoring

With traditional MySQL, you'd monitor the database server directly. PlanetScale is serverless, so you monitor at the application layer:

Traditional PlanetScale
Monitor DB server Monitor app + DB connection
Check MySQL port Check HTTP health endpoint
Monitor disk usage No disk to monitor
Connection count Connection pool in app

Conclusion

PlanetScale handles the hard parts of MySQL operations, but your app still needs monitoring. Vigilmon watches your application's health endpoint, detects database connectivity issues, and alerts you instantly. Start free today.

Top comments (0)