Monitoring and Analytics with QueueSaaS - QueueSaaS Blog
Relay
QueueSaaS Team

Monitoring and Analytics with QueueSaaS

Learn how to track message delivery, monitor system health, and analyze usage patterns with QueueSaaS analytics API. Build dashboards and set up alerts.

analytics monitoring observability tutorial

Monitoring and Analytics with QueueSaaS

Understanding your message queue performance is crucial for maintaining reliable systems. QueueSaaS provides comprehensive analytics and monitoring capabilities to help you track delivery rates, identify bottlenecks, and optimize your messaging patterns.

Analytics Overview

QueueSaaS tracks:

  • Message delivery statistics
  • Success and failure rates
  • Delivery latency
  • Schedule execution history
  • Usage patterns over time

Getting Started

import { Client } from '@anlyonhq/scheduler';

const client = new Client({
  apiKey: process.env.ANLYON_API_KEY!,
});

// Get message analytics
const analytics = await client.analytics.messages({
  startDate: '2025-01-01T00:00:00Z',
  endDate: '2025-01-31T23:59:59Z',
});

console.log(`Total messages: ${analytics.data.total}`);
console.log(`Delivered: ${analytics.data.delivered}`);
console.log(`Failed: ${analytics.data.failed}`);
console.log(`Success rate: ${analytics.data.successRate}%`);

Message Analytics

Overall Statistics

const stats = await client.analytics.messages({
  startDate: '2025-01-01T00:00:00Z',
  endDate: '2025-01-31T23:59:59Z',
});

console.log('Message Statistics:', {
  total: stats.data.total,
  delivered: stats.data.delivered,
  failed: stats.data.failed,
  pending: stats.data.pending,
  successRate: `${stats.data.successRate}%`,
  averageLatency: `${stats.data.averageLatency}ms`,
});

Time-Series Data

Get hourly or daily breakdowns:

const timeSeries = await client.analytics.messages({
  startDate: '2025-01-01T00:00:00Z',
  endDate: '2025-01-31T23:59:59Z',
  granularity: 'daily', // or 'hourly'
});

timeSeries.data.timeSeries.forEach(entry => {
  console.log(`${entry.date}: ${entry.delivered} delivered, ${entry.failed} failed`);
});

Filter by Status

Analyze specific message states:

// Get only failed messages
const failed = await client.analytics.messages({
  startDate: '2025-01-01T00:00:00Z',
  endDate: '2025-01-31T23:59:59Z',
  status: 'failed',
});

// Get only delivered messages
const delivered = await client.analytics.messages({
  startDate: '2025-01-01T00:00:00Z',
  endDate: '2025-01-31T23:59:59Z',
  status: 'delivered',
});

Schedule Analytics

Track CRON schedule execution:

const scheduleStats = await client.analytics.schedules({
  startDate: '2025-01-01T00:00:00Z',
  endDate: '2025-01-31T23:59:59Z',
});

console.log('Schedule Statistics:', {
  totalExecutions: scheduleStats.data.totalExecutions,
  successful: scheduleStats.data.successful,
  failed: scheduleStats.data.failed,
  successRate: `${scheduleStats.data.successRate}%`,
});

Usage Analytics

Monitor your usage and quotas:

// Get current usage
const usage = await client.billing.getUsage();

console.log('Current Usage:', {
  messagesToday: usage.data.usage.messagesToday,
  messagesThisMonth: usage.data.usage.messagesThisMonth,
  bandwidth: usage.data.usage.bandwidth,
  remaining: usage.data.remaining,
});

// Get usage history
const history = await client.billing.getUsageHistory({ days: 30 });

history.data.history.forEach(day => {
  console.log(`${day.date}: ${day.messagesPublished} messages published`);
});

Building Dashboards

Real-Time Dashboard

