gcp-cost-optimizer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGCP Cost Optimizer
GCP成本优化工具
Quick Start
快速开始
Analyze GCP costs and implement optimization strategies to reduce spending.
分析GCP成本并实施优化策略以降低支出。
Instructions
操作指南
Step 1: Analyze current costs
步骤1:分析当前成本
bash
undefinedbash
undefinedView billing data
View billing data
gcloud billing accounts list
gcloud billing accounts list
Export billing data to BigQuery
Export billing data to BigQuery
gcloud billing accounts projects link PROJECT_ID
--billing-account=BILLING_ACCOUNT_ID
--billing-account=BILLING_ACCOUNT_ID
gcloud billing accounts projects link PROJECT_ID
--billing-account=BILLING_ACCOUNT_ID
--billing-account=BILLING_ACCOUNT_ID
Query costs
Query costs
bq query --use_legacy_sql=false
'SELECT service.description, SUM(cost) as total_cost FROM
WHERE DATE(_PARTITIONTIME) >= DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY)
GROUP BY service.description
ORDER BY total_cost DESC'
'SELECT service.description, SUM(cost) as total_cost FROM
project.dataset.gcp_billing_exportundefinedbq query --use_legacy_sql=false
'SELECT service.description, SUM(cost) as total_cost FROM
WHERE DATE(_PARTITIONTIME) >= DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY)
GROUP BY service.description
ORDER BY total_cost DESC'
'SELECT service.description, SUM(cost) as total_cost FROM
project.dataset.gcp_billing_exportundefinedStep 2: Identify optimization opportunities
步骤2:识别优化机会
Committed Use Discounts:
- 1-year or 3-year commitments
- Up to 57% savings for Compute Engine
- Up to 70% savings for Cloud SQL
Sustained Use Discounts:
- Automatic discounts for running instances
- Up to 30% for instances running >25% of month
Preemptible VMs:
- Up to 80% savings
- Suitable for fault-tolerant workloads
Rightsizing:
- Use Recommender API for suggestions
- Downsize overprovisioned instances
- Adjust machine types
承诺使用折扣:
- 1年或3年承诺期限
- Compute Engine最高可节省57%成本
- Cloud SQL最高可节省70%成本
持续使用折扣:
- 为运行中的实例自动提供折扣
- 实例月运行时长超过25%时,最高可节省30%成本
抢占式虚拟机:
- 最高可节省80%成本
- 适用于容错型工作负载
资源合理配置:
- 使用Recommender API获取建议
- 为过度配置的实例降配
- 调整机器类型
Step 3: Implement cost-saving measures
步骤3:实施成本节约措施
bash
undefinedbash
undefinedGet rightsizing recommendations
Get rightsizing recommendations
gcloud recommender recommendations list
--project=PROJECT_ID
--location=us-central1
--recommender=google.compute.instance.MachineTypeRecommender
--project=PROJECT_ID
--location=us-central1
--recommender=google.compute.instance.MachineTypeRecommender
gcloud recommender recommendations list
--project=PROJECT_ID
--location=us-central1
--recommender=google.compute.instance.MachineTypeRecommender
--project=PROJECT_ID
--location=us-central1
--recommender=google.compute.instance.MachineTypeRecommender
Apply recommendation
Apply recommendation
gcloud recommender recommendations mark-claimed
RECOMMENDATION_ID
--project=PROJECT_ID
--location=us-central1
--recommender=google.compute.instance.MachineTypeRecommender
RECOMMENDATION_ID
--project=PROJECT_ID
--location=us-central1
--recommender=google.compute.instance.MachineTypeRecommender
undefinedgcloud recommender recommendations mark-claimed
RECOMMENDATION_ID
--project=PROJECT_ID
--location=us-central1
--recommender=google.compute.instance.MachineTypeRecommender
RECOMMENDATION_ID
--project=PROJECT_ID
--location=us-central1
--recommender=google.compute.instance.MachineTypeRecommender
undefinedBest Practices
最佳实践
- Enable billing export to BigQuery
- Set up budget alerts
- Use labels for cost allocation
- Review Recommender suggestions monthly
- Implement committed use discounts for stable workloads
- Use preemptible VMs for batch processing
- Clean up unused resources regularly
- Optimize storage classes
- 启用账单数据导出至BigQuery
- 设置预算警报
- 使用标签进行成本分配
- 每月查看Recommender建议
- 为稳定工作负载购买承诺使用折扣
- 为批处理任务使用抢占式虚拟机
- 定期清理闲置资源
- 优化存储类别