config: 配置Prometheus和Grafana监控

配置内容:
1. 更新Prometheus配置
   - 添加服务标签
   - 优化抓取间隔和超时
   - 配置NATS监控端点
   - 添加外部标签

2. 创建Grafana数据源配置
   - 配置Prometheus数据源
   - 设置为默认数据源
   - 配置查询超时和间隔

3. 创建Grafana仪表板配置
   - 配置自动发现仪表板
   - 支持UI更新

4. 创建监控仪表板
   - taiji-monitoring.json
   - 包含HTTP请求、Agent、工具调用、MCP请求等监控面板
   - 10个监控面板,覆盖系统关键指标

监控指标:
- HTTP请求总数和耗时
- 活跃Agent数
- Agent注册统计
- 工具调用统计
- MCP请求统计
- WebSocket连接数
- 系统连接状态(Redis、NATS、Database)
- 函数注册表大小
- 函数工具调用统计
This commit is contained in:
2025-12-23 07:42:56 +00:00
parent 70608bed16
commit 9b5f60fa91
4 changed files with 313 additions and 13 deletions
+14
View File
@@ -0,0 +1,14 @@
apiVersion: 1
providers:
- name: 'taiji-ai-pad'
orgId: 1
folder: ''
type: file
disableDeletion: false
updateIntervalSeconds: 10
allowUiUpdates: true
options:
path: /etc/grafana/provisioning/dashboards
foldersFromFilesStructure: true
@@ -0,0 +1,236 @@
{
"dashboard": {
"title": "taiji-AI-PAD 系统监控",
"tags": ["taiji", "monitoring", "system"],
"timezone": "browser",
"schemaVersion": 27,
"version": 1,
"refresh": "10s",
"time": {
"from": "now-6h",
"to": "now"
},
"panels": [
{
"id": 1,
"title": "HTTP请求总数",
"type": "graph",
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 0},
"targets": [
{
"expr": "sum(rate(http_requests_total[5m])) by (service)",
"legendFormat": "{{service}}",
"refId": "A"
}
],
"yaxes": [
{"format": "short", "label": "请求/秒"},
{"format": "short"}
],
"xaxis": {"mode": "time"}
},
{
"id": 2,
"title": "HTTP请求耗时",
"type": "graph",
"gridPos": {"h": 8, "w": 12, "x": 12, "y": 0},
"targets": [
{
"expr": "histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket[5m])) by (le, service))",
"legendFormat": "P95 {{service}}",
"refId": "A"
},
{
"expr": "histogram_quantile(0.50, sum(rate(http_request_duration_seconds_bucket[5m])) by (le, service))",
"legendFormat": "P50 {{service}}",
"refId": "B"
}
],
"yaxes": [
{"format": "s", "label": "耗时"},
{"format": "short"}
],
"xaxis": {"mode": "time"}
},
{
"id": 3,
"title": "活跃Agent数",
"type": "stat",
"gridPos": {"h": 4, "w": 6, "x": 0, "y": 8},
"targets": [
{
"expr": "agents_active_websockets",
"legendFormat": "活跃Agent",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"color": {"mode": "thresholds"},
"thresholds": {
"mode": "absolute",
"steps": [
{"value": null, "color": "green"},
{"value": 10, "color": "yellow"},
{"value": 50, "color": "red"}
]
}
}
}
},
{
"id": 4,
"title": "Agent注册总数",
"type": "stat",
"gridPos": {"h": 4, "w": 6, "x": 6, "y": 8},
"targets": [
{
"expr": "sum(increase(agents_registered_total[1h]))",
"legendFormat": "注册数",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"color": {"mode": "palette-classic"}
}
}
},
{
"id": 5,
"title": "工具调用总数",
"type": "graph",
"gridPos": {"h": 8, "w": 12, "x": 12, "y": 8},
"targets": [
{
"expr": "sum(rate(tool_calls_total[5m])) by (tool_type, status)",
"legendFormat": "{{tool_type}} - {{status}}",
"refId": "A"
}
],
"yaxes": [
{"format": "short", "label": "调用/秒"},
{"format": "short"}
],
"xaxis": {"mode": "time"}
},
{
"id": 6,
"title": "MCP请求总数",
"type": "graph",
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 12},
"targets": [
{
"expr": "sum(rate(mcp_requests_total[5m])) by (method, status)",
"legendFormat": "{{method}} - {{status}}",
"refId": "A"
}
],
"yaxes": [
{"format": "short", "label": "请求/秒"},
{"format": "short"}
],
"xaxis": {"mode": "time"}
},
{
"id": 7,
"title": "WebSocket连接数",
"type": "stat",
"gridPos": {"h": 4, "w": 6, "x": 12, "y": 12},
"targets": [
{
"expr": "websocket_connections_active",
"legendFormat": "活跃连接",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"color": {"mode": "thresholds"},
"thresholds": {
"mode": "absolute",
"steps": [
{"value": null, "color": "blue"},
{"value": 10, "color": "green"},
{"value": 50, "color": "yellow"},
{"value": 100, "color": "red"}
]
}
}
}
},
{
"id": 8,
"title": "系统连接状态",
"type": "stat",
"gridPos": {"h": 4, "w": 6, "x": 18, "y": 12},
"targets": [
{
"expr": "redis_connections",
"legendFormat": "Redis",
"refId": "A"
},
{
"expr": "nats_connections",
"legendFormat": "NATS",
"refId": "B"
},
{
"expr": "database_connections",
"legendFormat": "Database",
"refId": "C"
}
],
"fieldConfig": {
"defaults": {
"color": {"mode": "thresholds"},
"thresholds": {
"mode": "absolute",
"steps": [
{"value": null, "color": "red"},
{"value": 1, "color": "green"}
]
}
}
}
},
{
"id": 9,
"title": "函数注册表大小",
"type": "stat",
"gridPos": {"h": 4, "w": 6, "x": 0, "y": 16},
"targets": [
{
"expr": "function_registry_size",
"legendFormat": "函数数",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"color": {"mode": "palette-classic"}
}
}
},
{
"id": 10,
"title": "函数工具调用",
"type": "graph",
"gridPos": {"h": 8, "w": 18, "x": 6, "y": 16},
"targets": [
{
"expr": "sum(rate(function_tool_calls_total[5m])) by (function_name, status)",
"legendFormat": "{{function_name}} - {{status}}",
"refId": "A"
}
],
"yaxes": [
{"format": "short", "label": "调用/秒"},
{"format": "short"}
],
"xaxis": {"mode": "time"}
}
]
}
}
+15
View File
@@ -0,0 +1,15 @@
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
editable: true
jsonData:
timeInterval: "15s"
httpMethod: "POST"
queryTimeout: "60s"
secureJsonData: {}
+48 -13
View File
@@ -1,43 +1,78 @@
global: global:
scrape_interval: 15s scrape_interval: 15s
evaluation_interval: 15s evaluation_interval: 15s
external_labels:
cluster: 'taiji-ai-pad'
environment: 'production'
# 告警规则配置(可选,未来可添加)
# rule_files:
# - "alert_rules.yml"
# Alertmanager配置(可选,未来可添加)
# alerting:
# alertmanagers:
# - static_configs:
# - targets: ['alertmanager:9093']
scrape_configs: scrape_configs:
# MCP Server # MCP Server
- job_name: 'mcp-server' - job_name: 'mcp-server'
static_configs: static_configs:
- targets: ['mcp-server:8000'] - targets: ['mcp-server:8000']
labels:
service: 'mcp-server'
component: 'api'
metrics_path: '/metrics' metrics_path: '/metrics'
scrape_interval: 10s scrape_interval: 10s
scrape_timeout: 5s
# Data Ingestion Service # Data Ingestion Service
- job_name: 'data-ingestion' - job_name: 'data-ingestion'
static_configs: static_configs:
- targets: ['data-ingestion:8000'] - targets: ['data-ingestion:8000']
labels:
service: 'data-ingestion'
component: 'api'
metrics_path: '/metrics' metrics_path: '/metrics'
scrape_interval: 10s scrape_interval: 10s
scrape_timeout: 5s
# LiteLLM Gateway # LiteLLM Gateway (如果有metrics端点)
- job_name: 'litellm-gateway' - job_name: 'litellm-gateway'
static_configs: static_configs:
- targets: ['litellm-gateway:4001'] - targets: ['litellm-gateway:4000']
labels:
service: 'litellm-gateway'
component: 'gateway'
metrics_path: '/metrics' metrics_path: '/metrics'
scrape_interval: 10s scrape_interval: 10s
scrape_timeout: 5s
# 如果端点不存在,Prometheus会记录错误但不会影响其他服务
# PostgreSQL # PostgreSQL (需要postgres_exporter,当前未部署)
- job_name: 'postgres' # - job_name: 'postgres'
static_configs: # static_configs:
- targets: ['postgres:5432'] # - targets: ['postgres-exporter:9187']
scrape_interval: 30s # labels:
# service: 'postgres'
# component: 'database'
# Redis # Redis (需要redis_exporter,当前未部署)
- job_name: 'redis' # - job_name: 'redis'
static_configs: # static_configs:
- targets: ['redis:6379'] # - targets: ['redis-exporter:9121']
scrape_interval: 30s # labels:
# service: 'redis'
# component: 'cache'
# NATS # NATS (NATS自带监控端点)
- job_name: 'nats' - job_name: 'nats'
static_configs: static_configs:
- targets: ['nats:8222'] - targets: ['nats:8222']
labels:
service: 'nats'
component: 'message-queue'
metrics_path: '/varz'
scrape_interval: 30s scrape_interval: 30s
scrape_timeout: 10s