| name | kong-gateway-analyzer |
| description | Kong 网关日志查询分析技能。
触发场景:
- 查看 Kong 访问日志、排查 API 错误/超时
- 分析域名/路由/服务的流量和错误
- 分析请求延迟和性能瓶颈
反馈机制: 支持用户纠正和补充,持续改进
|
Kong Gateway Analyzer
Kong 网关日志查询分析技能。脚本获取数据,Agent 负责分析。
核心脚本
query_kong_logs.sh - 通用日志查询
scripts/query_kong_logs.sh -c prod-cluster -H api.example.com -l 100
scripts/query_kong_logs.sh -c prod-cluster --status 5xx -t 1h
scripts/query_kong_logs.sh -c prod-cluster --slow 1000 -t 15m --analyze
关键参数:
| 参数 | 说明 | 默认 |
|---|
-c | 集群名称 (必需) | - |
-H | 域名过滤 | - |
-t | 时间范围 (5m/1h/24h) | 5m |
--status | 状态码 (200/4xx/5xx) | - |
--slow | 慢请求阈值(ms) | - |
--analyze | 统计分析模式 | false |
analyze_traffic.sh - 流量分析
scripts/analyze_traffic.sh -c prod-cluster -H api.example.com -t 10m
返回:QPS、状态码分布、延迟统计(p50/p95/p99)、Top URI、慢请求
diagnose_5xx_errors.sh - 5xx 错误诊断
scripts/diagnose_5xx_errors.sh -c prod-cluster -t 10m
scripts/diagnose_5xx_errors.sh -c prod-cluster -H api.example.com -t 1h
返回:错误总数、状态码分类、按上游/URI/域名分组、时间分布、样本
diagnose_slow_requests.sh - 慢请求诊断
scripts/diagnose_slow_requests.sh -c prod-cluster --slow 1000 -t 10m
scripts/diagnose_slow_requests.sh -c prod-cluster -H api.example.com --slow 500
返回:慢请求数量占比、延迟分布、按上游/URI 分组、Top 20 慢请求、延迟来源分析
关键阈值
| 指标 | 正常 | 警告 | 严重 |
|---|
| 总响应时间 | <500ms | 500ms-2s | >2s |
| 上游响应时间 | <200ms | 200ms-1s | >1s |
| Kong 处理延迟 | <10ms | 10ms-50ms | >50ms |
| 5xx 错误率 | <0.1% | 0.1%-1% | >1% |
故障排查
5xx 错误排查
1. 诊断错误分布
scripts/diagnose_5xx_errors.sh -c prod-cluster -t 1h
2. 根据状态码分支
├─ 502 → 检查上游服务状态
├─ 504 → 使用慢请求诊断
└─ 500 → 检查上游服务日志
延迟问题排查
1. 诊断慢请求
scripts/diagnose_slow_requests.sh -c prod-cluster --slow 1000
2. 分析延迟来源
├─ upstream_caused_percent > 70% → 优化上游服务
└─ kong_time 占比高 → 检查 Kong 资源/插件
环境配置
VictoriaLogs API: https://victorialogs.example.com
集群标签:
| 名称 | 标签 |
|---|
| 生产 | prod-cluster |
| 计算 | compute-cluster |
| 腾讯云 | tencent-cluster |
| 阿里云 | aliyun-cluster |
反馈与改进
支持持续改进。发现问题请直接告知:
| 类型 | 示例 |
|---|
| 纠正 | "状态码字段应该是 status" |
| 补充 | "缺少 SSL 握手失败的错误模式" |
| 优化 | "排查流程需要补充..." |