DEV Community

Vigilmon
Vigilmon

Posted on

How to Monitor Your API Rate Limits and Third-Party Dependencies with Vigilmon

How to Monitor Your API Rate Limits and Third-Party Dependencies with Vigilmon

Most uptime monitoring focuses on your own infrastructure — your servers, your databases, your APIs. But modern applications depend heavily on third-party APIs: payment processors, email providers, mapping services, AI APIs, SMS gateways. When those go down or rate-limit you into silence, your app fails in ways your own monitors won't catch.

This guide shows how to monitor third-party API dependencies and rate limit health with Vigilmon.


Why Third-Party API Monitoring Matters

Your own infrastructure could be perfectly healthy while:

  • Stripe's API is degraded → payments fail silently
  • Sendgrid is throttling you → confirmation emails don't arrive; signups abandon
  • OpenAI's API is rate limiting your account → AI features return errors
  • Twilio is down in a region → SMS verification fails
  • Google Maps exceeded your quota → maps don't render

Third-party failures are the cause of roughly 40% of production incidents in API-driven applications.


Strategy 1: Monitor Status Pages Directly

Most major API providers have public status pages. You can monitor these:

Provider Status Page
Stripe status.stripe.com
Sendgrid status.sendgrid.com
Twilio status.twilio.com
OpenAI status.openai.com
GitHub githubstatus.com
Cloudflare cloudflarestatus.com
AWS health.aws.amazon.com

Add HTTP(S) monitors for the status pages you care about — many return non-200 or include structured data when there's an active incident.


Strategy 2: Build Proxy Health Endpoints

The best approach is to build lightweight health check routes in your application that test third-party connectivity:

// Express.js: Health check that validates all critical dependencies
app.get('/health/dependencies', async (req, res) => {
  const checks = {};

  // Check Stripe API
  try {
    const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);
    await stripe.balance.retrieve();
    checks.stripe = 'ok';
  } catch (err) {
    checks.stripe = err.type === 'StripeAuthenticationError' ? 'config_error' : 'degraded';
  }

  // Check Sendgrid
  try {
    const sgClient = require('@sendgrid/client');
    sgClient.setApiKey(process.env.SENDGRID_API_KEY);
    const [response] = await sgClient.request({ method: 'GET', url: '/v3/scopes' });
    checks.sendgrid = response.statusCode === 200 ? 'ok' : 'degraded';
  } catch (err) {
    checks.sendgrid = 'error';
  }

  // Check your database
  try {
    await db.raw('SELECT 1');
    checks.database = 'ok';
  } catch (err) {
    checks.database = 'error';
  }

  const hasErrors = Object.values(checks).some(v => v === 'error' || v === 'degraded');

  res.status(hasErrors ? 503 : 200).json({
    status: hasErrors ? 'degraded' : 'ok',
    dependencies: checks,
  });
});
Enter fullscreen mode Exit fullscreen mode

Monitor /health/dependencies with Vigilmon — it returns 503 when any critical dependency is unhealthy.


Strategy 3: Monitor Rate Limit Headroom via Heartbeat

Rate limiting is more insidious than full outages — you don't get a 503, you get 429s that only some users experience.

Build a rate limit monitor:

// rate-limit-check.js — run as a cron every 5 minutes
const fetch = require('node-fetch');

async function checkOpenAIRateLimit() {
  const response = await fetch('https://api.openai.com/v1/models', {
    headers: { 'Authorization': `Bearer ${process.env.OPENAI_API_KEY}` }
  });

  // OpenAI returns rate limit headers
  const remaining = parseInt(response.headers.get('x-ratelimit-remaining-requests') || '999');
  const limit = parseInt(response.headers.get('x-ratelimit-limit-requests') || '999');
  const usagePercent = ((limit - remaining) / limit) * 100;

  // Only ping heartbeat if usage is < 80% of limit
  if (response.ok && usagePercent < 80) {
    await fetch(process.env.VIGILMON_OPENAI_HEARTBEAT_URL);
  }
  // If rate limit > 80% OR API is down, heartbeat stops → Vigilmon alerts
}

checkOpenAIRateLimit().catch(console.error);
Enter fullscreen mode Exit fullscreen mode

Strategy 4: Monitor Payment Gateway Health

Payment failures are the most expensive type of API degradation. Add dedicated monitors:

// Check Stripe specifically
async function stripeHealthCheck() {
  try {
    // A real API call that doesn't charge anything
    const balance = await stripe.balance.retrieve();
    // If we get here, Stripe API is working
    await fetch(process.env.VIGILMON_STRIPE_HEARTBEAT_URL);
  } catch (err) {
    // Heartbeat not sent — Vigilmon alerts after interval
    console.error('Stripe health check failed:', err.message);
  }
}

// Run every 5 minutes via cron
Enter fullscreen mode Exit fullscreen mode

Strategy 5: Monitor Your Email Delivery Rate

# check_email_delivery.py
import sendgrid
import os
import requests

def check_email_delivery_rate():
    sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))

    # Get stats for last hour
    params = {'start_date': '2026-01-01', 'limit': 1}  # Adjust dates
    response = sg.client.stats.get(query_params=params)

    stats = response.to_dict
    # Check bounce rate
    bounce_rate = stats[0]['stats'][0]['metrics']['bounce_rate']

    if bounce_rate < 0.05:  # < 5% bounce rate is healthy
        requests.get(os.environ.get('VIGILMON_EMAIL_HEARTBEAT_URL'))
Enter fullscreen mode Exit fullscreen mode

Third-Party Dependency Monitoring Matrix

Dependency Monitor Type Alert Condition
Stripe API HTTP(S) proxy health endpoint Status != 200
Email provider Heartbeat (5-min delivery check) No ping in > 6 min
OpenAI API Heartbeat (rate limit check) No ping if > 80% used
Payment webhook HTTP(S) receiver health Status != 200
Third-party status pages HTTP(S) Non-200 response

Conclusion

Your application is only as reliable as its weakest dependency. By wrapping third-party API calls in proxy health endpoints and heartbeat checks, Vigilmon catches dependency failures — even when your own infrastructure is perfectly healthy.

Add dependency monitoring to Vigilmon free at vigilmon.online

Top comments (0)