版本: v2.1.0
功能: 基于阿里云账单CSV,分析最近6个月折扣变化趋势
更新日期: 2025-12
CloudLens 折扣趋势分析功能可以帮助您:
✅ 追踪折扣变化 - 分析最近6个月的折扣率变化趋势
✅ 多维度分析 - 支持按产品、合同、实例维度分析
✅ 商务决策支持 - 识别折扣下降的产品,及时与商务沟通
✅ 成本优化 - 找出折扣最高的资源,优化采购策略
将账单CSV文件放在以账号ID命名的目录中:
cloudlens/
└── 1844634015852583-账号名称/
├── 1844634015852583-账号-202507-res_consume_detail_1.csv
├── 1844634015852583-账号-202508-res_consume_detail_1.csv
├── 1844634015852583-账号-202509-res_consume_detail_1.csv
└── ...
提示: 账单文件可以分多个文件(如 detail_1.csv, detail_2.csv…),分析器会自动合并。
# 自动查找项目根目录下的账单目录
./cl analyze discount
# 指定账单目录
./cl analyze discount --bill-dir ./1844634015852583-ydzn
# 分析最近12个月
./cl analyze discount --months 12
# 导出HTML报告(默认)
./cl analyze discount --export
# 导出Excel报告
./cl analyze discount --export --format excel
# 导出JSON数据
./cl analyze discount --export --format json
按产品聚合折扣数据:
示例输出:
产品 累计折扣 平均折扣率 趋势
云消息队列 Kafka 版 ¥150,234.56 52.3% 📈 上升
云数据库 RDS ¥89,123.45 48.7% ➡️ 平稳
云服务器 ECS ¥67,890.12 35.2% 📉 下降
按商务合同聚合:
应用场景: 评估商务合同的实际折扣效果,为续签谈判提供数据支持。
分析单个实例的折扣情况:
应用场景: 识别高价值资源,优化续费和采购策略。
需求: 年度商务合同即将到期,需要评估当前折扣水平,为续签谈判准备数据。
操作步骤:
# 1. 分析最近6个月折扣趋势
./cl analyze discount --export
# 2. 查看报告(自动打开HTML)
# 关注以下指标:
# - 平均折扣率是否达到预期
# - 哪些产品折扣率最高/最低
# - 折扣率是否有下降趋势
决策依据:
需求: 识别折扣率较低的资源,优化采购策略。
操作步骤:
# 分析折扣趋势
./cl analyze discount --export --format excel
分析要点:
优化建议:
需求: 每月跟踪折扣变化,及时发现异常。
操作步骤:
# 设置定时任务(每月1号执行)
# crontab -e
0 9 1 * * cd /path/to/cloudlens && ./cl analyze discount --export
监控指标:
分析器会读取以下关键字段:
| 字段名 | 说明 | 用途 |
|---|---|---|
| 账期 | 账单月份(yyyy-MM) | 时间维度聚合 |
| 产品Code | 产品代码 | 产品维度分析 |
| 产品 | 产品名称 | 显示用 |
| 实例ID | 资源实例ID | 实例维度分析 |
| 官网价 | 税前官网价 | 计算折扣率基准 |
| 优惠金额 | 折扣金额 | 节省金额 |
| 应付金额 | 实际应付(折后) | 实际成本 |
| 优惠名称 | 优惠活动名称 | 识别折扣来源 |
| 合同编号 | 商务合同编号 | 合同维度分析 |
| 优惠类型 | 折扣/资源包等 | 折扣类型分类 |
折扣率 = 优惠金额 / 官网价
折扣率(%) = 折扣率 × 100
示例:
官网价: ¥1000
优惠金额: ¥500
应付金额: ¥500
折扣率: 50%(5折)
CloudLens 提供两种折扣分析方式:
./cl analyze discountGET /api/billing/discounts最佳实践: 两者结合使用
http://localhost:3000/discounts
答:
答:
答:
答:
答:
建议频率: 每月1号
#!/bin/bash
# 自动化脚本 - monthly_discount_check.sh
# 下载最新账单(需要手动或通过API自动化)
# ...
# 运行折扣分析
cd /path/to/cloudlens
./cl analyze discount --export
# 发送报告(邮件/钉钉/企业微信)
# ...
阈值设置: 折扣率下降 > 5%
处理流程:
决策矩阵:
| 折扣率 | 采购建议 |
|---|---|
| > 50% | 优先采购,锁定长期合同 |
| 30-50% | 正常采购 |
| < 30% | 评估替代方案,与商务沟通提高折扣 |
评估指标:
# 1. 成本趋势分析
./cl analyze cost --account prod --trend
# 2. 折扣趋势分析
./cl analyze discount --export
# 3. 综合评估
# - 成本是否增长?
# - 折扣率是否下降?
# - 是否需要优化采购策略?
# 1. 识别闲置资源
./cl analyze idle --account prod
# 2. 查看闲置资源的折扣情况
./cl analyze discount --export --format excel
# 在Excel中筛选闲置实例ID
# 3. 决策
# - 高折扣+闲置:释放浪费更大
# - 低折扣+闲置:优先释放
GET /api/discounts/trend?months=6&force_refresh=false
响应示例:
{
"success": true,
"data": {
"account_name": "1844634015852583",
"analysis_periods": ["2025-12", "2025-11", ...],
"trend_analysis": {
"latest_discount_rate": 0.5743,
"average_discount_rate": 0.5268,
"trend_direction": "上升",
"total_savings_6m": 2579330.06
},
"product_analysis": {...},
"contract_analysis": {...}
}
}
GET /api/discounts/products?product=kafka
用途: 查询特定产品的折扣明细。
错误信息: 未找到账单CSV目录
解决方案:
--bill-dir 参数明确指定错误信息: Failed to parse CSV
解决方案:
解决方案:
# 强制刷新缓存
./cl analyze discount --export
# 或清理缓存
rm -rf ~/.cloudlens/discount_cache
官网价 = 单价 × 用量(未折扣)
优惠金额 = 官网价 - 应付金额
应付金额 = 官网价 - 优惠金额(折后)
./cl analyze discount --help最后更新: 2025-12-15