监视器

其他 社区

技能解读

当前原文的自动摘译,尚未人工审校。

四大支柱

监视所有四个。错过任何一个都会造成盲点。

1. 错误

跟踪未处理的异常、失败的 API 调用和客户端错误。不要等待用户举报。捕获什么 · 如何捕获未处理的异常(服务器) · 全局错误处理程序向错误跟踪服务报告。包括堆栈跟踪和请求上下文。未处理的异常(客户端)· window.onerror 和 onunhandledrejection 连接到错误跟踪。失败的 API 调用 · 记录 4xx 和 5xx 响应以及请求路径、状态和持续时间。

2. 性能

衡量响应时间和用户体验。使用百分位数,而不是平均值。指标 · 目标 · 如何测量 API 响应时间 (p50) · < 200ms · 服务器端计时中间件。 API 响应时间 (p95) · < 500ms · 相同的中间件,跟踪百分位数分布。 API 响应时间 (p99) · < 1000ms · 相同的中间件。如果 p99 出现峰值,请调查异常查询。

3. 可用性

在您的用户之前知道您的服务何时停止。检查内容 · 频率 · 如果健康检查端点发出警报 · 每 30 秒 · 连续两次失败。 SSL 证书到期 · 每天 · 剩余时间少于 14 天。 DNS 解析 · 每 5m · 解析失败或返回意外的 IP。

4. 业务指标

仅凭技术指标并不能告诉您该产品是否有效。指标 · 为何重要 每小时/每天的注册次数 · 立即检测注册流程中断。转化率 · 放弃信号结账或入职问题。关键功能使用 · 确认新功能确实正在使用。

流狐档案 运行与权限由流狐静态检查推断,不代表作者声明或实际测试结果。
领域
通用
作者声明的智能体
未找到明确声明;不据此推断已兼容或已测试
静态检查
94 / 100 · 启发式扫描,不代表运行安全
运行环境证据
未执行;当前没有隔离运行测试证据
作者 / 版本 / 许可证
@kazdenc · MIT
上下文用量评级
低消耗
接入复杂程度
即装即用
是否需要外部接口密钥
不需要
兼容的系统
Windows
运行环境要求
未检出明确要求
检测到的文件与系统行为
  • 只读
  • 允许写入 / 修改
网络行为
仅限本地
安装命令数
无(仅作为资料)

需要注意: 未声明工具权限范围;实际权限由运行环境决定。

作者说明文件(原文) SKILL.md

# Production Monitoring Setup

Set up monitoring for a production application. If a `target` is provided, scope recommendations to that service or feature. Cover all four pillars, then configure health checks, alerts, SLOs, and dashboards.

## The Four Pillars

Monitor all four. Missing any one creates a blind spot.

### 1. Errors

Track unhandled exceptions, failed API calls, and client-side errors. Don't wait for users to report them.

| What to capture | How |
|----------------|-----|
| Unhandled exceptions (server) | Global error handler reports to error tracking service. Include stack trace and request context. |
| Unhandled exceptions (client) | `window.onerror` and `onunhandledrejection` wired to error tracking. |
| Failed API calls | Log 4xx and 5xx responses with request path, status, and duration. |
| Client-side errors | React error boundaries catch render failures. Report with component tree. |

**Tool examples:** Sentry (full stack, source maps, release tracking), LogRocket (session replay + error context).

### 2. Performance

Measure response times and user experience. Use percentiles, not averages.

| Metric | Target | How to measure |
|--------|--------|---------------|
| API response time (p50) | < 200ms | Server-side timing middleware. |
| API response time (p95) | < 500ms | Same middleware, track percentile distribution. |
| API response time (p99) | < 1000ms | Same middleware. If p99 spikes, investigate outlier queries. |
| Largest Contentful Paint | < 2.5s | Real User Monitoring (RUM) or Lighthouse CI. |
| First Input Delay | < 100ms | RUM. |
| Cumulative Layout Shift | < 0.1 | RUM or Lighthouse CI. |

**Tool examples:** Vercel Analytics (zero-config for Next.js), Speedlify (self-hosted Lighthouse tracking).

### 3. Availability

Know when your service is down before your users do.

| What to check | Frequency | Alert if |
|--------------|-----------|----------|
| Health check endpoint | Every 30s | Two consecutive failures. |
| SSL certificate expiry | Daily | Less than 14 days remaining. |
| DNS resolution | Every 5m | Resolution fails or returns unexpected IP. |
| Key third-party services | Every 1m | Dependency returns errors for > 2 minutes. |

**Tool examples:** Better Uptime (status pages + incident management), Checkly (synthetic monitoring with Playwright).

### 4. Business Metrics

Technical metrics alone don't tell you if the product works.

