Files
ljwx-health/backup_docs_20260104_182653/GRAFANA_QUICK_START.md
T
brunoandClaude Sonnet 4.5 8350cd86f3
CI/CD Pipeline / build-push (ljwx-admin) (push) Blocked by required conditions
CI/CD Pipeline / build-push (ljwx-bigscreen) (push) Blocked by required conditions
CI/CD Pipeline / build-push (ljwx-boot) (push) Blocked by required conditions
CI/CD Pipeline / update-deploy (push) Blocked by required conditions
CI/CD Pipeline / security-scan (push) Successful in 52s
CI/CD Pipeline / test-build-boot (push) Successful in 1m52s
CI/CD Pipeline / build-pr (ljwx-admin) (push) Has been skipped
CI/CD Pipeline / build-pr (ljwx-bigscreen) (push) Has been skipped
CI/CD Pipeline / build-pr (ljwx-boot) (push) Has been skipped
CI/CD Pipeline / test-admin (push) Successful in 1m18s
CI/CD Pipeline / test-bigscreen (push) Has been cancelled
docs: 文档结构标准化重构 v1.0
## 重构概览
完成文档标准化重构,建立专业的文档管理体系。

## 核心成果

### 文档精简
- 根目录文档: 57个 → 8个 (-86%)
- README.md: 1844行 → 258行 (-86%)
- 查找时间: 5-10分钟 → <1分钟 (-80%)

### 新增核心文档
- CHANGELOG.md - 版本变更日志
- CONTRIBUTING.md - 贡献指南(代码/提交/文档规范)
- docs/README.md - 文档导航中心(按角色/主题/关键词索引)
- archive/README.md - 归档说明

### 目录架构
- docs/01-getting-started/ - 快速开始
- docs/02-architecture/ - 架构设计
- docs/03-deployment/ - 部署指南(Docker/K8s/GitOps)
- docs/04-operations/ - 运维手册(监控/数据库/故障)
- docs/05-features/ - 功能文档
- docs/06-development/ - 开发指南(后端/前端/API)
- docs/07-compliance/ - 工程规范
- docs/08-reference/ - 参考资料
- archive/2025/ - 历史归档(fixes/implementations/experiments)
- archive/deprecated/ - 已废弃文档

## 文档迁移

### 已迁移文档(44个)
部署文档 → docs/03-deployment/
  - DOCKER_README.md → docker/docker-compose.md
  - DOCKERFILE_OPTIMIZATION_SUMMARY.md → docker/optimization.md
  - GITHUB_SETUP.md → gitops/github-actions.md

运维文档 → docs/04-operations/
  - DATABASE_IMPORT.md → database/data-import.md
  - GRAFANA_QUICK_START.md → monitoring/grafana-quick-start.md

开发文档 → docs/06-development/
  - AI_INTEGRATION_GUIDE.md → ai-integration.md

参考资料 → docs/08-reference/
  - REMOTE_ACCESS.md → remote-access.md

历史文档 → archive/2025/
  - fixes/ - 8个修复文档
  - implementations/ - 10个实施总结
  - experiments/ - 2个实验方案

已废弃 → archive/deprecated/
  - old-quick-starts/ - 5个旧版快速开始指南

### 备份
- backup_docs_20260104_182653/ - 完整备份(57个文件)
- backup_docs_20260104_182705/ - 增量备份(6个文件)

## 技术亮点
- ✅ 自动化迁移脚本(scripts/migrate-docs.sh)
- ✅ 智能文档分类
- ✅ 自动备份机制
- ✅ 文档生命周期管理
- ✅ 多维度导航系统

## 参考规范
- Keep a Changelog (CHANGELOG.md)
- Conventional Commits (提交规范)
- Divio Documentation System (文档分类)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-04 18:31:38 +08:00

5.7 KiB
Raw Blame History

Grafana 快速访问指南

🚀 一键访问 Grafana Dashboard

步骤 1: 端口转发 Grafana

在终端执行:

kubectl port-forward -n monitoring svc/prometheus-grafana 3000:80

保持此终端窗口打开。

步骤 2: 获取 Grafana 密码

在新的终端窗口执行:

kubectl get secret -n monitoring prometheus-grafana \
  -o jsonpath='{.data.admin-password}' | base64 -d && echo

复制输出的密码。

步骤 3: 登录 Grafana

  1. 打开浏览器访问: http://localhost:3000
  2. 登录凭证:
    • 用户名: admin
    • 密码: <步骤 2 获取的密码>

步骤 4: 查看 LJWX Health Dashboard

登录后:

  1. 点击左侧菜单 Dashboards → Browse
  2. 搜索框输入: LJWX
  3. 点击打开: LJWX Health - 服务监控总览

📊 Dashboard 内容

当前可用的监控面板:

1. HTTP 请求速率

  • ljwx-boot: Spring Boot API 请求速率
  • ljwx-bigscreen: Flask Dashboard 请求速率

Prometheus 查询:

sum(rate(http_server_requests_seconds_count{job="ljwx-boot"}[5m]))
sum(rate(flask_http_request_total{job="ljwx-bigscreen"}[5m]))

2. JVM Heap 使用率

  • ljwx-boot Java 应用堆内存使用百分比

Prometheus 查询:

