DEV Community

Vigilmon
Vigilmon

Posted on

How to Monitor Your Cloudflare Workers Application with Vigilmon

How to Monitor Your Cloudflare Workers Application with Vigilmon

Cloudflare Workers run your JavaScript at the edge — in 300+ data centers worldwide with millisecond cold starts. But even Workers can fail: deployment errors, exceeding CPU limits, dependency failures, and KV/D1 outages can all cause your Worker to return errors. This guide shows how to monitor your Cloudflare Worker with Vigilmon.

Why Monitor a Cloudflare Worker?

Common Cloudflare Worker failure scenarios:

  • Unhandled exceptions — a bad deployment that throws on every request
  • CPU limit exceeded — 50ms CPU time on free tier, 30s on paid
  • KV/R2/D1 outages — Cloudflare's storage services have independent SLAs
  • External API timeoutsfetch() calls that hang indefinitely
  • Environment variable mistakes — missing secrets in production deployment

Vigilmon checks your Worker from multiple regions every minute. If it returns a non-200 status or takes too long, you're alerted immediately.

Basic Worker Monitoring

  1. Sign up at vigilmon.online
  2. Add a monitor for your Worker URL
  3. Set interval: 1 minute
  4. Configure alerts

Your Worker URL is typically https://your-worker.your-subdomain.workers.dev or a custom domain.

Adding a Health Check Handler to Your Worker

Add a dedicated health check route to your Worker:

// worker.ts (using Hono or similar framework)
import { Hono } from 'hono';

const app = new Hono();

app.get('/health', (c) => {
  return c.json({
    status: 'ok',
    runtime: 'cloudflare-workers',
    region: c.req.raw.cf?.colo ?? 'unknown',
  });
});

app.get('/', (c) => {
  return c.text('Hello, World!');
});

export default app;
Enter fullscreen mode Exit fullscreen mode

Or in vanilla Workers:

// worker.ts
export default {
  async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
    const url = new URL(request.url);

    if (url.pathname === '/health') {
      return Response.json({
        status: 'ok',
        runtime: 'cloudflare-workers',
      });
    }

    // ... rest of your worker logic
  },
};
Enter fullscreen mode Exit fullscreen mode

Monitor https://your-worker.workers.dev/health in Vigilmon with keyword check "status":"ok".

Monitoring KV Store Connectivity

If your Worker depends on KV storage, check it in your health endpoint:

if (url.pathname === '/health') {
  try {
    // Write and read back a test value
    await env.MY_KV.put('health_check', 'ok', { expirationTtl: 60 });
    const value = await env.MY_KV.get('health_check');

    if (value !== 'ok') {
      return Response.json({ status: 'error', kv: 'read_mismatch' }, { status: 503 });
    }

    return Response.json({ status: 'ok', kv: 'connected' });
  } catch (e) {
    return Response.json({ status: 'error', kv: 'failed' }, { status: 503 });
  }
}
Enter fullscreen mode Exit fullscreen mode

Monitoring D1 Database Connectivity

For Workers using D1 (Cloudflare's SQLite):

if (url.pathname === '/health') {
  try {
    const result = await env.DB.prepare('SELECT 1 as ping').first();

    return Response.json({
      status: 'ok',
      d1: result?.ping === 1 ? 'connected' : 'unexpected_response',
    });
  } catch (e) {
    return Response.json({ status: 'error', d1: 'failed' }, { status: 503 });
  }
}
Enter fullscreen mode Exit fullscreen mode

Multi-Region Monitoring for Edge Workers

Cloudflare Workers run globally, but failures can be region-specific. Vigilmon's multi-region checks from US, Europe, and Asia Pacific help you catch:

  • Regional KV replication issues
  • Edge routing problems in specific colo locations
  • SSL certificate issues for custom domains

Monitoring Worker CPU Time

Cloudflare Workers have CPU time limits:

  • Free: 10ms CPU time
  • Paid (Workers Unbound): 30 seconds

If a Worker regularly approaches its CPU limit, requests start failing. You can't directly check CPU time with Vigilmon, but you can monitor response time as a proxy:

Set a Vigilmon alert if response time exceeds 500ms for a Worker. Workers should respond in tens of milliseconds — if they're taking 500ms, something is wrong (CPU-bound loop, external API slow, etc.).

Monitoring Custom Domains on Workers

If your Worker serves a custom domain (e.g., api.yourapp.com), Vigilmon also monitors the SSL certificate for that domain. You'll be alerted before expiry.

Wrangler Deployment Health Checks

After deploying with Wrangler, verify the deployment is healthy in CI:

# In your GitHub Actions deploy workflow
- name: Deploy Worker
  run: wrangler deploy

- name: Verify deployment
  run: |
    STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://your-worker.workers.dev/health)
    if [ "$STATUS" != "200" ]; then
      echo "Health check failed: $STATUS"
      exit 1
    fi
    echo "Deployment verified: $STATUS"
Enter fullscreen mode Exit fullscreen mode

This catches bad deployments immediately in CI, before Vigilmon's next check fires.

Monitoring Workers with Service Bindings

If you use Cloudflare Workers Service Bindings (one Worker calling another), monitor each Worker independently:

Monitor 1: https://api-worker.workers.dev/health (public API Worker)
Monitor 2: https://auth-worker.workers.dev/health (auth Worker — if publicly accessible)
Monitor 3: https://queue-worker.workers.dev/health (queue processor)
Enter fullscreen mode Exit fullscreen mode

Internal Workers not exposed publicly can use a separate health check via a shared monitoring route.

Alert Configuration for Workers

Recommended settings:

  • Alert after: 1 consecutive failure (Workers should almost never fail transiently)
  • Timeout: 5 seconds (Workers under 1 second is normal)
  • Check interval: 1 minute
  • Alert channels: Slack + PagerDuty for production

Summary

Cloudflare Workers are fast and reliable, but not immune to failures. Add a /health endpoint that checks your Worker's dependencies (KV, D1, external APIs), monitor it with Vigilmon, and get alerted within 1 minute of any issues.

Start free at vigilmon.online.

Top comments (0)