DEV Community

Vigilmon
Vigilmon

Posted on • Originally published at vigilmon.online

How to Monitor Your Fastify.js API with Vigilmon

How to Monitor Your Fastify.js API with Vigilmon

Fastify is one of the fastest Node.js web frameworks — it processes thousands of requests per second with minimal overhead. But performance doesn't protect you from infrastructure failures. This guide covers monitoring your Fastify API with Vigilmon.

Why Fastify APIs Need External Monitoring

Fastify's high throughput means failures affect more users faster. When a Fastify API goes down:

  • Millions of requests/hour suddenly fail
  • Error rates spike immediately
  • Downstream services that depend on your API start failing

Vigilmon monitors your Fastify API from outside your infrastructure — it'll alert you before your users notice.

Adding a Health Check Route to Fastify

Add a lightweight health endpoint that Vigilmon can probe:

// server.js or app.js
const fastify = require('fastify')({ logger: true });
const { Pool } = require('pg');

const pool = new Pool({ connectionString: process.env.DATABASE_URL });

// Health check route
fastify.get('/health', async (request, reply) => {
  const health = {
    status: 'ok',
    uptime: process.uptime(),
    timestamp: new Date().toISOString(),
  };

  // Check database
  try {
    await pool.query('SELECT 1');
    health.db = 'connected';
  } catch (err) {
    health.status = 'degraded';
    health.db = 'error';
    reply.code(503);
  }

  return health;
});

fastify.listen({ port: 3000 }, (err) => {
  if (err) process.exit(1);
});
Enter fullscreen mode Exit fullscreen mode

With TypeScript:

import Fastify from 'fastify';

const fastify = Fastify({ logger: true });

fastify.get<{ Reply: { status: string; uptime: number } }>(
  '/health',
  async (request, reply) => {
    return {
      status: 'ok',
      uptime: process.uptime(),
    };
  }
);
Enter fullscreen mode Exit fullscreen mode

Setting Up Vigilmon Monitoring

HTTP Uptime Monitor

  1. Log in to vigilmon.online
  2. Click Add MonitorHTTP(S)
  3. URL: https://api.yourapp.com/health
  4. Expected status code: 200
  5. Alert on non-200 response or timeout
  6. Interval: 60 seconds

SSL Certificate Monitor

  1. Add an SSL Monitor for api.yourapp.com
  2. Alert threshold: 14 days before expiry

Heartbeat Monitor for Background Workers

If you have Fastify-based background jobs using @fastify/schedule or custom intervals:

const schedule = require('node-cron');
const axios = require('axios');

// Background job that pings Vigilmon to prove it's running
schedule.schedule('*/5 * * * *', async () => {
  try {
    await runDataProcessingJob();
    // Ping heartbeat on success
    await axios.get(process.env.VIGILMON_HEARTBEAT_URL);
  } catch (err) {
    fastify.log.error('Background job failed', err);
    // Don't ping — Vigilmon will alert on missing heartbeat
  }
});
Enter fullscreen mode Exit fullscreen mode

Configure the heartbeat monitor in Vigilmon:

  • Type: Heartbeat
  • Expected interval: 10 minutes
  • Alert if no ping received in time window

Monitoring Fastify with PM2 or Docker

PM2 Deployment

If running with PM2, your process manager will restart crashed Fastify processes — but Vigilmon catches the window between crash and restart:

// ecosystem.config.js
module.exports = {
  apps: [{
    name: 'api',
    script: './server.js',
    instances: 'max',
    exec_mode: 'cluster',
    watch: false,
    env_production: {
      NODE_ENV: 'production',
      VIGILMON_HEARTBEAT_URL: 'https://push.vigilmon.online/YOUR_KEY'
    }
  }]
};
Enter fullscreen mode Exit fullscreen mode

Docker/Container Deployment

In your Dockerfile, expose the health endpoint:

FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000

# Docker health check (internal)
HEALTHCHECK --interval=30s --timeout=10s --retries=3 \n  CMD curl -f http://localhost:3000/health || exit 1

CMD ["node", "server.js"]
Enter fullscreen mode Exit fullscreen mode

Vigilmon provides external monitoring; Docker's HEALTHCHECK provides internal container health.

Response Time Monitoring

Fastify is fast — but database queries and external API calls can slow it down. Set response time thresholds in Vigilmon:

  • Warning: > 500ms response time
  • Critical: > 2000ms response time
  • Timeout: > 10 seconds

A response time alert that comes before an uptime alert often indicates a memory leak, slow query, or resource exhaustion.

Status Page for Your Fastify API

If your API serves external developers or customers:

  1. Create a Status Page in Vigilmon
  2. Add your API health monitor
  3. Publish at status.yourapi.com
  4. Developers can subscribe to status updates

Recommended Monitor Configuration

Monitor URL Interval Alert
API health /health 60s Slack + email
SSL cert Domain Daily Email
Background jobs Heartbeat 10 min Slack
Main endpoint / or /api/v1 60s PagerDuty

Summary

Fastify's performance makes failures more impactful — more users affected faster. External monitoring with Vigilmon gives you the early warning you need:

  1. HTTP monitor on your /health endpoint
  2. SSL certificate monitoring
  3. Heartbeat monitors for background workers
  4. Response time thresholds to catch slowdowns before they become outages
  5. Status page for API consumers

Vigilmon — uptime monitoring for Fastify and Node.js APIs.

Top comments (0)