# 轻量级监控配置指南 ## 📋 监控架构 ### 核心组件 1. **Sentry** - 错误监控和性能追踪 2. **UptimeRobot** - 外部可用性监控 3. **Google Analytics** - 用户行为和访问统计 4. **健康检查API** - 内部服务状态 5. **邮件告警** - 关键问题通知 ## 🔧 配置步骤 ### 1. Sentry 错误监控(已完成) Sentry 已经集成在项目中,配置文件: - `src/lib/sentry.ts` - Sentry 初始化 - `.env.production` - Sentry DSN 配置 **功能:** - JavaScript 错误捕获 - 性能监控 - 用户会话回放 - 错误告警 ### 2. UptimeRobot 可用性监控 #### 注册和配置 1. 访问 https://uptimerobot.com/ 2. 注册免费账号 3. 创建新的 Monitor: - **Monitor Type**: HTTP(s) - **URL**: https://www.novalon.cn - **Monitoring Interval**: 5 minutes - **Alert Contacts**: ops@novalon.cn #### 配置告警 在 UptimeRobot 中设置: - **Down Alert**: 网站不可用时发送邮件 - **Up Alert**: 网站恢复时发送邮件 - **SSL Expiry**: SSL 证书过期提醒 #### 高级配置 ```yaml # 推荐的监控端点 - 主页: https://www.novalon.cn - 健康检查: https://www.novalon.cn/api/health - 管理后台: https://www.novalon.cn/admin ``` ### 3. Google Analytics 访问统计 #### 获取跟踪 ID 1. 访问 https://analytics.google.com/ 2. 创建新的 GA4 属性 3. 复制测量 ID(格式:G-XXXXXXXXXX) #### 配置 Next.js 更新 `.env.production`: ```env NEXT_PUBLIC_GA_MEASUREMENT_ID=G-XXXXXXXXXX ``` #### 集成到应用 创建 `src/lib/analytics.ts`: ```typescript export const GA_MEASUREMENT_ID = process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID; export const pageview = (url: string) => { if (typeof window !== "undefined" && GA_MEASUREMENT_ID) { window.gtag("config", GA_MEASUREMENT_ID, { page_path: url, }); } }; export const event = (action: string, category: string, label?: string) => { if (typeof window !== "undefined" && GA_MEASUREMENT_ID) { window.gtag("event", action, { event_category: category, event_label: label, }); } }; ``` 在 `src/app/layout.tsx` 中添加: ```typescript import Script from 'next/script'; export default function RootLayout({ children }: { children: React.ReactNode }) { return ( {process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID && (