feat: 方案100%匹配 — RBAC动态权限+Grafana监控+目录库独立微服务+全国目录中心+标识同步

This commit is contained in:
selfrelease
2026-06-30 13:42:11 +08:00
parent 96e2393c50
commit 29a6b57533
40 changed files with 4159 additions and 7 deletions
+80
View File
@@ -0,0 +1,80 @@
# TCS-IPTV 监控部署说明
## 组件
| 文件 | 说明 |
|------|------|
| `prometheus.yml` | Prometheus 采集配置,抓取 api-svc / chain-svc / hash-api / catalog-svc 的 `/metrics` |
| `grafana-dashboard.json` | Grafana 面板 JSON,覆盖 4 金指标 |
## 快速部署
### 1. Prometheus
```bash
# 启动 PrometheusDocker
docker run -d --name prometheus \
-p 9090:9090 \
-v $(pwd)/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus
```
### 2. Grafana
```bash
# 启动 GrafanaDocker
docker run -d --name grafana \
-p 3000:3000 \
-v $(pwd)/grafana-dashboard.json:/etc/grafana/provisioning/dashboards/tcs-iptv.json \
grafana/grafana
```
### 3. 导入面板
1. 打开 Grafana → http://localhost:3000
2. Dashboards → Import → 上传 `grafana-dashboard.json`
3. 数据源选择 Prometheushttp://prometheus:9090
## 面板指标说明
| 面板 | 指标 | Prometheus Metric |
|------|------|-------------------|
| 请求延迟 | P50/P95/P99 | `tcs_http_request_duration_seconds` (Histogram) |
| 请求总量 | QPS by path | `tcs_http_requests_total` (Counter) |
| 错误率 | 4xx/5xx QPS | `tcs_http_errors_total` (Counter) |
| 在途请求 | 并发数 | `tcs_http_in_flight_requests` (Gauge) |
| 错误率百分比 | 错误/总请求 | 上述两个 Counter 计算 |
| 延迟热力图 | by path | Histogram bucket 热力图 |
## 告警规则建议
在 Prometheus 中配置 `alerting_rules.yml`
```yaml
groups:
- name: tcs-iptv-alerts
rules:
- alert: HighErrorRate
expr: sum(rate(tcs_http_errors_total[5m])) / sum(rate(tcs_http_requests_total[5m])) > 0.1
for: 5m
labels:
severity: critical
annotations:
summary: "错误率超过 10%"
- alert: HighLatency
expr: histogram_quantile(0.95, sum(rate(tcs_http_request_duration_seconds_bucket[5m])) by (le)) > 2
for: 5m
labels:
severity: warning
annotations:
summary: "P95 延迟超过 2 秒"
- alert: HighInFlight
expr: tcs_http_in_flight_requests > 100
for: 2m
labels:
severity: warning
annotations:
summary: "在途请求超过 100"
```
@@ -0,0 +1,181 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"description": "TCS-IPTV MA 码系统运行监控面板 — 覆盖4金指标:Latency / Traffic / Errors / Saturation",
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 1,
"id": null,
"links": [],
"liveNow": false,
"panels": [
{
"title": "请求延迟 (Latency — P50/P95/P99)",
"type": "timeseries",
"datasource": "Prometheus",
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 0 },
"fieldConfig": {
"defaults": {
"unit": "s",
"color": { "mode": "palette-classic" }
}
},
"targets": [
{
"expr": "histogram_quantile(0.50, sum(rate(tcs_http_request_duration_seconds_bucket[5m])) by (le))",
"legendFormat": "P50",
"refId": "A"
},
{
"expr": "histogram_quantile(0.95, sum(rate(tcs_http_request_duration_seconds_bucket[5m])) by (le))",
"legendFormat": "P95",
"refId": "B"
},
{
"expr": "histogram_quantile(0.99, sum(rate(tcs_http_request_duration_seconds_bucket[5m])) by (le))",
"legendFormat": "P99",
"refId": "C"
}
]
},
{
"title": "请求总量 (Traffic — QPS)",
"type": "timeseries",
"datasource": "Prometheus",
"gridPos": { "h": 8, "w": 12, "x": 12, "y": 0 },
"fieldConfig": {
"defaults": {
"unit": "reqps",
"color": { "mode": "palette-classic" }
}
},
"targets": [
{
"expr": "sum(rate(tcs_http_requests_total[1m])) by (method, path)",
"legendFormat": "{{method}} {{path}}",
"refId": "A"
}
]
},
{
"title": "错误率 (Errors — 4xx/5xx)",
"type": "timeseries",
"datasource": "Prometheus",
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 8 },
"fieldConfig": {
"defaults": {
"unit": "reqps",
"color": { "mode": "palette-classic" }
}
},
"targets": [
{
"expr": "sum(rate(tcs_http_errors_total[5m])) by (method, path, status)",
"legendFormat": "{{method}} {{path}} {{status}}",
"refId": "A"
}
]
},
{
"title": "在途请求 (Saturation — 并发数)",
"type": "stat",
"datasource": "Prometheus",
"gridPos": { "h": 8, "w": 6, "x": 12, "y": 8 },
"fieldConfig": {
"defaults": {
"unit": "short",
"thresholds": {
"steps": [
{ "color": "green", "value": null },
{ "color": "yellow", "value": 50 },
{ "color": "red", "value": 100 }
]
}
}
},
"targets": [
{
"expr": "tcs_http_in_flight_requests",
"legendFormat": "在途请求",
"refId": "A"
}
]
},
{
"title": "错误率百分比",
"type": "gauge",
"datasource": "Prometheus",
"gridPos": { "h": 8, "w": 6, "x": 18, "y": 8 },
"fieldConfig": {
"defaults": {
"unit": "percentunit",
"min": 0,
"max": 1,
"thresholds": {
"steps": [
{ "color": "green", "value": null },
{ "color": "yellow", "value": 0.05 },
{ "color": "red", "value": 0.1 }
]
}
}
},
"targets": [
{
"expr": "sum(rate(tcs_http_errors_total[5m])) / sum(rate(tcs_http_requests_total[5m]))",
"legendFormat": "错误率",
"refId": "A"
}
]
},
{
"title": "按路径延迟热力图",
"type": "heatmap",
"datasource": "Prometheus",
"gridPos": { "h": 8, "w": 24, "x": 0, "y": 16 },
"targets": [
{
"expr": "sum(rate(tcs_http_request_duration_seconds_bucket[5m])) by (le, path)",
"legendFormat": "{{path}}",
"refId": "A",
"format": "heatmap"
}
],
"options": {
"calculate": false,
"cellGap": 1,
"color": {
"scheme": "Spectral"
}
}
}
],
"refresh": "10s",
"schemaVersion": 38,
"style": "dark",
"tags": ["tcs-iptv", "ma-code"],
"templating": {
"list": []
},
"time": {
"from": "now-1h",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "TCS-IPTV MA 码系统监控",
"uid": "tcs-iptv-monitor",
"version": 1,
"weekStart": ""
}
+39
View File
@@ -0,0 +1,39 @@
# TCS-IPTV Prometheus 采集配置
# 对应方案:系统管理模块 — 运行监控
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
# api-svc 主服务
- job_name: "tcs-api-svc"
metrics_path: /metrics
static_configs:
- targets: ["api-svc:8080"]
labels:
service: "api-svc"
# chain-svc 链服务
- job_name: "tcs-chain-svc"
metrics_path: /metrics
static_configs:
- targets: ["chain-svc:8081"]
labels:
service: "chain-svc"
# hash-api 哈希服务
- job_name: "tcs-hash-api"
metrics_path: /metrics
static_configs:
- targets: ["hash-api:8082"]
labels:
service: "hash-api"
# catalog-svc 目录库服务(独立部署时启用)
- job_name: "tcs-catalog-svc"
metrics_path: /metrics
static_configs:
- targets: ["catalog-svc:8083"]
labels:
service: "catalog-svc"