packages/super-sync-server/scripts/MONITORING-README.md
Comprehensive suite of tools for monitoring and analyzing SuperSync server storage, operations, and user patterns.
# Run all monitoring checks
npm run monitor:all
# Run quick health check (skip deep analysis)
npm run monitor:all:quick
# Save full report to file
npm run monitor:all:save
# Focus on specific user
npm run monitor:all -- --user 29
monitor.ts)General server health and user storage tracking.
# System vitals (CPU, memory, disk, DB)
npm run monitor:dev -- stats
# Top 20 users by storage
npm run monitor:dev -- usage
# View usage history/trends
npm run monitor:dev -- usage-history --tail 20
# Active user counts and recent activity
npm run monitor:dev -- active-users
npm run monitor:dev -- active-users --threshold 5 --limit 50
# Recent operations analysis
npm run monitor:dev -- ops --tail 100
npm run monitor:dev -- ops --user 29
# View server logs
npm run monitor:dev -- logs --tail 200
npm run monitor:dev -- logs --search "error"
npm run monitor:dev -- logs --error
analyze-storage.ts)Deep-dive analysis for investigating storage anomalies and patterns.
# Analyze operation size distribution
npm run analyze-storage -- operation-sizes
npm run analyze-storage -- operation-sizes --user 29
# Temporal patterns (bursts, daily/hourly trends)
npm run analyze-storage -- operation-timeline
npm run analyze-storage -- operation-timeline --user 29
# Breakdown by operation/entity types
npm run analyze-storage -- operation-types
npm run analyze-storage -- operation-types --user 29
# Find largest operations
npm run analyze-storage -- large-ops --limit 50
# Detect rapid-fire/sync loops (>5 ops/second by default)
npm run analyze-storage -- rapid-fire --threshold 10
# Analyze snapshot patterns
npm run analyze-storage -- snapshot-analysis
# Complete deep-dive for one user
npm run analyze-storage -- user-deep-dive --user 27
# Export operations to JSON for external analysis
npm run analyze-storage -- export-ops --user 29 --limit 1000
# Compare two users
npm run analyze-storage -- compare-users 27 29
run-all-monitoring.ts)Runs all monitoring and analysis tools in sequence.
# Run everything
npm run monitor:all
# Quick mode (skip deep analysis)
npm run monitor:all:quick
# Save to timestamped file in monitoring-reports/
npm run monitor:all:save
# Focus on specific user
npm run monitor:all -- --user 29 --save
npm run monitor:all:quick
Review:
User has unusually high storage (e.g., User #29 with 28k operations):
# Step 1: Get complete picture
npm run analyze-storage -- user-deep-dive --user 29
# Step 2: Check for rapid-fire patterns
npm run analyze-storage -- rapid-fire --threshold 3
# Step 3: Export for detailed analysis
npm run analyze-storage -- export-ops --user 29 --limit 5000
User has unusually large operations (e.g., User #27 with 54KB avg):
# Step 1: Find largest operations
npm run analyze-storage -- large-ops --limit 20
# Step 2: Analyze that user's patterns
npm run analyze-storage -- user-deep-dive --user 27
# Step 3: Compare with "normal" user
npm run analyze-storage -- compare-users 27 29
Suspect a sync loop or rapid-fire operations:
# Step 1: Detect rapid-fire (lower threshold)
npm run analyze-storage -- rapid-fire --threshold 3
# Step 2: Timeline analysis for affected user
npm run analyze-storage -- operation-timeline --user 29
# Step 3: Check operation types
npm run analyze-storage -- operation-types --user 29
Generate comprehensive monthly storage report:
# Generate and save full report
npm run monitor:all:save
# Review trends
npm run monitor:dev -- usage-history --tail 30
logs/usage-history.jsonl - Appended by monitor.ts usageanalysis-output/ - JSON exports from export-opsmonitoring-reports/ - Timestamped reports from monitor:all --savePossible causes:
Investigate: user-deep-dive, operation-timeline, rapid-fire
Possible causes:
Investigate: large-ops, operation-types, compare with normal users
Possible causes:
Investigate: rapid-fire, operation-timeline, per-device breakdown in user-deep-dive
Possible causes:
Investigate: snapshot-analysis, correlation with op count
You can set up cron jobs for regular monitoring:
# Daily health check at 2 AM
0 2 * * * cd /path/to/super-sync-server && npm run monitor:all:quick >> logs/daily-check.log 2>&1
# Weekly full report every Sunday at 3 AM
0 3 * * 0 cd /path/to/super-sync-server && npm run monitor:all:save
# Hourly rapid-fire detection
0 * * * * cd /path/to/super-sync-server && npm run analyze-storage -- rapid-fire >> logs/rapid-fire.log 2>&1
monitor:all:quick first, then drill down with specific commands--save or redirect output to filescompare-users to understand what's "normal" vs anomalousexport-ops to get raw data for custom analysisusage-history checks reveal growth patternsnpm install -g tsxnpx tsx scripts/analyze-storage.ts ...--limit valuesNODE_OPTIONS=--max-old-space-size=4096 npm run ...To add new analysis commands:
scripts/analyze-storage.tsmain() switchgetMonitoringCommands() in run-all-monitoring.ts if it should run in full suiteQuestions or issues? File an issue or check the main SuperSync documentation.