Application health monitoring and performance tracking
{ packageName: string, // App identifier timestamp: Date, // Measurement time health: 'healthy' | 'degraded' | 'offline', onlineStatus: boolean, // Simple up/down status responseTimeMs: number | null // Response latency }
// 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 });
// Calculate uptime percentage const total = await AppUptime.countDocuments({ packageName }); const online = await AppUptime.countDocuments({ packageName, onlineStatus: true }); const uptimePercent = (online / total) * 100;
// Average response time const avgResponse = await AppUptime.aggregate([ { $match: { packageName, responseTimeMs: { $ne: null } } }, { $group: { _id: null, avgMs: { $avg: '$responseTimeMs' } }} ]);