自動スケーリングを有効にすると、指定されたオプションに基づいてオートスケーラーがスケーリングに関する判断を下します。スケーリングに関するそれぞれの判断は Cloud Logging によって記録されます。ログ エクスプローラでこれらのログを読み込み、オートスケーラーのスケーリングに関する決定について理解を深めます。
ログ エクスプローラを使用すると、以下に関連するイベントを表示できます。
- マネージド インスタンス グループ(MIG)のサイズ変更に関するオートスケーラーの推奨事項オートスケーラーが MIG の新しい推奨サイズを計算する場合は、推奨サイズの変更はオートスケーラー ログに記述されます。ログエントリのサイズを変更するをご覧ください。
- オートスケーラーのステータスの変更。たとえば、想定どおりに動作していたオートスケーラーに問題が発生した場合、ステータスの変更がオートスケーラー ログに記述されます。ステータス変更のログエントリをご覧ください。
始める前に
- 自動スケーリングのドキュメントを読みます。
- ログを表示する対象となるアクティブなオートスケーラーを用意します。
- ログ エクスプローラの使用方法を確認します。
-
まだ設定していない場合は、認証を設定します。認証とは、Google Cloud サービスと API にアクセスするために ID を確認するプロセスです。ローカル開発環境からコードまたはサンプルを実行するには、次のいずれかのオプションを選択して Compute Engine に対する認証を行います。
Select the tab for how you plan to use the samples on this page:
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
-
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
- Set a default region and zone.
REST
このページの REST API サンプルをローカル開発環境で使用するには、gcloud CLI に指定した認証情報を使用します。
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
詳細については、 Google Cloud 認証ドキュメントの REST を使用して認証するをご覧ください。
-
オートスケーラー ログを表示する
オートスケーラー ログを表示するには、Google Cloud コンソール、gcloud CLI、または REST を使用します。
自動スケーリングをオンにしている場合は、Google Cloud コンソールで自動スケーリングのログを表示できます。
- [ログ エクスプローラ] ページに移動
- リソース プルダウン メニューをプルダウンし、[GCE オートスケーラー] を選択します。
次の手順で、MIG から [ログ エクスプローラ] ページに移動することもできます。
Google Cloud コンソールの [インスタンス グループ] ページに移動します。
ログを表示する MIG の名前をクリックします。
[モニタリング] タブをクリックします。
[モニタリング] タブで、[ログ] パネルはページの下部にあります。このパネルの最後にあるアイコンをクリックしてパネルを開きます。
[ログ エクスプローラ] ページを開くには、このパネルの [ログ エクスプローラで表示] アイコンをクリックします。デフォルトのクエリでログ エクスプローラが開き、MIG のすべてのオートスケーラー ログを取得します。
自動スケーリングに関連するすべてのログを検索するには、logging read
コマンドを使用します。次に例を示します。
gcloud logging read "resource.type=autoscaler" --limit 10 \ --format json
特定の MIG のオートスケーラー ログを表示するには、次のように instance_group_manager_name
を指定します。
gcloud logging read "resource.type=autoscaler AND \ resource.labels.instance_group_manager_name=example-igm" \ --limit 10 --format json
オートスケーラーのサイズ変更アクションに関連するログエントリを表示するには、compute.autoscalers.resize
メソッド名を指定します。
gcloud logging read "resource.type=autoscaler AND \ resource.labels.instance_group_manager_name=example-igm AND \ protoPayload.methodName=compute.autoscalers.resize" \ --limit 10 --format json
オートスケーラーのステータスの変更に関連するログエントリを表示するには、compute.autoscalers.changeStatus
メソッド名を指定します。
gcloud logging read "resource.type=autoscaler AND \ resource.labels.instance_group_manager_name=example-igm AND \ protoPayload.methodName=compute.autoscalers.changeStatus" \ --limit 10 --format json
Logging V2 API へのリクエストを発行します。リクエスト本文には、ログ検索で使用する filter
パラメータと、ログ表示の対象となる project
が含まれている必要があります。たとえば、特定の MIG のサイズ変更アクションのリストを取得するには次の要求を行います。
POST https://logging.googleapis.com/v2/entries:list { "filter": "resource.type=autoscaler AND resource.labels.instance_group_manager_name=example-igm AND protoPayload.methodName=compute.autoscalers.resize", "pageSize": 10, "resourceNames": [ "projects/example-project" ] }
特定の MIG のステータス変更のリストを取得するために次の要求を行います。
POST https://logging.googleapis.com/v2/entries:list { "filter": "resource.type=autoscaler AND resource.labels.instance_group_manager_name=example-igm AND protoPayload.methodName=compute.autoscalers.changeStatus", "pageSize": 10, "resourceNames": [ "projects/example-project" ] }
ログエントリのサイズを変更する
オートスケーラーで MIG の推奨サイズが計算されると、Compute Engine では新しい推奨サイズと古い推奨サイズをキャプチャするログエントリが作成されます。ゾーン MIG の場合、ログエントリには推奨サイズの変更理由もキャプチャされます。
以下は、ゾーン MIG のログエントリの例です。この例でオートスケーラーは、予測自動スケーリングに基づいて、目標の CPU 使用率 35%
を達成するには 3
個の VM が最適であると計算しています。ただし、自動スケーリング ポリシーで構成されるインスタンスの最大数は 2
です。そのため、オートスケーラーは推奨サイズを 2
に制限します。
{ insertId: "1l68z7sg4jw7kzo" logName: "projects/example-project/logs/cloudaudit.googleapis.com%2Fsystem_event" protoPayload: { @type: "type.googleapis.com/google.cloud.audit.AuditLog" metadata: { @type: "type.googleapis.com/autoscaler.AutoscalerSizeChangeExplanation" autoscalingMode: "ON" autoscalingReason: { scalingLimit: { limitPolicy: { maxNumReplicas: 2 } limitSize: 2 name: "MAX_INSTANCES" } scalingSignal: { calculatedSize: 3 calculationDetails: { servingSize: 1 signalTarget: 0.35 signalValue: 1.03533 } name: "PREDICTED_CPU_UTILIZATION" signalPolicy: { coolDownPeriodSec: 15 cpuUtilization: { predictiveMethod: "OPTIMIZE_AVAILABILITY" utilizationTarget: 0.35 } } } summary: "The autoscaler's recommended size changed from 1 to 2 because the autoscaler predicted that in 15 seconds the average CPU utilization across 1 serving instance will be 103.533%, which is above the utilization target of 35%. The calculated size was 3 to achieve the target CPU utilization but the size was limited by the maximum number of instances set in the autoscaling policy." } newSize: 2 oldSize: 1 } methodName: "compute.autoscalers.resize" resourceName: "projects/example-project/zones/us-east1-d/autoscalers/example-autoscaler" serviceName: "compute.googleapis.com" } receiveTimestamp: "2022-06-13T22:34:43.045973046Z" resource: { labels: { autoscaler_id: "1234567890123456789" autoscaler_name: "example-autoscaler" instance_group_manager_id: "1357908642148074125" instance_group_manager_name: "example-igm" location: "us-east1-d" project_id: "example-project" } type: "autoscaler" } severity: "INFO" timestamp: "2022-06-13T22:34:42.810216614Z" }
次の表に、ログエントリのフィールドの説明を示します。
プロパティ | 値 |
---|---|
autoscalingMode |
エントリがログに記録された時点の自動スケーリング モード。モードに関係なく、オートスケーラーは、ログで newSize で表される推奨サイズを計算します。自動スケーリング モードに応じて、オートスケーラーは MIG を次のように変更します。
|
autoscalingReason |
自動スケーリングの理由の詳細。このフィールドは、ゾーン MIG の場合のみ表示されます。 |
autoscalingReason.scalingLimit
|
calculatedSize を制限した自動スケーリング機能の詳細。これは、自動スケーリング シグナルに基づいてオートスケーラーが計算したサイズです。calculatedSize を制限できる自動スケーリング機能は、インスタンスの最大数または最小数、スケールインの制御、または安定化期間です。calculatedSize に適用される制限がない場合、scalingLimit フィールドはログに表示されません。 |
autoscalingReason.scalingLimit.limitPolicy
|
calculatedSize を制限した自動スケーリング機能の構成。安定化は自動スケーリングのデフォルトの機能であるため、安定化が calculatedSize を制限する場合、limitPolicy フィールドは設定されません。 |
autoscalingReason.scalingLimit.limitSize
|
calculatedSize を制限した自動スケーリング機能に基づく VM の数。 |
autoscalingReason.scalingLimit.name
|
calculatedSize を制限した自動スケーリング機能の名前。 |
autoscalingReason.scalingSignal
|
MIG が持つべき VM 数の計算に使用される自動スケーリング シグナルの詳細。自動スケーリング ポリシーに複数のシグナルがある場合、オートスケーラーは、最大数の VM を必要とするシグナルを考慮します。 |
autoscalingReason.scalingSignal.calculatedSize
|
MIG が持つべき VM の数は、自動スケーリング シグナルに基づきます。scalingLimit が適用される場合、オートスケーラーは calculatedSize を scalingLimit.limitSize に制限します。 |
autoscalingReason.scalingSignal.calculationDetails
|
calculatedSize の決定に使用される詳細。
|
autoscalingReason.scalingSignal.name
|
オートスケーラーが(ログ内で calculatedSize として表示される)VM の数を計算するために使用した自動スケーリング シグナルの名前。 |
autoscalingReason.scalingSignal.signalPolicy
|
オートスケーラーが calculatedSize を判断するために使用した自動スケーリング シグナルの構成。 |
autoscalingReason.summary
|
自動スケーリングの理由の説明。 |
newSize
|
MIG の現在の推奨サイズ。autoscalingMode に応じて、オートスケーラーは次のように MIG のサイズを newSize に変更します。
|
oldSize
|
MIG の以前の推奨サイズ。 |
ログエントリのその他のフィールドについては、監査ログエントリの形式をご覧ください。
ステータス変更のログエントリ
オートスケーラーのステータスが変わると、Compute Engine は新旧のステータス メッセージをキャプチャするログエントリを作成します。このステータス メッセージは、オートスケーラーが予期したとおりに動作しない理由を調べたり、過去に発生していた問題をデバッグしたりするために使用できます。一般的なステータス メッセージについては、よく返されるステータス メッセージをご覧ください。
protoPayload
の次のフィールドでは、新旧のステータスについて説明します。
metadata.newStatus.details
: オートスケーラーの新しいステータス。metadata.oldStatus.details
: オートスケーラーの以前のステータス。
以下に、ステータスの変更を示すログエントリの例を示します。この例では、ロード バランシング構成に問題があることを示す新しいステータス メッセージが表示されます。
{ insertId: "ivho6kg4icqfio" logName: "projects/example-project/logs/cloudaudit.googleapis.com%2Fsystem_event" protoPayload: { metadata: { @type: "type.googleapis.com/autoscaler.AutoscalerStatusChange" newStatus: { details: "The autoscaler is configured to scale based on a load balancing signal but the instance group has not received any utilization data from the load balancer or the utilization is constantly 0. Check that the load balancing configuration is working" } oldStatus: { details: "OK" }, methodName: "compute.autoscalers.changeStatus" resourceName: "projects/example-project/zones/us-east1-b/autoscalers/example-autoscaler" serviceName: "compute.googleapis.com" } receiveTimestamp: "2022-06-08T03:54:12.332329320Z" resource: { labels: { autoscaler_id: "1234567890123456789" autoscaler_name: "example-autoscaler" instance_group_manager_id: "1357908642148074125" instance_group_manager_name: "example-igm" location: "us-east1-b" project_id: "example-project" } type: "autoscaler" } severity: "INFO" timestamp: "2022-06-08T03:54:10.675416812Z" } }
ログエントリのその他のフィールドについては、監査ログエントリの形式をご覧ください。
次のステップ
- ログから受け取った情報を使用してオートスケーラーを更新する。
- オートスケーラーの決定方法について確認する。
- 自動スケーリングのオプションを確認する。