DEV Community

Vigilmon
Vigilmon

Posted on

How to Monitor CockroachDB with Vigilmon (Distributed SQL Health Checks)

CockroachDB is a distributed SQL database designed for global scale and resilience. But even a globally distributed database needs external monitoring — you need to know if your application can actually connect and query it, not just if the nodes are up internally.

Why External CockroachDB Monitoring Matters

CockroachDB has excellent built-in monitoring via its Admin UI and metrics. But internal monitoring has a blind spot: it can't tell you if your application is actually connecting successfully.

External monitoring with Vigilmon catches:

  • Connection pool exhaustion (the DB is up but apps can't connect)
  • Authentication failures (certs expired, password rotated)
  • Network partitions between your app and the DB cluster
  • Application-layer query failures that don't appear as node failures

Setting Up Application-Level Health Checks

With Node.js (using pg driver)

import { Pool } from 'pg'

const pool = new Pool({
  connectionString: process.env.DATABASE_URL,
  ssl: { rejectUnauthorized: true },
})

export async function checkCockroachDB(): Promise<boolean> {
  try {
    const client = await pool.connect()
    await client.query('SELECT 1')
    client.release()
    return true
  } catch (err) {
    console.error('CockroachDB health check failed:', err)
    return false
  }
}
Enter fullscreen mode Exit fullscreen mode

Express.js health route

app.get('/health', async (req, res) => {
  const dbOk = await checkCockroachDB()

  res.status(dbOk ? 200 : 503).json({
    status: dbOk ? 'ok' : 'degraded',
    checks: { database: dbOk ? 'ok' : 'error' },
    timestamp: new Date().toISOString(),
  })
})
Enter fullscreen mode Exit fullscreen mode

With Prisma (CockroachDB provider)

import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()

app.get('/health', async (req, res) => {
  try {
    await prisma.$queryRaw`SELECT 1`
    res.json({ status: 'ok', database: 'ok' })
  } catch (err) {
    res.status(503).json({ status: 'degraded', database: 'error' })
  }
})
Enter fullscreen mode Exit fullscreen mode

Setting Up Vigilmon

  1. Go to vigilmon.onlineAdd Monitor
  2. Enter: https://your-app.com/health
  3. Expected status: 200
  4. Keyword check: "database":"ok"
  5. Interval: 60 seconds
  6. Multi-region: enabled (critical for distributed apps)

If your CockroachDB connection fails, the health check returns 503 and Vigilmon alerts you immediately.

Monitoring CockroachDB Multi-Region Deployments

CockroachDB's selling point is global distribution. For each application region, set up a separate Vigilmon monitor targeting that region's health endpoint. This tells you if a specific regional instance is having connection issues.

Heartbeat Monitoring for CockroachDB Jobs

CockroachDB has a jobs system for changefeeds, backups, and scheduled operations. Monitor these with Vigilmon heartbeats:

// After a successful backup or changefeed checkpoint
await fetch('https://vigilmon.online/api/heartbeat/YOUR_HEARTBEAT_ID')
Enter fullscreen mode Exit fullscreen mode

Configure the heartbeat to alert if it doesn't receive a ping within your expected window (e.g., 25 hours for a daily backup).

CockroachDB Cloud Monitoring

If you're on CockroachDB Serverless or Dedicated:

  • CockroachDB Cloud: Internal node metrics, query performance
  • Vigilmon: External connectivity, application-level health, alerting

These complement each other — CockroachDB Cloud monitoring can't tell you if your app is failing to connect.

What to Alert On

Scenario Vigilmon Alert
App can't connect to CRDB Health endpoint returns 503
CRDB query timeout Health endpoint times out
App deployment failed Health endpoint returns 500
Connection pool exhausted Health endpoint degraded response
Daily backup missed Heartbeat goes cold

Start free CockroachDB monitoring with Vigilmon →

Top comments (0)