Halaman ini menunjukkan cara memulai Cost Estimation API, dan menyertakan contoh permintaan API untuk skenario biaya umum. Jika ingin menggunakan konsol Google Cloud, pelajari cara mendapatkan estimasi di konsol Google Cloud
Anda dapat menggunakan Cost Estimation API untuk mendapatkan gambaran tentang biaya workload hipotetis. Misalnya, jika Anda ingin membuat anggaran untuk aplikasi baru, API membantu Anda memperkirakan biaya infrastruktur untuk aplikasi seiring waktu. Anda juga bisa mendapatkan estimasi yang mencakup kredit dari diskon abonemen (DA).
API mendukung estimasi untuk layanan berikut:
- Compute Engine
- Cloud Storage
- CDN Interconnect
- Cloud CDN
- VPC
Jika memiliki kontrak harga yang dinegosiasikan, Anda juga dapat memperkirakan biaya dengan harga yang dinegosiasikan.
Sebelum memulai
Untuk memanggil API, dapatkan kunci API.
Jika ingin mendapatkan estimasi dengan harga kontrak, Anda harus memiliki izin
billing.accounts.getPricing
. Jika Anda memanggil API menggunakan akun layanan, akun layanan tersebut harus memiliki izin.Peran bawaan berikut memiliki izin
billing.accounts.getPricing
:- Billing Account Administrator
- Billing Account Viewer
Jika ingin, aktifkan berbagi diskon untuk DA Anda. Jika Anda tidak mengaktifkan berbagi diskon dan penggunaan Anda terjadi dalam project yang bukan bagian dari komitmen, estimasi biaya dan biaya sebenarnya mungkin berbeda secara signifikan.
Memahami komponen estimasi
Saat menentukan workload untuk estimasi biaya, pertimbangkan faktor-faktor berikut:
Workload: Menggambarkan penggunaan Anda atas satu produk Google Cloud selama jangka waktu estimasi. Misalnya, workload dapat berupa Virtual machine Compute Engine n2 selama 1 minggu.
Dalam permintaan API, Anda menentukan daftar workload dalam objek
workloads
.Skenario Biaya: Kumpulan workload, yang mewakili produk Google Cloud yang dibutuhkan aplikasi Anda. Misalnya, skenario biayanya mungkin merupakan 5 virtual machine n2 dan 4 Gibibyte (GiB) Cloud Storage selama satu minggu.
Dalam permintaan API, Anda mengonfigurasi skenario biaya dalam objek
costScenario
, yang mencakup jangka waktu dan daftar workload.Jangka waktu: Durasi yang ingin Anda perkirakan biayanya. Anda bisa mendapatkan estimasi untuk durasi antara 1 jam dan 10 tahun.
Dalam permintaan API, Anda menentukan jangka waktu menggunakan objek
estimateDuration
.Segmen waktu: Anda dapat membagi estimasi menjadi beberapa segmen waktu, di mana penggunaan bervariasi selama jangka waktu tertentu. Misalnya, Anda dapat meminta estimasi untuk jangka waktu empat minggu, di mana Anda memulai dengan 5 VM selama seminggu, lalu meningkatkannya menjadi 8 VM selama dua minggu, dan mengurangi menjadi 3 VM pada minggu terakhir.
Dalam permintaan API, Anda menentukan segmen waktu menggunakan objek
usageRateTimeline
, dan menetapkan awal segmen menggunakanestimationTimeFrameOffset
.Penggunaan: Menggambarkan jumlah penggunaan selama sebuah segmen waktu. Misalnya, Anda dapat menentukan segmen waktu 5 hari, di mana Anda ingin menggunakan 6 Gibibyte (GiB) di bucket Cloud Storage.
Dalam permintaan API, tentukan penggunaan menggunakan objek
usage
. Saat membuat permintaan API, jika Anda memberikan unit yang salah untuk penggunaan, pesan error akan menyertakan unit yang benar.
Batasan
Workload yang dapat Anda buat modelnya menggunakan API tidak dapat mencerminkan pola penggunaan dunia nyata dengan sempurna. Misalnya, Anda dapat membuat model workload yang berubah setiap jam menggunakan API, tetapi penggunaan Compute Engine dicatat pada tingkat mikrodetik.
Estimasi membuat model penggunaan yang terjadi dalam satu project. Jika Anda memiliki diskon abonemen (DA) dan telah mengaktifkan berbagi diskon di beberapa project, biaya dan kredit untuk DA akan diatribusikan di semua project yang menggunakan layanan tersebut. Misalnya, jika project A dan project B berturut-turut menghabiskan penggunaan senilai $75 dan $25, project A akan dicakup hingga 75% dan project B hingga 25% dari kredit yang tersedia.
Jika penggunaan Anda terjadi pada akhir bulan, penggunaan tersebut mungkin dicatat pada bulan invoice berikutnya.
Estimasi tersebut tidak mencakup biaya jaringan yang terpasang pada VM Compute Engine dalam skenario biaya Anda.
Estimasi ini tidak memperhitungkan Diskon untuk Penggunaan Berkelanjutan (SUD).
Estimasi tersebut tidak memperhitungkan kredit di akun Anda, seperti kredit promosi, atau diskon dari penawaran pribadi di Cloud Marketplace.
Estimasi ini tidak memperhitungkan perubahan harga produk Google Cloud di masa mendatang.
Contoh skenario biaya
Contoh berikut menunjukkan panggilan API untuk mendapatkan estimasi biaya. Untuk mengetahui informasi mendetail mengenai format permintaan, lihat referensi API.
Dalam respons API, estimasi biaya bersih ada dalam objek berikut:
segmentTotalCostEstimate
: Estimasi biaya untuk segmen waktu.workloadTotalCostEstimate
: Estimasi biaya untuk workload.
Memperkirakan biaya virtual machine dengan harga jual
Permintaan API berikut mendapatkan estimasi untuk 5 virtual machine (VM) n1 kustom, dengan harga jual, untuk penggunaan selama 100 jam.
Dalam permintaan, usageRate
menunjukkan jumlah resource yang menjadi bagian dari skenario
biaya.
Sebelum menggunakan salah satu data permintaan, buat pengganti berikut:
- API_KEY: Kunci Google Cloud API Anda
Metode HTTP dan URL:
POST https://cloudbilling.googleapis.com/v1beta:estimateCostScenario?key=API_KEY
Isi JSON permintaan:
{ "costScenario": { "scenarioConfig": { "estimateDuration": "360000s" }, "workloads": [ { "name": "vm-example", "computeVmWorkload": { "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 5 } ] } }, "machineType": { "customMachineType": { "machineSeries": "n1", "virtualCpuCount": 4, "memorySizeGb": 4 } }, "region": "us-central1" } } ] } }
Untuk mengirim permintaan Anda, pilih salah satu opsi berikut:
curl
Simpan isi permintaan dalam file bernama request.json
.
Jalankan perintah berikut di terminal untuk membuat atau menimpa file ini di direktori saat ini:
cat > request.json << 'EOF' { "costScenario": { "scenarioConfig": { "estimateDuration": "360000s" }, "workloads": [ { "name": "vm-example", "computeVmWorkload": { "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 5 } ] } }, "machineType": { "customMachineType": { "machineSeries": "n1", "virtualCpuCount": 4, "memorySizeGb": 4 } }, "region": "us-central1" } } ] } } EOF
Kemudian, jalankan perintah berikut untuk mengirim permintaan REST Anda:
curl -X POST \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
--output cost-estimate.json \
"https://cloudbilling.googleapis.com/v1beta:estimateCostScenario?key=API_KEY"
/powershell
Simpan isi permintaan dalam file bernama request.json
.
Jalankan perintah berikut di terminal untuk membuat atau menimpa file ini di direktori saat ini:
@' { "costScenario": { "scenarioConfig": { "estimateDuration": "360000s" }, "workloads": [ { "name": "vm-example", "computeVmWorkload": { "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 5 } ] } }, "machineType": { "customMachineType": { "machineSeries": "n1", "virtualCpuCount": 4, "memorySizeGb": 4 } }, "region": "us-central1" } } ] } } '@ | Out-File -FilePath request.json -Encoding utf8
Kemudian jalankan perintah berikut untuk mengirim permintaan REST Anda:
$headers = @{ }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-OutFile cost-estimate.json `
-Uri "https://cloudbilling.googleapis.com/v1beta:estimateCostScenario?key=API_KEY"
cost-estimate.json
, dengan
konten berikut.
{ { "costEstimationResult": { "segmentCostEstimates": [ { "segmentStartTime": { "estimationTimeFrameOffset": "0s" }, "workloadCostEstimates": [ { "name": "vm-example", "skuCostEstimates": [ { "sku": "services/6F81-5844-456A/skus/ACBC-6999-A1C4", "usageAmount": 2000, "usageUnit": "h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "66", "nanos": 348000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "66", "nanos": 348000000 } } }, { "sku": "services/6F81-5844-456A/skus/51E2-59BD-7A6E", "usageAmount": 2000, "usageUnit": "GiBy.h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 892000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 892000000 } } } ], "workloadTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "75", "nanos": 240000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "75", "nanos": 240000000 } } } ], "segmentTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "75", "nanos": 240000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "75", "nanos": 240000000 } } } ], "skus": [ { "sku": "services/6F81-5844-456A/skus/ACBC-6999-A1C4", "displayName": "Custom Instance Core running in Americas", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 33174000 } } ], "unit": "h", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/51E2-59BD-7A6E", "displayName": "Custom Instance Ram running in Americas", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 4446000 } } ], "unit": "GiBy.h", "unitCount": 1 } } ] } ], "currencyCode": "USD" } } }
Memperkirakan biaya penggunaan Cloud Storage dengan harga kontrak
Permintaan API berikut mendapatkan estimasi untuk 1 bulan sebesar 500 GibiBytes (GiB) di asia-southeast2, dengan harga kontrak:
Sebelum menggunakan salah satu data permintaan, buat pengganti berikut:
- BILLING_ACCOUNT_ID: ID akun Penagihan Cloud. Akun harus memiliki kontrak harga kustom yang terkait dengannya.
Metode HTTP dan URL:
POST https://cloudbilling.googleapis.com/v1beta/billingAccounts/BILLING_ACCOUNT_ID:estimateCostScenario
Isi JSON permintaan:
{ "costScenario": { "workloads": [ { "name": "combined-example-storage", "cloudStorageWorkload": { "region": { "name": "us-central1" }, "storageClass": "archive", "dataStored": { "usageRateTimeline": { "unit": "GiBy", "usageRateTimelineEntries": [ { "usageRate": 7000 } ] } } } }, { "name": "combined-example-compute", "computeVmWorkload": { "machineType": { "predefinedMachineType": { "machineType": "n2-standard-4" } }, "region": "us-central1", "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 8 }, { "usageRate": 11, "effectiveTime": { "estimationTimeFrameOffset": "1209600s" } } ] } } } } ], "scenarioConfig": { "estimateDuration": "2628000s" } } }
Untuk mengirim permintaan Anda, pilih salah satu opsi berikut:
curl
Simpan isi permintaan dalam file bernama request.json
.
Jalankan perintah berikut di terminal untuk membuat atau menimpa file ini di direktori saat ini:
cat > request.json << 'EOF' { "costScenario": { "workloads": [ { "name": "combined-example-storage", "cloudStorageWorkload": { "region": { "name": "us-central1" }, "storageClass": "archive", "dataStored": { "usageRateTimeline": { "unit": "GiBy", "usageRateTimelineEntries": [ { "usageRate": 7000 } ] } } } }, { "name": "combined-example-compute", "computeVmWorkload": { "machineType": { "predefinedMachineType": { "machineType": "n2-standard-4" } }, "region": "us-central1", "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 8 }, { "usageRate": 11, "effectiveTime": { "estimationTimeFrameOffset": "1209600s" } } ] } } } } ], "scenarioConfig": { "estimateDuration": "2628000s" } } } EOF
Kemudian, jalankan perintah berikut untuk mengirim permintaan REST Anda:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
--output cost-estimate.json \
"https://cloudbilling.googleapis.com/v1beta/billingAccounts/BILLING_ACCOUNT_ID:estimateCostScenario"
/powershell
Simpan isi permintaan dalam file bernama request.json
.
Jalankan perintah berikut di terminal untuk membuat atau menimpa file ini di direktori saat ini:
@' { "costScenario": { "workloads": [ { "name": "combined-example-storage", "cloudStorageWorkload": { "region": { "name": "us-central1" }, "storageClass": "archive", "dataStored": { "usageRateTimeline": { "unit": "GiBy", "usageRateTimelineEntries": [ { "usageRate": 7000 } ] } } } }, { "name": "combined-example-compute", "computeVmWorkload": { "machineType": { "predefinedMachineType": { "machineType": "n2-standard-4" } }, "region": "us-central1", "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 8 }, { "usageRate": 11, "effectiveTime": { "estimationTimeFrameOffset": "1209600s" } } ] } } } } ], "scenarioConfig": { "estimateDuration": "2628000s" } } } '@ | Out-File -FilePath request.json -Encoding utf8
Kemudian jalankan perintah berikut untuk mengirim permintaan REST Anda:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-OutFile cost-estimate.json `
-Uri "https://cloudbilling.googleapis.com/v1beta/billingAccounts/BILLING_ACCOUNT_ID:estimateCostScenario"
cost-estimate.json
, dengan
konten berikut.
{ "costEstimationResult": { "segmentCostEstimates": [ { "segmentStartTime": { "estimationTimeFrameOffset": "0s" }, "workloadCostEstimates": [ { "name": "combined-example-storage", "skuCostEstimates": [ { "sku": "services/95FF-2EF5-5EA1/skus/EC4B-C190-470D", "usageAmount": 7000, "usageUnit": "GiBy.mo", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 400000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 400000000 } } } ], "workloadTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 400000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 400000000 } } }, { "name": "combined-example-compute", "skuCostEstimates": [ { "sku": "services/6F81-5844-456A/skus/BB77-5FDA-69D9", "usageAmount": 28088, "usageUnit": "h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "887", "nanos": 889768000 }, "creditEstimates": [ { "creditAmount": { "currencyCode": "USD", "units": "-159", "nanos": -850504800 }, "creditType": "Sustained Use Discount" } ], "netCostEstimate": { "currencyCode": "USD", "units": "728", "nanos": 39263200 } } }, { "sku": "services/6F81-5844-456A/skus/5B01-D157-A097", "usageAmount": 112352, "usageUnit": "GiBy.h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "476", "nanos": 35424000 }, "creditEstimates": [ { "creditAmount": { "currencyCode": "USD", "units": "-85", "nanos": -702646400 }, "creditType": "Sustained Use Discount" } ], "netCostEstimate": { "currencyCode": "USD", "units": "390", "nanos": 332777600 } } } ], "workloadTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "1363", "nanos": 925192000 }, "creditEstimates": [ { "creditAmount": { "currencyCode": "USD", "units": "-245", "nanos": -553151200 }, "creditType": "Sustained Use Discount" } ], "netCostEstimate": { "currencyCode": "USD", "units": "1118", "nanos": 372040800 } } } ], "segmentTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "1372", "nanos": 325192000 }, "creditEstimates": [ { "creditAmount": { "currencyCode": "USD", "units": "-245", "nanos": -553151200 }, "creditType": "Sustained Use Discount" } ], "netCostEstimate": { "currencyCode": "USD", "units": "1126", "nanos": 772040800 } } } ], "skus": [ { "sku": "services/95FF-2EF5-5EA1/skus/EC4B-C190-470D", "displayName": "Archive Storage Iowa", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 1200000 } } ], "unit": "GiBy.mo", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/BB77-5FDA-69D9", "displayName": "N2 Instance Core running in Americas", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 31611000 } } ], "unit": "h", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/5B01-D157-A097", "displayName": "N2 Instance Ram running in Americas", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 4237000 } } ], "unit": "GiBy.h", "unitCount": 1 } } ] } ], "currencyCode": "USD" } }
Memperkirakan biaya workload yang berubah dari waktu ke waktu
Permintaan API berikut mendapatkan estimasi untuk penggunaan selama 1 bulan, dengan harga kontrak kustom, untuk resource berikut:
- Penyimpanan 7.000 GiB
- 8 VM n2-standard-4
- 3 VM n2-standard-4 tambahan setelah 14 hari dalam sebulan
Contoh ini menggunakan kolom estimationTimeFrameOffset
untuk menentukan kapan
segmen waktu yang baru dimulai. Jumlah VM berubah dari 8
menjadi 11
(usageRate
)
setelah 1209600 detik (14 hari), seperti yang ditunjukkan dalam cuplikan ini:
"usageRateTimeline": {
"usageRateTimelineEntries": [
{
"usageRate": 8
},
{
"usageRate": 11,
"effectiveTime": {
"estimationTimeFrameOffset": "1209600s"
}
}
]
Demikian pula, jika Anda ingin memperkirakan biaya jika workload Anda dikurangi menjadi 3 VM
20 hari sejak awal jangka waktu, Anda dapat menambahkan satu segmen lagi ke
usageRateTimelineEntries
, yang ditunjukkan dalam contoh ini:
"usageRateTimeline": {
"usageRateTimelineEntries": [
{
"usageRate": 8
},
{
"usageRate": 11,
"effectiveTime": {
"estimationTimeFrameOffset": "1209600s"
}
}
{
"usageRate": 3,
"effectiveTime": {
"estimationTimeFrameOffset": "1728000s"
}
}
]
Sebelum menggunakan salah satu data permintaan, buat pengganti berikut:
- API_KEY: Kunci Google Cloud API Anda
Metode HTTP dan URL:
POST https://cloudbilling.googleapis.com/v1beta:estimateCostScenario?key=API_KEY
Isi JSON permintaan:
{ "costScenario": { "workloads": [ { "name": "combined-example-storage", "cloudStorageWorkload": { "region": { "name": "us-central1" }, "storageClass": "archive", "dataStored": { "usageRateTimeline": { "unit": "GiBy", "usageRateTimelineEntries": [ { "usageRate": 7000 } ] } } } }, { "name": "combined-example-compute", "computeVmWorkload": { "machineType": { "predefinedMachineType": { "machineType": "n2-standard-4" } }, "region": "us-central1", "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 8 }, { "usageRate": 11, "effectiveTime": { "estimationTimeFrameOffset": "1209600s" } } ] } } } } ], "scenarioConfig": { "estimateDuration": "2628000s" } } }
Untuk mengirim permintaan Anda, pilih salah satu opsi berikut:
curl
Simpan isi permintaan dalam file bernama request.json
.
Jalankan perintah berikut di terminal untuk membuat atau menimpa file ini di direktori saat ini:
cat > request.json << 'EOF' { "costScenario": { "workloads": [ { "name": "combined-example-storage", "cloudStorageWorkload": { "region": { "name": "us-central1" }, "storageClass": "archive", "dataStored": { "usageRateTimeline": { "unit": "GiBy", "usageRateTimelineEntries": [ { "usageRate": 7000 } ] } } } }, { "name": "combined-example-compute", "computeVmWorkload": { "machineType": { "predefinedMachineType": { "machineType": "n2-standard-4" } }, "region": "us-central1", "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 8 }, { "usageRate": 11, "effectiveTime": { "estimationTimeFrameOffset": "1209600s" } } ] } } } } ], "scenarioConfig": { "estimateDuration": "2628000s" } } } EOF
Kemudian, jalankan perintah berikut untuk mengirim permintaan REST Anda:
curl -X POST \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
--output cost-estimate.json \
"https://cloudbilling.googleapis.com/v1beta:estimateCostScenario?key=API_KEY"
/powershell
Simpan isi permintaan dalam file bernama request.json
.
Jalankan perintah berikut di terminal untuk membuat atau menimpa file ini di direktori saat ini:
@' { "costScenario": { "workloads": [ { "name": "combined-example-storage", "cloudStorageWorkload": { "region": { "name": "us-central1" }, "storageClass": "archive", "dataStored": { "usageRateTimeline": { "unit": "GiBy", "usageRateTimelineEntries": [ { "usageRate": 7000 } ] } } } }, { "name": "combined-example-compute", "computeVmWorkload": { "machineType": { "predefinedMachineType": { "machineType": "n2-standard-4" } }, "region": "us-central1", "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 8 }, { "usageRate": 11, "effectiveTime": { "estimationTimeFrameOffset": "1209600s" } } ] } } } } ], "scenarioConfig": { "estimateDuration": "2628000s" } } } '@ | Out-File -FilePath request.json -Encoding utf8
Kemudian jalankan perintah berikut untuk mengirim permintaan REST Anda:
$headers = @{ }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-OutFile cost-estimate.json `
-Uri "https://cloudbilling.googleapis.com/v1beta:estimateCostScenario?key=API_KEY"
cost-estimate.json
, dengan
konten berikut.
{ "costEstimationResult": { "segmentCostEstimates": [ { "segmentStartTime": { "estimationTimeFrameOffset": "0s" }, "workloadCostEstimates": [ { "name": "combined-example-storage", "skuCostEstimates": [ { "sku": "services/95FF-2EF5-5EA1/skus/EC4B-C190-470D", "usageAmount": 7000, "usageUnit": "GiBy.mo", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 400000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 400000000 } } } ], "workloadTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 400000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 400000000 } } }, { "name": "combined-example-compute", "skuCostEstimates": [ { "sku": "services/6F81-5844-456A/skus/BB77-5FDA-69D9", "usageAmount": 28088, "usageUnit": "h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "887", "nanos": 889768000 }, "netCostEstimate": { "currencyCode": "USD", "units": "887", "nanos": 889768000 } } }, { "sku": "services/6F81-5844-456A/skus/5B01-D157-A097", "usageAmount": 112352, "usageUnit": "GiBy.h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "476", "nanos": 35424000 }, "netCostEstimate": { "currencyCode": "USD", "units": "476", "nanos": 35424000 } } } ], "workloadTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "1363", "nanos": 925192000 }, "netCostEstimate": { "currencyCode": "USD", "units": "1363", "nanos": 925192000 } } } ], "segmentTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "1372", "nanos": 325192000 }, "netCostEstimate": { "currencyCode": "USD", "units": "1372", "nanos": 325192000 } } } ], "skus": [ { "sku": "services/95FF-2EF5-5EA1/skus/EC4B-C190-470D", "displayName": "Archive Storage Iowa", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 1200000 } } ], "unit": "GiBy.mo", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/BB77-5FDA-69D9", "displayName": "N2 Instance Core running in Americas", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 31611000 } } ], "unit": "h", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/5B01-D157-A097", "displayName": "N2 Instance Ram running in Americas", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 4237000 } } ], "unit": "GiBy.h", "unitCount": 1 } } ] } ], "currencyCode": "USD" } }
Memperkirakan biaya workload saat Anda memiliki diskon abonemen (DA)
Contoh berikut menunjukkan permintaan API untuk VM a2-megagpu, dengan GPU NVIDIA Tesla A100 dan persistent disk Extreme, selama 5 jam (18.000 detik), dengan harga kontrak dan komitmen 1 tahun.
Sebelum menggunakan salah satu data permintaan, buat pengganti berikut:
- BILLING_ACCOUNT_ID: ID akun Penagihan Cloud. Akun harus memiliki kontrak harga kustom yang terkait dengannya.
Metode HTTP dan URL:
POST https://cloudbilling.googleapis.com/v1beta/billingAccounts/BILLING_ACCOUNT_ID:estimateCostScenario
Isi JSON permintaan:
{ "costScenario": { "workloads": [{ "name": "Custom VM", "computeVmWorkload": { "region": "us-central1", "machineType": { "predefinedMachineType": { "machineType": "a2-megagpu-16g" } }, "guestAccelerator": { "acceleratorType": "nvidia-tesla-a100", "acceleratorCount": "1" }, "persistentDisks": [{ "diskType": "pd-extreme", "scope": "SCOPE_ZONAL", "diskSize": { "usageRateTimeline": { "unit": "GiBy", "usageRateTimelineEntries": [{ "usageRate": 1000.0 }] } }, "provisionedIops": { "usageRateTimeline": { "usageRateTimelineEntries": [{ "usageRate": 15000.0 }] } } }], "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [{ "usageRate": 1.0 }] } } } }], "commitments": [{ "name": "VM commitment", "vmResourceBasedCud": { "region": "us-central1", "virtualCpuCount": "48", "memorySizeGb": 680.0, "plan": "TWELVE_MONTH", "machineSeries": "a2" } }], "scenarioConfig": { "estimateDuration": "18000s" } } }
Untuk mengirim permintaan Anda, pilih salah satu opsi berikut:
curl
Simpan isi permintaan dalam file bernama request.json
.
Jalankan perintah berikut di terminal untuk membuat atau menimpa file ini di direktori saat ini:
cat > request.json << 'EOF' { "costScenario": { "workloads": [{ "name": "Custom VM", "computeVmWorkload": { "region": "us-central1", "machineType": { "predefinedMachineType": { "machineType": "a2-megagpu-16g" } }, "guestAccelerator": { "acceleratorType": "nvidia-tesla-a100", "acceleratorCount": "1" }, "persistentDisks": [{ "diskType": "pd-extreme", "scope": "SCOPE_ZONAL", "diskSize": { "usageRateTimeline": { "unit": "GiBy", "usageRateTimelineEntries": [{ "usageRate": 1000.0 }] } }, "provisionedIops": { "usageRateTimeline": { "usageRateTimelineEntries": [{ "usageRate": 15000.0 }] } } }], "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [{ "usageRate": 1.0 }] } } } }], "commitments": [{ "name": "VM commitment", "vmResourceBasedCud": { "region": "us-central1", "virtualCpuCount": "48", "memorySizeGb": 680.0, "plan": "TWELVE_MONTH", "machineSeries": "a2" } }], "scenarioConfig": { "estimateDuration": "18000s" } } } EOF
Kemudian, jalankan perintah berikut untuk mengirim permintaan REST Anda:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
--output cost-estimate.json \
"https://cloudbilling.googleapis.com/v1beta/billingAccounts/BILLING_ACCOUNT_ID:estimateCostScenario"
/powershell
Simpan isi permintaan dalam file bernama request.json
.
Jalankan perintah berikut di terminal untuk membuat atau menimpa file ini di direktori saat ini:
@' { "costScenario": { "workloads": [{ "name": "Custom VM", "computeVmWorkload": { "region": "us-central1", "machineType": { "predefinedMachineType": { "machineType": "a2-megagpu-16g" } }, "guestAccelerator": { "acceleratorType": "nvidia-tesla-a100", "acceleratorCount": "1" }, "persistentDisks": [{ "diskType": "pd-extreme", "scope": "SCOPE_ZONAL", "diskSize": { "usageRateTimeline": { "unit": "GiBy", "usageRateTimelineEntries": [{ "usageRate": 1000.0 }] } }, "provisionedIops": { "usageRateTimeline": { "usageRateTimelineEntries": [{ "usageRate": 15000.0 }] } } }], "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [{ "usageRate": 1.0 }] } } } }], "commitments": [{ "name": "VM commitment", "vmResourceBasedCud": { "region": "us-central1", "virtualCpuCount": "48", "memorySizeGb": 680.0, "plan": "TWELVE_MONTH", "machineSeries": "a2" } }], "scenarioConfig": { "estimateDuration": "18000s" } } } '@ | Out-File -FilePath request.json -Encoding utf8
Kemudian jalankan perintah berikut untuk mengirim permintaan REST Anda:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-OutFile cost-estimate.json `
-Uri "https://cloudbilling.googleapis.com/v1beta/billingAccounts/BILLING_ACCOUNT_ID:estimateCostScenario"
cost-estimate.json
, dengan
konten berikut. Estimasi penghematan dari
DA ada dalam objek `commitmentCostEstimates`:
{ "costEstimationResult": { "segmentCostEstimates": [ { "segmentStartTime": { "estimationTimeFrameOffset": "0s" }, "workloadCostEstimates": [ { "name": "Custom VM", "skuCostEstimates": [ { "sku": "services/6F81-5844-456A/skus/2922-40C5-B19F", "usageAmount": 480, "usageUnit": "h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "15", "nanos": 173280000 }, "creditEstimates": [ { "creditAmount": { "currencyCode": "USD", "units": "-7", "nanos": -586640000 }, "creditType": "Committed Use Discount" } ], "netCostEstimate": { "currencyCode": "USD", "units": "7", "nanos": 586640000 } } }, { "sku": "services/6F81-5844-456A/skus/2390-DCAF-DA38", "usageAmount": 6800, "usageUnit": "GiBy.h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "28", "nanos": 811600000 }, "creditEstimates": [ { "creditAmount": { "currencyCode": "USD", "units": "-6", "nanos": -609720000 }, "creditType": "Committed Use Discount" } ], "netCostEstimate": { "currencyCode": "USD", "units": "22", "nanos": 201880000 } } }, { "sku": "services/6F81-5844-456A/skus/039F-D0DA-4055", "usageAmount": 5, "usageUnit": "h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "14", "nanos": 669540000 }, "netCostEstimate": { "currencyCode": "USD", "units": "14", "nanos": 669540000 } } }, { "sku": "services/6F81-5844-456A/skus/165B-942F-F345", "usageAmount": 6.8493150684931505, "usageUnit": "GiBy.mo", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "nanos": 856164383 }, "netCostEstimate": { "currencyCode": "USD", "nanos": 856164383 } } }, { "sku": "services/6F81-5844-456A/skus/DCA4-F1BE-57C4", "usageAmount": 102.73972602739725, "usageUnit": "mo", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "6", "nanos": 678082191 }, "netCostEstimate": { "currencyCode": "USD", "units": "6", "nanos": 678082191 } } } ], "workloadTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "66", "nanos": 188666574 }, "creditEstimates": [ { "creditAmount": { "currencyCode": "USD", "units": "-14", "nanos": -196360000 }, "creditType": "Committed Use Discount" } ], "netCostEstimate": { "currencyCode": "USD", "units": "51", "nanos": 992306574 } } } ], "segmentTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "75", "nanos": 131906574 }, "creditEstimates": [ { "creditAmount": { "currencyCode": "USD", "units": "-14", "nanos": -196360000 }, "creditType": "Committed Use Discount" } ], "netCostEstimate": { "currencyCode": "USD", "units": "60", "nanos": 935546574 } }, "commitmentCostEstimates": [ { "name": "VM commitment", "skuCostEstimates": [ { "sku": "services/6F81-5844-456A/skus/3A31-931E-6360", "usageAmount": 240, "usageUnit": "h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "4", "nanos": 779600000 }, "netCostEstimate": { "currencyCode": "USD", "units": "4", "nanos": 779600000 } } }, { "sku": "services/6F81-5844-456A/skus/220C-35D0-70E0", "usageAmount": 1560, "usageUnit": "GiBy.h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "4", "nanos": 163640000 }, "netCostEstimate": { "currencyCode": "USD", "units": "4", "nanos": 163640000 } } } ], "commitmentTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 943240000 }, "netCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 943240000 } } } ] } ], "skus": [ { "sku": "services/6F81-5844-456A/skus/3A31-931E-6360", "displayName": "Commitment v1: A2 Cpu in Americas for 1 Year", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 19915000 } } ], "unit": "h", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/220C-35D0-70E0", "displayName": "Commitment v1: A2 Ram in Americas for 1 Year", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 2669000 } } ], "unit": "GiBy.h", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/039F-D0DA-4055", "displayName": "Nvidia Tesla A100 GPU running in Americas", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "units": "2", "nanos": 933908000 } } ], "unit": "h", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/165B-942F-F345", "displayName": "Extreme PD Capacity", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 125000000 } } ], "unit": "GiBy.mo", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/DCA4-F1BE-57C4", "displayName": "Extreme PD IOPS", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 65000000 } } ], "unit": "mo", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/2922-40C5-B19F", "displayName": "A2 Instance Core running in Americas", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 31611000 } } ], "unit": "h", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/2390-DCAF-DA38", "displayName": "A2 Instance Ram running in Americas", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 4237000 } } ], "unit": "GiBy.h", "unitCount": 1 } } ] } ], "currencyCode": "USD" } }
Memperkirakan biaya VM dengan lisensi premium, dengan harga jual
Contoh berikut menunjukkan permintaan API untuk 5 virtual machine n1 kustom dengan lisensi premium Windows Server 2022 DC dengan harga jual, selama 100 jam.
Sebelum menggunakan salah satu data permintaan, buat pengganti berikut:
- API_KEY: Kunci Google Cloud API Anda
Metode HTTP dan URL:
POST https://cloudbilling.googleapis.com/v1beta:estimateCostScenario?key=API_KEY
Isi JSON permintaan:
{ "costScenario": { "scenarioConfig": { "estimateDuration": "360000s" }, "workloads": [ { "name": "vm-example", "computeVmWorkload": { "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 5 } ] } }, "machineType": { "customMachineType": { "machineSeries": "n1", "virtualCpuCount": 4, "memorySizeGb": 4 } }, "region": "us-central1", "licenses": "projects/windows-cloud/global/licenses/windows-server-2022-dc" } } ] } }
Untuk mengirim permintaan Anda, pilih salah satu opsi berikut:
curl
Simpan isi permintaan dalam file bernama request.json
.
Jalankan perintah berikut di terminal untuk membuat atau menimpa file ini di direktori saat ini:
cat > request.json << 'EOF' { "costScenario": { "scenarioConfig": { "estimateDuration": "360000s" }, "workloads": [ { "name": "vm-example", "computeVmWorkload": { "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 5 } ] } }, "machineType": { "customMachineType": { "machineSeries": "n1", "virtualCpuCount": 4, "memorySizeGb": 4 } }, "region": "us-central1", "licenses": "projects/windows-cloud/global/licenses/windows-server-2022-dc" } } ] } } EOF
Kemudian, jalankan perintah berikut untuk mengirim permintaan REST Anda:
curl -X POST \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
--output cost-estimate.json \
"https://cloudbilling.googleapis.com/v1beta:estimateCostScenario?key=API_KEY"
/powershell
Simpan isi permintaan dalam file bernama request.json
.
Jalankan perintah berikut di terminal untuk membuat atau menimpa file ini di direktori saat ini:
@' { "costScenario": { "scenarioConfig": { "estimateDuration": "360000s" }, "workloads": [ { "name": "vm-example", "computeVmWorkload": { "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 5 } ] } }, "machineType": { "customMachineType": { "machineSeries": "n1", "virtualCpuCount": 4, "memorySizeGb": 4 } }, "region": "us-central1", "licenses": "projects/windows-cloud/global/licenses/windows-server-2022-dc" } } ] } } '@ | Out-File -FilePath request.json -Encoding utf8
Kemudian jalankan perintah berikut untuk mengirim permintaan REST Anda:
$headers = @{ }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-OutFile cost-estimate.json `
-Uri "https://cloudbilling.googleapis.com/v1beta:estimateCostScenario?key=API_KEY"
cost-estimate.json
, dengan
konten berikut.
{ "costEstimationResult": { "segmentCostEstimates": [ { "segmentStartTime": { "estimationTimeFrameOffset": "0s" }, "workloadCostEstimates": [ { "name": "vm-example", "skuCostEstimates": [ { "sku": "services/6F81-5844-456A/skus/ACBC-6999-A1C4", "usageAmount": 2000, "usageUnit": "h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "66", "nanos": 348000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "66", "nanos": 348000000 } } }, { "sku": "services/6F81-5844-456A/skus/51E2-59BD-7A6E", "usageAmount": 2000, "usageUnit": "GiBy.h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 892000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 892000000 } } }, { "sku": "services/6F81-5844-456A/skus/92D2-8A8F-DF54", "usageAmount": 2000, "usageUnit": "h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "92" }, "netCostEstimate": { "currencyCode": "USD", "units": "92" } } } ], "workloadTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "167", "nanos": 240000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "167", "nanos": 240000000 } } } ], "segmentTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "167", "nanos": 240000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "167", "nanos": 240000000 } } } ], "skus": [ { "sku": "services/6F81-5844-456A/skus/92D2-8A8F-DF54", "displayName": "Licensing Fee for Windows Server 2022 Datacenter Edition on VM", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 46000000 } } ], "unit": "h", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/ACBC-6999-A1C4", "displayName": "Custom Instance Core running in Americas", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 33174000 } } ], "unit": "h", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/51E2-59BD-7A6E", "displayName": "Custom Instance Ram running in Americas", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 4446000 } } ], "unit": "GiBy.h", "unitCount": 1 } } ] } ], "currencyCode": "USD" } }