Prometheus + Grafana 监控实战:让 LLM 服务可见
目录
为什么 LLM 需要监控
传统服务监控:
- CPU / 内存 / 网络
- 请求延迟 / 错误率
LLM 监控额外需要:
- Token 消耗
- 模型响应延迟
- 幻觉率
- Prompt 长度分布Prometheus 配置
scrape_configs:
- job_name: 'llm-service'
metrics_path: '/metrics'
static_configs:
- targets: ['llm-api:8000']关键指标
# Token 消耗速率
rate(llm_tokens_total[5m])
# 平均响应延迟
rate(llm_request_duration_seconds_sum[5m]) / rate(llm_request_duration_seconds_count[5m])
# 错误率
rate(llm_errors_total[5m]) / rate(llm_requests_total[5m])Grafana Dashboard
常用面板:
- Token 消耗趋势
- P50/P95/P99 延迟分布
- 错误类型分布
- 模型调用成功率
结论
LLM 服务 = 普通服务 + AI 特有指标。
监控要跟上,不然出问题了都不知道。