jvm_memory_used_bytes{job="ljwx-boot", area="heap"} /
jvm_memory_max_bytes{job="ljwx-boot", area="heap"} * 100

3. HTTP 请求延迟 P99

  • ljwx-boot API 请求 99 分位延迟(按 URI 分组)

Prometheus 查询:

histogram_quantile(0.99,
  sum(rate(http_server_requests_seconds_bucket{job="ljwx-boot"}[5m]))
  by (uri, le)
)

4. 活跃线程数

  • ljwx-boot JVM 线程池监控

Prometheus 查询:

jvm_threads_live_threads{job="ljwx-boot"}

🔍 使用 Grafana Explore 查询数据

查询 Prometheus 指标

  1. 左侧菜单 → Explore
  2. 数据源选择: Prometheus
  3. 输入查询,例如:
    # 查看所有 ljwx-boot 指标
    {job="ljwx-boot"}
    
    # 查看 bigscreen HTTP 请求
    flask_http_request_total
    
    # JVM 内存使用
    jvm_memory_used_bytes{area="heap"}
    

查询 Loki 日志

  1. 左侧菜单 → Explore
  2. 数据源选择: Loki
  3. 输入查询,例如:
    # 查看 ljwx-bigscreen 日志
    {app="ljwx-bigscreen"}
    
    # 筛选错误日志
    {app="ljwx-bigscreen"} |= "ERROR"
    
    # 解析 JSON 日志字段
    {app="ljwx-bigscreen"} | json | level="ERROR"
    

查询 Tempo 链路

  1. 左侧菜单 → Explore
  2. 数据源选择: Tempo
  3. Search → Service Name: ljwx-bigscreen
  4. 点击 Trace 查看详细调用链

🛠️ 常见问题

Q: 端口转发连接中断怎么办?

A: 重新执行端口转发命令:

kubectl port-forward -n monitoring svc/prometheus-grafana 3000:80

Q: Dashboard 中没有数据显示?

A: 检查时间范围和数据采集状态:

  1. 调整时间范围: Dashboard 右上角选择 "Last 15 minutes" 或 "Last 1 hour"
  2. 验证 Prometheus 抓取:
    # 运行验证脚本
    ./scripts/verify-observability.sh
    
  3. 检查 Pod 状态:
    kubectl get pods -n ljwx-health
    

Q: 如何查看原始 Prometheus 数据?

A: 端口转发 Prometheus 并访问 UI:

kubectl port-forward -n monitoring \
  svc/prometheus-kube-prometheus-prometheus 9090:9090

访问: http://localhost:9090

点击 Status → Targets 搜索 ljwx 查看抓取状态。

Q: 密码忘记或丢失怎么办?

A: 重新执行步骤 2 获取密码,或重置 Grafana admin 密码:

# 获取 Grafana Pod 名称
GRAFANA_POD=$(kubectl get pod -n monitoring -l app.kubernetes.io/name=grafana -o jsonpath='{.items[0].metadata.name}')

# 重置密码为 admin123
kubectl exec -n monitoring $GRAFANA_POD -- grafana-cli admin reset-admin-password admin123

📈 监控最佳实践

1. 设置时间范围自动刷新

  • Dashboard 右上角设置刷新间隔: 30s 或 1m
  • 实时监控应用性能变化

2. 添加告警规则

  • Settings → Alert rules → New alert rule
  • 示例: JVM Heap 使用率 > 85% 时告警

3. 创建自定义 Dashboard

  • Dashboards → New → New Dashboard
  • 添加面板选择 Prometheus 数据源
  • 使用上方提供的 PromQL 查询

4. 导出和分享 Dashboard

  • Dashboard 右上角 Share → Export
  • 保存 JSON 文件用于版本控制

🔗 相关资源

文档:

  • 完整部署状态: OBSERVABILITY_DEPLOYMENT_STATUS.md
  • 验证脚本: scripts/verify-observability.sh
  • 部署脚本: scripts/complete-observability-deployment.sh

命令速查:

# 验证可观测性状态
./scripts/verify-observability.sh

# 查看应用 Pod
kubectl get pods -n ljwx-health

# 查看 ServiceMonitor
kubectl get servicemonitor -n monitoring | grep ljwx

# 查看 Grafana Dashboard ConfigMap
kubectl get configmap -n monitoring ljwx-observability-dashboards

# 测试 ljwx-bigscreen metrics
kubectl logs -n ljwx-health -l app=ljwx-bigscreen | grep "GET /metrics"

# 测试 ljwx-boot metrics
kubectl exec -n ljwx-health -l app=ljwx-boot -- \
  wget -q -O- http://localhost:9998/actuator/prometheus | head

✅ 快速验证清单

访问 Grafana 后验证以下内容:

  • Dashboard "LJWX Health - 服务监控总览" 可访问
  • HTTP 请求速率面板有数据(ljwx-bigscreen 和 ljwx-boot)
  • JVM Heap 使用率面板有数据
  • 时间范围设置为 "Last 15 minutes",数据持续更新
  • Explore → Prometheus 可查询 flask_http_request_total
  • Explore → Loki 可查询 {app="ljwx-bigscreen"}

提示: 如果遇到问题,先运行 ./scripts/verify-observability.sh 检查基础设施状态。

更新时间: 2025-12-22