async function buildDashboard() {
  // Get current stats
  const [messages, schedules, usage] = await Promise.all([
    client.analytics.messages({
      startDate: new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(),
      endDate: new Date().toISOString(),
    }),
    client.analytics.schedules({
      startDate: new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(),
      endDate: new Date().toISOString(),
    }),
    client.billing.getUsage(),
  ]);

  return {
    messages: {
      total: messages.data.total,
      successRate: messages.data.successRate,
      averageLatency: messages.data.averageLatency,
    },
    schedules: {
      totalExecutions: schedules.data.totalExecutions,
      successRate: schedules.data.successRate,
    },
    usage: {
      messagesToday: usage.data.usage.messagesToday,
      messagesThisMonth: usage.data.usage.messagesThisMonth,
      remaining: usage.data.remaining,
    },
  };
}
async function getTrends(days: number = 30) {
  const endDate = new Date();
  const startDate = new Date();
  startDate.setDate(startDate.getDate() - days);

  const analytics = await client.analytics.messages({
    startDate: startDate.toISOString(),
    endDate: endDate.toISOString(),
    granularity: 'daily',
  });

  return analytics.data.timeSeries.map(entry => ({
    date: entry.date,
    delivered: entry.delivered,
    failed: entry.failed,
    successRate: (entry.delivered / (entry.delivered + entry.failed)) * 100,
  }));
}

Setting Up Alerts

Usage Alerts

QueueSaaS automatically sends alerts when you approach quota limits. Configure thresholds:

await client.notifications.updatePreferences({
  quotaAlertThresholds: [50, 75, 90, 100], // Alert at these percentages
  emailRecipients: ['ops@example.com'],
  enabledTypes: ['quota_warning', 'quota_exceeded'],
});

Failure Rate Alerts

Monitor for delivery failure spikes:

async function checkFailureRate() {
  const stats = await client.analytics.messages({
    startDate: new Date(Date.now() - 60 * 60 * 1000).toISOString(), // Last hour
    endDate: new Date().toISOString(),
  });

  const failureRate = (stats.data.failed / stats.data.total) * 100;

  if (failureRate > 10) { // Alert if > 10% failure rate
    // Send alert to monitoring system
    console.warn(`High failure rate detected: ${failureRate}%`);
  }
}

Integration with Monitoring Tools

Prometheus Metrics

import { Registry, Counter, Gauge } from 'prom-client';

const registry = new Registry();
const messagesTotal = new Counter({
  name: 'queuesaas_messages_total',
  help: 'Total messages published',
  registers: [registry],
});

const messagesDelivered = new Counter({
  name: 'queuesaas_messages_delivered',
  help: 'Messages delivered successfully',
  registers: [registry],
});

async function updateMetrics() {
  const stats = await client.analytics.messages({
    startDate: new Date(Date.now() - 60 * 60 * 1000).toISOString(),
    endDate: new Date().toISOString(),
  });

  messagesTotal.inc(stats.data.total);
  messagesDelivered.inc(stats.data.delivered);
}

Datadog Integration

import { StatsD } from 'node-statsd';
const statsd = new StatsD();

async function sendToDatadog() {
  const stats = await client.analytics.messages({
    startDate: new Date(Date.now() - 60 * 60 * 1000).toISOString(),
    endDate: new Date().toISOString(),
  });

  statsd.gauge('queuesaas.messages.total', stats.data.total);
  statsd.gauge('queuesaas.messages.delivered', stats.data.delivered);
  statsd.gauge('queuesaas.messages.failed', stats.data.failed);
  statsd.gauge('queuesaas.success_rate', stats.data.successRate);
}

Best Practices

  1. Monitor regularly: Set up automated checks for key metrics
  2. Track trends: Look for patterns in success rates over time
  3. Set appropriate alerts: Don’t alert on every failure, focus on trends
  4. Analyze failures: Use analytics to understand why messages fail
  5. Optimize based on data: Use latency metrics to optimize endpoints

Next Steps

Monitor with confidence using QueueSaaS analytics! 📊