gcp-cost-optimizer

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GCP Cost Optimizer

GCP成本优化工具

Quick Start

快速开始

Analyze GCP costs and implement optimization strategies to reduce spending.
分析GCP成本并实施优化策略以降低支出。

Instructions

操作指南

Step 1: Analyze current costs

步骤1:分析当前成本

bash
undefined
bash
undefined

View 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
gcloud billing accounts projects link PROJECT_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
project.dataset.gcp_billing_export
WHERE DATE(_PARTITIONTIME) >= DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY) GROUP BY service.description ORDER BY total_cost DESC'
undefined
bq query --use_legacy_sql=false
'SELECT service.description, SUM(cost) as total_cost FROM
project.dataset.gcp_billing_export
WHERE DATE(_PARTITIONTIME) >= DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY) GROUP BY service.description ORDER BY total_cost DESC'
undefined

Step 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
undefined
bash
undefined

Get rightsizing recommendations

Get rightsizing recommendations

gcloud recommender recommendations list
--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

Apply recommendation

Apply recommendation

gcloud recommender recommendations mark-claimed
RECOMMENDATION_ID
--project=PROJECT_ID
--location=us-central1
--recommender=google.compute.instance.MachineTypeRecommender
undefined
gcloud recommender recommendations mark-claimed
RECOMMENDATION_ID
--project=PROJECT_ID
--location=us-central1
--recommender=google.compute.instance.MachineTypeRecommender
undefined

Best Practices

最佳实践

  1. Enable billing export to BigQuery
  2. Set up budget alerts
  3. Use labels for cost allocation
  4. Review Recommender suggestions monthly
  5. Implement committed use discounts for stable workloads
  6. Use preemptible VMs for batch processing
  7. Clean up unused resources regularly
  8. Optimize storage classes
  1. 启用账单数据导出至BigQuery
  2. 设置预算警报
  3. 使用标签进行成本分配
  4. 每月查看Recommender建议
  5. 为稳定工作负载购买承诺使用折扣
  6. 为批处理任务使用抢占式虚拟机
  7. 定期清理闲置资源
  8. 优化存储类别