Overview

The AppUptime model tracks the availability and performance of third-party applications. It stores time-series data for monitoring app health and response times.

Schema Structure

{
  packageName: string,      // App identifier
  timestamp: Date,          // Measurement time
  health: 'healthy' | 'degraded' | 'offline',
  onlineStatus: boolean,    // Simple up/down status
  responseTimeMs: number | null  // Response latency
}

Field Purposes

packageName (string)

Identifies which app this metric belongs to:
  • Links to App model via package name
  • Enables per-app monitoring dashboards
  • Used for alerting on specific apps

timestamp (Date)

When this measurement was taken:
  • Time-series data point
  • Enables historical analysis
  • Used for uptime percentage calculations

health (enum)

Overall app health status:
  • healthy: App responding normally
  • degraded: Slow responses or partial failures
  • offline: App not responding at all

onlineStatus (boolean)

Simple binary availability:
  • Quick dashboard indicators
  • Uptime percentage calculations
  • Triggering alerts

responseTimeMs (number | null)

Webhook response latency:
  • Performance monitoring
  • SLA tracking
  • Null when app is offline

Usage Patterns

Health Monitoring

// Check recent app health
const recentHealth = await AppUptime.find({
  packageName: 'com.translator.app',
  timestamp: { $gte: new Date(Date.now() - 24*60*60*1000) }
}).sort({ timestamp: -1 });

Uptime Calculation

// Calculate uptime percentage
const total = await AppUptime.countDocuments({ packageName });
const online = await AppUptime.countDocuments({ 
  packageName, 
  onlineStatus: true 
});
const uptimePercent = (online / total) * 100;

Performance Tracking

// Average response time
const avgResponse = await AppUptime.aggregate([
  { $match: { packageName, responseTimeMs: { $ne: null } } },
  { $group: { 
    _id: null, 
    avgMs: { $avg: '$responseTimeMs' } 
  }}
]);

Data Collection

Uptime records are created by:
  1. Periodic health checks: Every 5 minutes
  2. Webhook failures: When app doesn’t respond
  3. User reports: Manual health updates

Retention

  • Keep high-resolution data for 7 days
  • Aggregate to hourly for 30 days
  • Monthly summaries retained indefinitely

Indexes

  • packageName: Filter by app
  • timestamp: Time-based queries
  • Compound index on both for efficient queries