钉钉 AI 客服:监控告警配置指南

4 阅读1分钟

钉钉 AI 客服:监控告警配置指南

完善的监控告警是保障服务质量的关键。


一、监控指标

1.1 业务指标

指标说明告警阈值
对话量QPS< 1 或 > 100
解决率自动解决占比< 80%
转人工率转人工占比> 20%

1.2 技术指标

指标说明告警阈值
响应时间平均响应> 2s
错误率HTTP 错误> 1%
CPU 使用率服务器负载> 80%
内存使用率内存占用> 90%

二、Prometheus 配置

2.1 安装 Prometheus

brew install prometheus

2.2 配置指标采集

# prometheus.yml
global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'ai-chat'
    static_configs:
      - targets: ['localhost:3000']

2.3 自定义指标

const promClient = require('prom-client');

const chatDuration = new promClient.Histogram({
  name: 'chat_duration_seconds',
  help: 'Chat duration',
  buckets: [0.1, 0.5, 1, 2, 5]
});

const chatTotal = new promClient.Counter({
  name: 'chat_total',
  help: 'Total chats'
});

三、Grafana 可视化

3.1 安装 Grafana

brew install grafana

3.2 配置数据源

  1. 打开 Grafana (http://localhost:3001)
  2. 添加 Prometheus 数据源
  3. 配置 URL: http://localhost:9090

3.3 创建仪表盘

示例面板

  • 对话量趋势图
  • 响应时间分布
  • 错误率变化
  • 资源使用情况

四、告警配置

4.1 告警规则

groups:
  - name: ai-chat
    rules:
      - alert: HighLatency
        expr: chat_duration_seconds > 2
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "响应延迟过高"

      - alert: HighErrorRate
        expr: rate(http_errors[5m]) > 0.01
        for: 2m
        labels:
          severity: critical
        annotations:
          summary: "错误率过高"

4.2 告警通道

钉钉告警

async function sendAlert(message) {
  await fetch(process.env.DINGTALK_WEBHOOK, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      msgtype: 'text',
      text: { content: `[告警] ${message}` }
    })
  });
}

邮件告警

const nodemailer = require('nodemailer');

const transporter = nodemailer.createTransport({
  host: 'smtp.example.com',
  auth: { user: 'alert@example.com', pass: 'xxx' }
});

transporter.sendMail({
  to: 'admin@example.com',
  subject: '[告警] AI 客服异常',
  text: message
});

五、日志监控

5.1 ELK 集成

# filebeat.yml
filebeat.inputs:
  - type: log
    paths:
      - /var/log/ai-chat/*.log

output.elasticsearch:
  hosts: ["localhost:9200"]

5.2 日志分析

  • 错误日志聚合
  • 慢请求追踪
  • 异常模式识别

六、健康检查

6.1 健康检查接口

app.get('/health', (req, res) => {
  const health = {
    status: 'ok',
    uptime: process.uptime(),
    memory: process.memoryUsage(),
    timestamp: Date.now()
  };
  res.json(health);
});

6.2 定时检查

# crontab
*/5 * * * * curl -f http://localhost:3000/health || alert.sh

项目地址:GitHub - dingtalk-connector-pro 有问题欢迎 Issue 或评论区交流