設定未充分運用的預留項目建議


本頁面說明如何查看及修改未充分利用的隨選預訂建議設定。您可能想修改設定,增加收到的建議數量,或是減少建議數量,以便刪除打算使用的預訂。

事前準備

  • 如果尚未設定驗證,請先完成設定。 「驗證」是指驗證身分的程序,確認您有權存取 Google Cloud 服務和 API。如要從本機開發環境執行程式碼或範例,請選取下列其中一個選項,向 Compute Engine 進行驗證:

    Select the tab for how you plan to use the samples on this page:

    gcloud

      1. After installing the Google Cloud CLI, initialize it by running the following command:

        gcloud init

        If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

      2. Set a default region and zone.
      3. REST

        如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。

          After installing the Google Cloud CLI, initialize it by running the following command:

          gcloud init

          If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

        詳情請參閱 Google Cloud 驗證說明文件中的「Authenticate for using REST」。

設定建議

如要設定資源用量不足的預訂項目建議,請按照下列步驟操作:

  1. 取得目前的設定,以取得設定的 JSON 檔案。
  2. 編輯 JSON 格式的設定檔。
  3. 上傳新的設定檔,即可套用變更。

取得目前的設定

您可以使用 Google Cloud CLI 或 REST,取得專案目前未充分利用預留資源建議的設定。

請使用下列其中一種方法完成這項工作。

gcloud

如要取得目前的設定參數,請使用 gcloud recommender recommender-config describe 指令,並將 google.compute.RightSizeResourceRecommender 做為 Recommender ID:

gcloud recommender recommender-config describe google.compute.RightSizeResourceRecommender \
  --location=ZONE --billing-account=BILLING_ACCOUNT_ID

更改下列內容:

  • ZONE,其中包含要列出建議的預訂項目。
  • BILLING_ACCOUNT_ID 替換為帳單帳戶的 ID。

例如:

gcloud recommender recommender-config describe google.compute.RightSizeResourceRecommender \
  --location=us-central1-c --billing-account=my-billing-account-id

指令會傳回建議事項設定,包括可修改的子欄位 params.under_utilized_reservation_lookback_periodparams.under_utilized_reservation_utilization_threshold

{
  "name": "projects/PROJECT_ID/locations/ZONE/recommenders/google.compute.RightSizeResourceRecommender/config",
  "recommenderGenerationConfig": {
    "params": {
      "under_utilized_reservation_lookback_period": "P7D",
      "under_utilized_reservation_utilization_threshold": "0.8"
    }
  },
  "etag": "\"2f3c9b65cda6a4ba\"",
  "updateTime": "2024-06-03T04:41:15.330351Z"
}

REST

如要擷取目前的設定,請使用 recommenders.getConfig 方法,並將 google.compute.RightSizeResourceRecommender 指定為建議事項 ID:

GET https://recommender.googleapis.com/v1/projects/PROJECT_ID/locations/ZONE/recommenders/google.compute.RightSizeResourceRecommender/config

更改下列內容:

  • PROJECT_ID:要修改建議事項設定的專案 ID。
  • ZONE:包含專案的可用區。

在指令列執行下列指令,取得專案的建議事項設定:

PROJECT_ID=PROJECT_ID
ZONE=ZONE
curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: ${PROJECT_ID}" \
https://recommender.googleapis.com/v1/projects/$PROJECT_ID/locations/$ZONE/recommenders/google.compute.RightSizeResourceRecommender/config

這項指令會傳回建議事項設定,包括可修改的子欄位:params.under_utilized_reservation_lookback_periodparams.under_utilized_reservation_utilization_threshold

{
  "name": "projects/PROJECT_ID/locations/ZONE/recommenders/google.compute.RightSizeResourceRecommender/config",
  "recommenderGenerationConfig": {
    "params": {
      "under_utilized_reservation_lookback_period": "P7D",
      "under_utilized_reservation_utilization_threshold": "0.8"
    }
  },
  "etag": "\"2f3c9b65cda6a4ba\"",
  "updateTime": "2024-06-03T04:41:15.330351Z"
}

更新專案的設定

如要更新資源用量不足預訂建議的設定,請修改 under_utilized_reservation_lookback_period 的值,並上傳專案的新設定。

