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);
});
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(),
};
}
);
Setting Up Vigilmon Monitoring
HTTP Uptime Monitor
- Log in to vigilmon.online
- Click Add Monitor → HTTP(S)
- URL:
https://api.yourapp.com/health - Expected status code: 200
- Alert on non-200 response or timeout
- Interval: 60 seconds
SSL Certificate Monitor
- Add an SSL Monitor for
api.yourapp.com - 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
}
});
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'
}
}]
};
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"]
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:
- Create a Status Page in Vigilmon
- Add your API health monitor
- Publish at
status.yourapi.com - Developers can subscribe to status updates
Recommended Monitor Configuration
| Monitor | URL | Interval | Alert |
|---|---|---|---|
| API health | /health |
60s | Slack + email |
| SSL cert | Domain | Daily | |
| 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:
-
HTTP monitor on your
/healthendpoint - SSL certificate monitoring
- Heartbeat monitors for background workers
- Response time thresholds to catch slowdowns before they become outages
- Status page for API consumers
Vigilmon — uptime monitoring for Fastify and Node.js APIs.
Top comments (0)