DEV Community

Vigilmon
Vigilmon

Posted on

How to Monitor Your Elysia.js API with Vigilmon (Uptime + Heartbeats)

Elysia.js is a fast TypeScript framework for Bun runtime. If you're building APIs with Elysia, here's how to add uptime monitoring and heartbeat checks with Vigilmon.

Step 1: Add a Health Check Route to Elysia

import { Elysia } from 'elysia';

const app = new Elysia()
  .get('/health', () => ({
    status: 'ok',
    timestamp: Date.now(),
    runtime: 'bun'
  }))
  .get('/api/users', () => getUsers())
  .listen(3000);

console.log(`Server running at http://${app.server?.hostname}:${app.server?.port}`);
Enter fullscreen mode Exit fullscreen mode

Step 2: Enhanced Health Check with Database Connectivity

const app = new Elysia()
  .get('/health', async ({ set }) => {
    const checks: Record<string, boolean> = {
      server: true,
      database: false,
    };

    try {
      await db.execute('SELECT 1');
      checks.database = true;
    } catch {}

    const allHealthy = Object.values(checks).every(Boolean);
    set.status = allHealthy ? 200 : 503;

    return {
      status: allHealthy ? 'ok' : 'degraded',
      checks,
      timestamp: Date.now(),
    };
  })
  .listen(3000);
Enter fullscreen mode Exit fullscreen mode

If the database is down, this returns 503 and Vigilmon alerts your team.

Step 3: Set Up Vigilmon Monitoring

  1. Go to vigilmon.online
  2. Create a new HTTP monitor
  3. URL: https://your-elysia-api.com/health
  4. Check interval: 1 minute
  5. Multi-region: enabled

Step 4: Heartbeat Monitoring for Background Tasks

// src/tasks/daily-cleanup.ts
const HEARTBEAT_URL = process.env.VIGILMON_HEARTBEAT_URL;

export async function runDailyCleanup() {
  try {
    await deleteOldSessions();
    await archiveExpiredOrders();

    if (HEARTBEAT_URL) {
      await fetch(HEARTBEAT_URL).catch(() => {});
    }
  } catch (error) {
    console.error('Cleanup failed:', error);
    // No heartbeat = Vigilmon alerts
  }
}
Enter fullscreen mode Exit fullscreen mode

Create a heartbeat monitor with a 25-hour period for daily tasks.

Elysia on Bun + Docker

FROM oven/bun:1 as base
WORKDIR /app
COPY package*.json bun.lockb ./
RUN bun install --frozen-lockfile
COPY . .
EXPOSE 3000
CMD ["bun", "src/index.ts"]
Enter fullscreen mode Exit fullscreen mode

After deploying to Fly.io, Railway, or Render, add a Vigilmon monitor pointing to your production URL.

What Vigilmon Catches for Elysia

Issue Detected by
Bun process crashed Connection refused
Unhandled exception Brief downtime detected
Database connection lost 503 from health endpoint
OOM kill Downtime detected
Regional network issue Multi-region cross-check

Summary

  1. Add a /health route to your Elysia app
  2. Check database connectivity (return 503 if DB is down)
  3. Create a Vigilmon HTTP monitor for the health endpoint
  4. Add heartbeat monitoring for scheduled background tasks
  5. Set up Slack/email alerts

Elysia + Bun is fast. Keep it reliable with Vigilmon.


Vigilmon — uptime and heartbeat monitoring for Elysia.js, Hono, Fastify, and every Bun API. Free plan available.

Top comments (0)