DEV Community

Vigilmon
Vigilmon

Posted on

How to Monitor Your AdonisJS Application with Vigilmon

How to Monitor Your AdonisJS Application with Vigilmon

AdonisJS is a full-featured Node.js MVC framework inspired by Laravel. Its first-class TypeScript support, ORM (Lucid), and batteries-included design make it popular for building APIs and web apps. Like any production service, it needs uptime monitoring.

This guide covers adding a health endpoint to your AdonisJS app and connecting it to Vigilmon.

Adding a Health Route in AdonisJS

AdonisJS uses a controller-based routing system. Let's add a proper health endpoint:

Create the Health Controller

node ace make:controller Health --resource
Enter fullscreen mode Exit fullscreen mode

Edit app/Controllers/Http/HealthController.ts:

import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import Database from '@ioc:Adonis/Lucid/Database'

export default class HealthController {
  public async index({ response }: HttpContextContract) {
    const checks: Record<string, string> = {}

    // Database check
    try {
      await Database.rawQuery('SELECT 1')
      checks.database = 'ok'
    } catch (e) {
      checks.database = 'error'
    }

    const allOk = Object.values(checks).every(v => v === 'ok')

    return response
      .status(allOk ? 200 : 503)
      .json({
        status: allOk ? 'ok' : 'degraded',
        checks
      })
  }
}
Enter fullscreen mode Exit fullscreen mode

Register the Route

In start/routes.ts:

import Route from '@ioc:Adonis/Core/Route'

Route.get('/health', 'HealthController.index')
Enter fullscreen mode Exit fullscreen mode

Using AdonisJS v6 (new syntax)

AdonisJS v6 switched to ESM and a new router API:

// start/routes.ts
import router from '@adonisjs/core/services/router'
import db from '@adonisjs/lucid/services/db'

router.get('/health', async ({ response }) => {
  try {
    await db.rawQuery('SELECT 1')
    return response.json({ status: 'ok', db: 'connected' })
  } catch {
    return response.status(503).json({ status: 'error', db: 'disconnected' })
  }
})
Enter fullscreen mode Exit fullscreen mode

Testing Your Health Endpoint

# Local development
curl http://127.0.0.1:3333/health

# Expected output
# {"status":"ok","checks":{"database":"ok"}}
Enter fullscreen mode Exit fullscreen mode

Setting Up Vigilmon

  1. Go to vigilmon.online and create a free account
  2. Click Add Monitor
  3. Enter URL: https://your-adonis-app.com/health
  4. Set interval: 1 minute
  5. Enable keyword check: verify "status":"ok" in response body
  6. Multi-region: on
  7. Add email/Slack/webhook alert contact

AdonisJS Deployment + Monitoring Best Practices

PM2 + Vigilmon

Most AdonisJS apps run behind PM2:

pm2 start ecosystem.config.js
Enter fullscreen mode Exit fullscreen mode
// ecosystem.config.js
module.exports = {
  apps: [{
    name: 'my-adonis-app',
    script: 'server.js',
    instances: 'max',
    exec_mode: 'cluster',
    env_production: {
      NODE_ENV: 'production',
      PORT: 3333
    }
  }]
}
Enter fullscreen mode Exit fullscreen mode

Vigilmon catches what PM2 misses: if the app restarts too frequently, its external checks show intermittent failures.

Queue and Background Job Monitoring

AdonisJS uses Bull or Adonis Queue for background jobs. Monitor queue health separately:

router.get('/health/queue', async ({ response }) => {
  const queueHealth = await checkQueueHealth()
  return response
    .status(queueHealth ? 200 : 503)
    .json({ status: queueHealth ? 'ok' : 'error', queue: 'bull' })
})
Enter fullscreen mode Exit fullscreen mode

Conclusion

AdonisJS is a production-grade framework — and Vigilmon is the perfect complement for external uptime monitoring. Add your health endpoint, connect Vigilmon, and you'll know instantly when your AdonisJS app goes down.

Start monitoring at vigilmon.online.

Top comments (0)