Guides / Monitoring

How to Get Notified When Your App Goes Down

3 min readยทMonitoring

Build a health check endpoint

ts
// app/api/health/route.ts
import { db } from "@/lib/db";

export async function GET() {
  try {
    await db.query("SELECT 1");
    return Response.json({ status: "ok", timestamp: Date.now() });
  } catch {
    return Response.json({ status: "error" }, { status: 503 });
  }
}

Add a cron job that checks it

Use a cron service (Vercel Cron, Trigger.dev, or a simple external pinger) to hit your health endpoint every minute and log failures:

ts
// cron/health-check.ts (runs every minute)
import { logit } from "@/lib/logit";

const HEALTH_URL = "https://yourapp.com/api/health";
const TIMEOUT_MS = 10000;

export async function checkHealth() {
  const start = Date.now();
  try {
    const res = await fetch(HEALTH_URL, { signal: AbortSignal.timeout(TIMEOUT_MS) });
    const duration = Date.now() - start;

    if (!res.ok) {
      await logit.now("uptime", {
        event: "Health check failed",
        description: `Status ${res.status} โ€” app may be down`,
        icon: "๐Ÿšจ",
        notify: true,
        metadata: { status: res.status, durationMs: duration, url: HEALTH_URL },
      });
    }
  } catch (error) {
    await logit.now("uptime", {
      event: "App unreachable",
      description: error instanceof Error ? error.message : "Timeout or network error",
      icon: "๐Ÿ”ด",
      notify: true,
      metadata: {
        error: error instanceof Error ? error.message : String(error),
        url: HEALTH_URL,
        durationMs: Date.now() - start,
      },
    });
  }
}

Log recovery too

ts
// Track when the app comes back up after a failure
await logit.now("uptime", {
  event: "App recovered",
  description: "Health check passing again",
  icon: "โœ…",
  notify: true,
  metadata: { durationMs: Date.now() - start },
});

Vercel Cron setup

json
// vercel.json
{
  "crons": [
    {
      "path": "/api/cron/health-check",
      "schedule": "* * * * *"
    }
  ]
}

Tip: If you log when the app goes down AND when it comes back up, you can calculate downtime duration from the LogIt event timestamps.

Try LogIt free

7-day trial. No credit card required.

Start free