mgmt/docs/cleanup-strategy.md

5.1 KiB
Raw Blame History

🧹 基于Git修改频率的智能清理策略

🎯 清理理论

核心原理:

  • 修改频率高 = 活跃文件,需要保留
  • 修改频率低 = 可能是垃圾文件,可以清理
  • 混乱度低 = 角落里的垃圾,优先清理

清理优先级:

  1. 高优先级清理 - 修改频率低 + 混乱度低
  2. 中优先级清理 - 修改频率低 + 混乱度高
  3. 低优先级清理 - 修改频率高 + 混乱度低
  4. 保留 - 修改频率高 + 混乱度高

📊 当前项目文件分析

🔴 高优先级清理目标 (修改频率低 + 混乱度低)

Dashboard JSON文件 (8:46批量创建之后未修改)

# 这些是测试/实验文件,可以清理
/root/mgmt/final-working-dashboard.json
/root/mgmt/fixed-nomad-dashboard.json
/root/mgmt/health-dashboard.json
/root/mgmt/logs-dashboard.json
/root/mgmt/nomad-cluster-dashboard.json
/root/mgmt/simple-nomad-dashboard.json
/root/mgmt/test-simple-dashboard.json
/root/mgmt/working-dashboard.json
/root/mgmt/working-nomad-dashboard.json

临时配置文件 (8:46创建之后未修改)

# 这些是实验配置,可以清理
/root/mgmt/promtail-config.yaml
/root/mgmt/promtail-simple.yaml
/root/mgmt/promtail-working.yaml

演示文档 (9:03创建一次性使用)

# 演示文档,可以清理
/root/mgmt/metrics-correlation-demo.md
/root/mgmt/heatmap-demo-instructions.md

🟡 中优先级清理目标 (修改频率低 + 混乱度高)

安全文档 (可能重复)

# 检查是否有重复
/root/mgmt/security/grafana-api-keys.md  # 可能被 grafana-api-credentials.md 替代

🟢 保留文件 (修改频率高 + 重要)

核心配置文件

# 这些是核心文件,必须保留
/root/mgmt/README.md                    # 主文档,频繁修改
/root/mgmt/PROJECT-COMPLETION-SUMMARY.md # 项目总结
/root/mgmt/deploy-promtail.yml          # 部署脚本
/root/mgmt/loki-heatmap-demo.json       # 最终Dashboard配置
/root/mgmt/promtail-journal.yaml        # 最终配置模板

基础设施配置

# 这些是生产配置,必须保留
/root/mgmt/infrastructure/monitor/monitoring-stack.nomad
/root/mgmt/infrastructure/monitor/prometheus.yml
/root/mgmt/infrastructure/monitor/configs/promtail/promtail-config.yaml

🧹 清理执行计划

第一阶段:清理测试文件

# 清理Dashboard测试文件
rm -f /root/mgmt/*-dashboard.json
rm -f /root/mgmt/final-working-dashboard.json
rm -f /root/mgmt/fixed-nomad-dashboard.json
rm -f /root/mgmt/health-dashboard.json
rm -f /root/mgmt/logs-dashboard.json
rm -f /root/mgmt/nomad-cluster-dashboard.json
rm -f /root/mgmt/simple-nomad-dashboard.json
rm -f /root/mgmt/test-simple-dashboard.json
rm -f /root/mgmt/working-dashboard.json
rm -f /root/mgmt/working-nomad-dashboard.json

第二阶段:清理临时配置

# 清理临时配置文件
rm -f /root/mgmt/promtail-config.yaml
rm -f /root/mgmt/promtail-simple.yaml
rm -f /root/mgmt/promtail-working.yaml

第三阶段:清理演示文档

# 清理演示文档
rm -f /root/mgmt/metrics-correlation-demo.md
rm -f /root/mgmt/heatmap-demo-instructions.md

第四阶段:检查重复文件

# 检查安全文档是否重复
ls -la /root/mgmt/security/
# 如果 grafana-api-keys.md 被 grafana-api-credentials.md 替代,则删除

📈 清理效果预期

清理前:

  • 总文件数161个配置文件
  • 根目录文件:~20个
  • 混乱度:高(大量测试文件)

清理后:

  • 预计减少:~15个文件
  • 根目录文件:~5个核心文件
  • 混乱度:低(只保留生产文件)

🎯 清理原则

保留标准:

  1. 修改频率高 - 最近有修改的文件
  2. 功能重要 - 核心配置文件
  3. 生产使用 - 实际在生产环境使用的文件
  4. 文档完整 - 重要的文档文件

清理标准:

  1. 修改频率低 - 创建后未再修改
  2. 功能重复 - 被其他文件替代
  3. 测试性质 - 实验/测试文件
  4. 临时性质 - 一次性使用的文件

🔍 清理验证

清理后检查:

# 检查核心功能是否完整
ls -la /root/mgmt/README.md
ls -la /root/mgmt/deploy-promtail.yml
ls -la /root/mgmt/loki-heatmap-demo.json
ls -la /root/mgmt/infrastructure/monitor/

# 检查安全配置是否完整
ls -la /root/mgmt/security/

功能测试:

# 测试部署脚本
ansible-playbook -i inventory deploy-promtail.yml --check

# 测试Dashboard导入
curl -X POST "http://influxdb.tailnet-68f9.ts.net:3000/api/dashboards/db" \
  -H "Authorization: Bearer glsa_Lu2RW7yPMmCtYrvbZLNJyOI3yE1LOH5S_629de57b" \
  -d @loki-heatmap-demo.json

🎉 清理目标

通过基于修改频率的智能清理,实现:

  • 减少混乱度 - 只保留核心文件
  • 提高可维护性 - 清晰的文件结构
  • 降低认知负担 - 减少无关文件干扰
  • 保持功能完整 - 不影响核心功能

这就是基于Git修改频率的智能清理策略 🚀