降低 Logging 費用
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
啟用記錄功能後,您必須設定記錄的轉送、儲存和保留方式。如果超出免付費的用量和保留期限,您可能需要支付額外的 Google Cloud 費用,才能擷取及保留記錄。請參閱 Google Cloud Observability 定價。
不過,您可以採用下列各節所述的任一方法,控管記錄費用。
減少記錄用量
您可以排除特定記錄項目,限制擷取的記錄資料量。詳情請參閱「排除記錄檔」。
以下範例說明常見的 Fleet Engine 情境,以及如何篩除特定記錄訊息來降低費用。
依方法篩選
您可以篩除唯讀方法,因為這些方法通常不需要用於資料分析或疑難排解。
下列指令會更新 _Default
記錄值區,排除 GetVehicle
記錄。
gcloud logging sinks update _Default \
--add-exclusion=name=ExcludeFleetengineGetVehicle,\
filter='jsonPayload.@type:"type.googleapis.com/maps.fleetengine.v1.GetVehicleLog"'
下列指令會更新 _Default
記錄值區,排除 GetTrip
記錄。
gcloud logging sinks update _Default \
--add-exclusion=name=ExcludeFleetengineGetTrip,filter=\
'jsonPayload.@type:"type.googleapis.com/maps.fleetengine.v1.GetTripLog"'
建立偵錯屬性
如要只查看特定車輛的記錄,請設定 debug
屬性。現在,系統會排除沒有 debug
屬性的車輛。
下列指令會更新 _Default
記錄值區,從 UpdateVehicle
記錄中排除沒有 debug
屬性的車輛。
gcloud logging sinks update _Default \
--add-exclusion=name=ExcludeFleetengineNonDebug,\
filter='resource.type="fleetengine.googleapis.com/Fleet"
log_name:"logs/fleetengine.googleapis.com%2Fupdate_vehicle"
jsonPayload.@type="type.googleapis.com/maps.fleetengine.v1.UpdateVehicleLog"
NOT jsonPayload.response.attributes.key="debug"'
篩選空白的受限用途記錄
啟用後,受限使用記錄會為每筆一般記錄建立子項記錄,即使作業未填入受限欄位也是如此。篩除這些空白的受限記錄,有助於降低成本。
下列指令會更新 RestrictedLogs
記錄值區,排除空白的受限 UpdateVehicle
記錄。
gcloud logging sinks update RestrictedLogs \
--add-exclusion=name=ExcludeFleetengineEmptyRestrictedVehicleLogs,\
filter='resource.type="fleetengine.googleapis.com/Fleet"
log_name:"logs/fleetengine.googleapis.com%2Fupdate_vehicle_restricted"
NOT jsonPayload.request.vehicle.currentRouteSegment:*
NOT jsonPayload.response.currentRouteSegment:*
NOT jsonPayload.response.waypoints:*'
匯出或傳送記錄
您可以將記錄檔轉送至其他 Google Cloud 或外部目的地,避免產生預設的擷取和儲存費用。請務必關閉記錄檔擷取功能 (如下一節所述),以免產生擷取費用。
請參閱「Cloud Logging 匯出」和「匯出記錄」。
關閉記錄擷取功能
如果您不打算使用 Fleet Engine 記錄,可以關閉擷取功能,避免產生 Cloud Logging 費用。根據預設,Fleet Engine 記錄會傳送至 _Default 記錄檔值區。
下列指令會更新 _Default 記錄 bucket,使其不會擷取 Fleet Engine 記錄。
gcloud logging sinks update _Default \
--log-filter='NOT LOG_ID("cloudaudit.googleapis.com/activity")
AND NOT LOG_ID("externalaudit.googleapis.com/activity")
AND NOT LOG_ID("cloudaudit.googleapis.com/system_event")
AND NOT LOG_ID("externalaudit.googleapis.com/system_event")
AND NOT LOG_ID("cloudaudit.googleapis.com/access_transparency")
AND NOT LOG_ID("externalaudit.googleapis.com/access_transparency")
AND NOT resource.type:"fleetengine.googleapis.com"'
另請參閱四個步驟,在預算內管理 Cloud Logging 費用。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-09-10 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-10 (世界標準時間)。"],[[["\u003cp\u003eWhen logging is enabled, you are responsible for routing, storage, and retention, which might incur extra Google Cloud costs if usage and retention limits for no charge are exceeded.\u003c/p\u003e\n"],["\u003cp\u003eYou can reduce logging costs by limiting ingested data, excluding specific log entries, routing logs to other destinations, or turning off log ingestion entirely.\u003c/p\u003e\n"],["\u003cp\u003eIf you choose to route logs to external destinations, ensure to turn off log ingestion to avoid extra charges.\u003c/p\u003e\n"],["\u003cp\u003eTo completely avoid Fleet Engine logging charges when you don't intend to use the logs, turn off ingestion for the _Default log bucket.\u003c/p\u003e\n"]]],["After enabling logging, you can manage costs by controlling log ingestion and retention. To reduce costs, limit ingested data by excluding specific log entries, like `GetVehicle` logs, using commands such as `gcloud logging sinks update`. You can also route logs to other destinations, avoiding default storage costs, by using Cloud Logging Exports. To completely prevent charges, you can turn off log ingestion using the provided command to update the `_Default` logging bucket to ignore specified logs including `fleetengine.googleapis.com`.\n"],null,["After logging is enabled, you are responsible for setting up how you would like\nto route, store, and retain your logs. You may incur extra Google Cloud costs\nfor log ingestion and retention if you exceed the usage and retention limits for\nno charge. See [Google Cloud Observability pricing](https://cloud.google.com/stackdriver/pricing).\n\nHowever, you can control logging costs by using any of the following approaches\ndescribed in the following sections.\n\nReduce logging usage\n\nYou can limit the amount of log data that is ingested by excluding certain log\nentries. See [Excluding logs](https://cloud.google.com/logging/docs/exclusions) for more details.\n\nThe following examples demonstrate common Fleet Engine scenarios and how to\nfilter out specific log messages to reduce costs.\n\nFilter by method\n\nYou can filter out read-only methods since these are typically not need for data\nanalysis or troubleshooting.\n\nThe following command updates the `_Default` logging bucket to exclude\n`GetVehicle` logs. \n\n gcloud logging sinks update _Default \\\n --add-exclusion=name=ExcludeFleetengineGetVehicle,\\\n filter='jsonPayload.@type:\"type.googleapis.com/maps.fleetengine.v1.GetVehicleLog\"'\n\nThe following command updates the `_Default` logging bucket to exclude\n`GetTrip` logs. \n\n gcloud logging sinks update _Default \\\n --add-exclusion=name=ExcludeFleetengineGetTrip,filter=\\\n 'jsonPayload.@type:\"type.googleapis.com/maps.fleetengine.v1.GetTripLog\"'\n\nCreate a debug attribute\n\nYou can reduce logs to specific vehicles only by setting a `debug` [attribute](https://developers.google.com/maps/documentation/mobility/fleet-engine/essentials/vehicles/on-demand-vehicle-fields#vehicle_attributes_field).\nAny vehicle that does not have the `debug` attribute will now be excluded.\n\nThe following command updates the `_Default` logging bucket to exclude vehicles\nwithout the `debug` attribute from the `UpdateVehicle` logs. \n\n gcloud logging sinks update _Default \\\n --add-exclusion=name=ExcludeFleetengineNonDebug,\\\n filter='resource.type=\"fleetengine.googleapis.com/Fleet\"\n log_name:\"logs/fleetengine.googleapis.com%2Fupdate_vehicle\"\n jsonPayload.@type=\"type.googleapis.com/maps.fleetengine.v1.UpdateVehicleLog\"\n NOT jsonPayload.response.attributes.key=\"debug\"'\n\nFilter empty restricted use logs\n\nWhen enabled, restricted use logs create a child log for every regular log,\neven if the operation doesn't populate restricted fields. Filtering out these\nempty restricted logs can reduce costs.\n\nThe following command updates the `RestrictedLogs` logging bucket to exclude\nempty restricted `UpdateVehicle` logs. \n\n gcloud logging sinks update RestrictedLogs \\\n --add-exclusion=name=ExcludeFleetengineEmptyRestrictedVehicleLogs,\\\n filter='resource.type=\"fleetengine.googleapis.com/Fleet\"\n log_name:\"logs/fleetengine.googleapis.com%2Fupdate_vehicle_restricted\"\n NOT jsonPayload.request.vehicle.currentRouteSegment:*\n NOT jsonPayload.response.currentRouteSegment:*\n NOT jsonPayload.response.waypoints:*'\n\nExport or route logs\n\nYou can route logs to other Google Cloud or external destinations to avoid the\ndefault ingestion and storage costs. Make sure you turn off log ingestion, as\ndescribed in the next section, to avoid ingestion costs.\n\nSee [Cloud Logging Exports](https://cloud.google.com/logging/docs/overview#store) and [Exporting\nlogs](https://cloud.google.com/logging/docs/export/configure_export_v2).\n\nTurn off log ingestion\n\nIf you don't intend to use Fleet Engine logs, you can avoid potential Cloud\nLogging charges by turning off ingestion. By default, Fleet Engine logs are\nrouted to the _Default log bucket.\n\nThe following command updates the _Default logging bucket to not ingest Fleet\nEngine logs. \n\n gcloud logging sinks update _Default \\\n --log-filter='NOT LOG_ID(\"cloudaudit.googleapis.com/activity\")\n AND NOT LOG_ID(\"externalaudit.googleapis.com/activity\")\n AND NOT LOG_ID(\"cloudaudit.googleapis.com/system_event\")\n AND NOT LOG_ID(\"externalaudit.googleapis.com/system_event\")\n AND NOT LOG_ID(\"cloudaudit.googleapis.com/access_transparency\")\n AND NOT LOG_ID(\"externalaudit.googleapis.com/access_transparency\")\n AND NOT resource.type:\"fleetengine.googleapis.com\"'\n\nSee also [Four steps to managing your Cloud Logging costs on a\nbudget](https://cloud.google.com/blog/products/devops-sre/cloud-logging-cost-management-best-practices)."]]