DEV Community

Vigilmon
Vigilmon

Posted on

How to Monitor Your Elysia Application with Vigilmon

How to Monitor Your Elysia Application with Vigilmon

Elysia is the fast, ergonomic web framework for Bun — designed for TypeScript-first development with a focus on developer experience and end-to-end type safety. Here's how to add health monitoring to your Elysia application and connect it to Vigilmon for external uptime monitoring.

Adding Health Endpoints to Elysia

Basic Health Check

import { Elysia } from 'elysia';

const app = new Elysia()
  .get('/health', () => ({
    status: 'ok',
    runtime: 'bun',
    framework: 'elysia',
    version: Bun.version,
    uptime: process.uptime(),
    timestamp: new Date().toISOString(),
  }))
  .listen(3000);

console.log(`Elysia running at http://localhost:3000`);
Enter fullscreen mode Exit fullscreen mode

With Database Connectivity Check

import { Elysia } from 'elysia';
import { drizzle } from 'drizzle-orm/bun-sqlite';
import { Database } from 'bun:sqlite';

const db = drizzle(new Database('app.db'));

const app = new Elysia()
  .get('/health', async () => {
    try {
      // Test DB connection
      await db.execute('SELECT 1');
      return {
        status: 'ok',
        database: 'connected',
        uptime: process.uptime(),
      };
    } catch (error) {
      return new Response(
        JSON.stringify({
          status: 'error',
          database: 'disconnected',
        }),
        { status: 503 }
      );
    }
  })
  .listen(3000);
Enter fullscreen mode Exit fullscreen mode

Health Check Plugin (Reusable)

import { Elysia } from 'elysia';

// Reusable health plugin
const healthPlugin = new Elysia({ name: 'health' })
  .get('/health', () => ({
    status: 'ok',
    uptime: process.uptime(),
    memory: process.memoryUsage(),
    timestamp: new Date().toISOString(),
  }))
  .get('/health/ready', async () => {
    // Readiness check — all dependencies available?
    const checks = {
      database: false,
      cache: false,
    };

    // Check your dependencies here
    // checks.database = await testDbConnection();
    // checks.cache = await testCacheConnection();

    const allReady = Object.values(checks).every(Boolean);

    return new Response(
      JSON.stringify({ ready: allReady, checks }),
      { status: allReady ? 200 : 503 }
    );
  });

// Use in your app
const app = new Elysia()
  .use(healthPlugin)
  .get('/', () => 'Hello Elysia!')
  .listen(3000);
Enter fullscreen mode Exit fullscreen mode

With Elysia Eden (Full Type Safety)

import { Elysia, t } from 'elysia';

const healthSchema = t.Object({
  status: t.String(),
  uptime: t.Number(),
  timestamp: t.String(),
});

const app = new Elysia()
  .get('/health', 
    (): typeof healthSchema.static => ({
      status: 'ok',
      uptime: process.uptime(),
      timestamp: new Date().toISOString(),
    }),
    { response: healthSchema }
  )
  .listen(3000);
Enter fullscreen mode Exit fullscreen mode

Heartbeat Monitoring for Elysia Background Jobs

import { Elysia } from 'elysia';

const VIGILMON_HEARTBEAT = 'https://vigilmon.online/api/heartbeat/YOUR_MONITOR_ID';

// Background job with heartbeat
async function runJob() {
  try {
    // Your job logic
    await processQueue();

    // Signal success
    await fetch(VIGILMON_HEARTBEAT, { method: 'POST' });
  } catch (err) {
    console.error('Job failed:', err);
    // Don't send heartbeat on failure — Vigilmon will alert
  }
}

// Run every 5 minutes
setInterval(runJob, 5 * 60 * 1000);

const app = new Elysia()
  .get('/health', () => ({ status: 'ok' }))
  .listen(3000);
Enter fullscreen mode Exit fullscreen mode

Docker Setup for Elysia

# Dockerfile
FROM oven/bun:1 as base

WORKDIR /app

COPY package.json bun.lock ./
RUN bun install --frozen-lockfile

COPY . .

EXPOSE 3000

# Health check for Docker
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \n  CMD curl -f http://localhost:3000/health || exit 1

CMD ["bun", "run", "src/index.ts"]
Enter fullscreen mode Exit fullscreen mode
# docker-compose.yml
services:
  app:
    build: .
    ports:
      - "3000:3000"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
      interval: 30s
      timeout: 10s
      retries: 3
    restart: unless-stopped
Enter fullscreen mode Exit fullscreen mode

Setting Up Vigilmon

  1. Sign up at vigilmon.online
  2. Add HTTP monitor → https://your-elysia-app.com/health
  3. Configure: 1-min check interval, email + Slack alerts
  4. Add SSL monitor → https://your-elysia-app.com
  5. Add heartbeat monitor for background jobs

Monitoring Checklist

  • [ ] /health returns 200 with JSON
  • [ ] Database check included in health endpoint
  • [ ] External dependency checks (Redis, APIs)
  • [ ] Docker HEALTHCHECK configured
  • [ ] Vigilmon uptime monitor active
  • [ ] SSL certificate monitor active
  • [ ] Heartbeat monitors for background jobs
  • [ ] Alert channels configured (email + Slack)

Start monitoring your Elysia app free →

Top comments (0)