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`);
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);
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);
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);
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);
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"]
# 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
Setting Up Vigilmon
- Sign up at vigilmon.online
-
Add HTTP monitor →
https://your-elysia-app.com/health - Configure: 1-min check interval, email + Slack alerts
-
Add SSL monitor →
https://your-elysia-app.com - Add heartbeat monitor for background jobs
Monitoring Checklist
- [ ]
/healthreturns 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)
Top comments (0)