您可以將觀察期設為 7 天到 30 天之間的值,方法是使用以 P 開頭的字串,然後輸入天數的整數值 (最小值為 7,最大值為 30),最後加上 D,例如:

  • 如要將觀測期設為 7 天,請使用 "P7D"
  • 如要設定 30 天的觀測期,請使用 "P30D"

同樣地,請修改 under_utilized_reservation_utilization_threshold 的值,設定觸發資源用量不足預訂項目建議的用量門檻,並上傳專案的新設定,例如:

  • 如果門檻為 80%,則為 "0.8"

上傳新設定後,大約需要 48 小時才會生效。在此之前,系統會使用先前的設定生成建議。

請使用下列其中一種方法完成這項工作。

gcloud

如要更新設定參數,請使用 gcloud recommender recommender-config update 指令,並將 google.compute.RightSizeResourceRecommender 做為建議事項 ID:

gcloud recommender recommender-config update google.compute.RightSizeResourceRecommender\
  --location=ZONE \
  --config-file=CONFIG_FILE_PATH \
  --etag=ETAG \
  --billing-account=BILLING_ACCOUNT_ID

更改下列內容:

  • ZONE:要取得目前設定的區域
  • CONFIG_FILE_PATH:包含目前設定的 JSON 檔案路徑
  • ETAG:目前設定的 etag 值
  • BILLING_ACCOUNT_ID:帳單帳戶的 ID

在設定檔中,只指定包含更新後設定參數的 recommenderGenerationConfig 物件。舉例來說,如要指定 21 天的觀察期,並將資源用量不足的預訂項目門檻設為 80%,請使用下列設定檔:

{
  "params": {
    "under_utilized_reservation_lookback_period": "P21D",
    "under_utilized_reservation_utilization_threshold": "0.8"
  }
}

如果指令成功,會傳回類似以下的內容,顯示您剛修改參數的新設定。

{
  "name": "projects/PROJECT_ID/locations/ZONE/recommenders/google.compute.RightSizeResourceRecommender/config",
  "recommenderGenerationConfig": {
    "params": {
      "under_utilized_reservation_lookback_period": "P21D",
      "under_utilized_reservation_utilization_threshold": "0.8"
    }
  },
  "etag": "\"1245f9435cd01ea8\"",
  "updateTime": "2024-06-03T05:00:05Z"
}

REST

如要更新設定,請對 recommenders.updateConfig 方法發出 PATCH 要求,並將 google.compute.RightSizeResourceRecommender 指定為建議事項 ID:

PATCH https://recommender.googleapis.com/v1/projects/PROJECT_ID/locations/ZONE/recommenders/google.compute.RightSizeResourceRecommender/config

{
  "name": "projects/PROJECT_ID/locations/ZONE/recommenders/google.compute.RightSizeResourceRecommender/config",
  "recommenderGenerationConfig": {
    "params": {
      "under_utilized_reservation_lookback_period": "P21D",
      "under_utilized_reservation_utilization_threshold": "0.8"
    }
  },
  "etag": "\"2f3c9b65cda6a4ba\""
}

更改下列內容:

  • PROJECT_ID:要修改建議事項設定的專案 ID。
  • ZONE:包含專案的可用區。

將要求主體儲存在檔案中,例如 config.json。接著,您可以使用類似下列的指令,在更新專案的建議事項設定時參照該檔案:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-H "x-goog-user-project: ${PROJECT_ID}" \
-d @config.json \
https://recommender.googleapis.com/v1/projects/$PROJECT_ID/locations/$ZONE/recommenders/google.compute.RightSizeResourceRecommender/config

POST 指令會傳回類似下列的回應主體,顯示您剛修改的參數和新設定。

{
  "name": "projects/PROJECT_ID/locations/ZONE/recommenders/google.compute.RightSizeResourceRecommender/config",
  "recommenderGenerationConfig": {
    "params": {
      "under_utilized_reservation_lookback_period": "P21D",
      "under_utilized_reservation_utilization_threshold": "0.8"
    }
  },
  "etag": "\"1245f9435cd01ea8\"",
  "updateTime": "2024-06-03T05:00:05Z"
}

後續步驟