| Metric | Why it matters |
|--------|---------------|
| Signups per hour/day | Detects registration flow breakage immediately. |
| Conversion rate | Drop signals checkout or onboarding issues. |
| Key feature usage | Confirms new features are actually being used. |
| Error rate per user action | Ties technical errors to user impact. |

**Tool examples:** PostHog (open-source product analytics, feature flags, session replay), Mixpanel (funnel and retention analysis).

## Health Check Endpoint

Create a `/api/health` endpoint that verifies real connectivity, not just "the server is running."

```typescript
// app/api/health/route.ts
import { NextResponse } from 'next/server'

export async function GET() {
  const checks: Record<string, 'ok' | 'fail'> = {}

  // Check database connectivity
  try {
    await db.query('SELECT 1')
    checks.database = 'ok'
  } catch {
    checks.database = 'fail'
  }

  // Check external services (cache, queue, etc.)
  try {
    await redis.ping()
    checks.cache = 'ok'
  } catch {
    checks.cache = 'fail'
  }

  const allHealthy = Object.values(checks).every((s) => s === 'ok')

  return NextResponse.json(
    { status: allHealthy ? 'healthy' : 'degraded', checks },
    { status: allHealthy ? 200 : 503 },
  )
}
```

Adapt the checks to the actual services in the stack. Return 503 if any check fails so load balancers and uptime monitors detect it.

## Alerting Strategy

Alert on actionable signals only. Noisy alerts get ignored.

| Signal | Severity | Notification channel | Response time |
|--------|----------|---------------------|---------------|
| Health check down (2+ consecutive) | Critical | PagerDuty / phone call | < 15 minutes |
| Error rate > 5% of requests | Critical | Slack #incidents + PagerDuty | < 15 minutes |
| Error rate > 1% of requests | Warning | Slack #alerts | < 1 hour |
| p95 response time > 1s | Warning | Slack #alerts | < 1 hour |
| SSL cert expiry < 14 days | Info | Slack #ops | < 1 day |
| Disk usage > 80% | Warning | Slack #ops | < 4 hours |
| Deploy completed | Info | Slack #deploys | No response needed |

**Rules for good alerting:**
- Don't alert on single transient errors. Use thresholds and windows (e.g., "error rate > 5% over 5 minutes").
- Every alert must have a clear owner and a documented first-response action.
- Review alert fatigue monthly. If an alert fires > 3 times without action, fix it or remove it.

## SLOs (Service Level Objectives)

Define SLOs for key services. SLOs set expectations; SLIs measure them.

| Service | SLI (what you measure) | SLO (target) | Error budget |
|---------|----------------------|--------------|-------------|
| API availability | % of requests returning non-5xx | 99.9% | 8.7 hours downtime / year |
| API latency | p95 response time | < 500ms | 5% of requests can exceed |
| Web vitals (LCP) | p75 LCP across all pages | < 2.5s | 25% of page loads can exceed |
| Data pipeline freshness | Time since last successful sync | < 15 minutes | 4 allowed SLO violations / month |

**How to use error budgets:**
- When the budget is healthy, ship fast and take calculated risks.
- When the budget is low, freeze non-critical deploys and focus on reliability.
- Track budget burn rate weekly. A sudden spike means something broke.

## Dashboard Essentials

Build a team dashboard with these panels. Keep it to one screen.

| Panel | What it shows | Why |
|-------|--------------|-----|
| Error rate (last 24h) | Errors per minute, with deploy markers | Correlate errors with deploys instantly. |
| Latency trends (last 24h) | p50, p95, p99 lines on one chart | Spot gradual degradation before it becomes critical. |
| Active users (real-time) | Current connected / active users | Context for error rates. 10 errors with 10 users is worse than 10 errors with 10,000. |
| Uptime status | Green/red for each monitored endpoint | Glanceable health. |
| Deploy history | Last 10 deploys with timestamp and author | Quick reference for "what changed?" |
| SLO burn rate | Error budget remaining for the period | Know when to slow down. |

## Incident Response

Use severity levels to set expectations and escalation.

| Level | Definition | Example | Response expectation |
|-------|-----------|---------|---------------------|
| **SEV1** | Service down or major data loss. Most users affected. | API returning 500 for all requests. Payment processing broken. | All hands. Respond in < 15 min. Communicate status every 30 min. |
| **SEV2** | Significant degradation. Some users affected. | Slow response times. One region down. Feature broken for subset of users. | On-call responds in < 30 min. Hourly status updates. |
| **SEV3** | Minor issue. Workaround exists. | Non-critical feature broken. Cosmetic bug in production. | Address within business hours. No status page update needed. |

**For every incident:**
1. Acknowledge the alert and declare severity.
2. Open an incident channel (or thread) for coordination.
3. Mitigate first, investigate second. Get the service back up, then find root cause.
4. Write a brief post-incident review: what happened, why, and what will prevent recurrence.

讨论

基于 GitHub Discussions。登录 GitHub 即可参与讨论、点赞、订阅更新。