使用 BigQuery 分析日志
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
BigQuery 是一款功能强大的分析工具。您可以使用它来存储长期日志,并对数据执行类似 SQL 的查询。如需使用 BigQuery 进行分析,您必须明确将日志路由到 BigQuery,如下一部分中所述。
将日志路由到 BigQuery
- 在日志浏览器中,创建一个用于隔离 Fleet Engine 日志的过滤条件:
Fleetengine.googleapis.com/Fleet
。
- 在“查询结果”窗格中,点击操作或更多操作菜单,然后选择创建接收器。
- 指定接收器名称(例如 FleetEngineLogsSink)。点击下一步。
- 在接收器目标位置中,选择 BigQuery 数据集。
- 在选择 BigQuery 数据集中,选择新建 BigQuery 数据集。
- 在创建数据集对话框中,输入数据集 ID。
- 保留所有其他设置不变,然后点击创建数据集。
- 选中使用分区表。点击下一步。
- 保持选择要包含在接收器中的日志和选择要从接收器中过滤掉的日志不变。
- 点击创建接收器。
您的日志现在应该开始填充 BigQuery 数据集,这可能需要一段时间。另请参阅将日志路由到支持的目标位置。
将日志数据路由到 BigQuery 后,系统会自动填充 FleetEngineLogs 数据集下的多个表,每个日志类型对应一个表:
- CreateVehicle
- GetVehicle
- ListVehicles
- SearchVehicles
- UpdateVehicle
- CreateTrip
- GetTrip
- UpdateTrip
- ListTrips
表名称采用以下格式:
project_id.data_set.log_name
例如,如果项目名为 test-project,数据集名称为 FleetEngineLogs,则 CreateTrip
表的名称如下:
test-project.FleetEngineLogs.fleetengine_googleapis_com_create_trip
BigQuery 查询示例
以下示例查询展示了如何在 BigQuery 中搜索不同的日志条目。
按小时分组的 CreateTrips 日志数量
SELECT TIMESTAMP_TRUNC(timestamp, HOUR) as hour,
count(*) as num_trips_created
FROM
`ProjectId.FleetEngineLogs.fleetengine_googleapis_com_create_trip`
GROUP BY hour
ORDER by hour
每辆车每小时的停靠次数
SELECT
jsonpayload_v1_updatevehiclelog.request.vehicleid AS vehicle,
TIMESTAMP_TRUNC(timestamp, HOUR) AS hour,
COUNT(*) AS num_stops
FROM
`ProjectId.FleetEngineLogs.fleetengine_googleapis_com_update__vehicle`
WHERE
ARRAY_LENGTH(jsonpayload_v1_updatevehiclelog.request.vehicle.remainingvehiclejourneysegments) > 0
AND jsonpayload_v1_updatevehiclelog.request.vehicle.remainingvehiclejourneysegments[
OFFSET
(0)].stop.state = 'VEHICLE_STOP_STATE_LOG_ARRIVED'
GROUP BY
1,
2
ORDER BY
2
例如,此查询可以告知您过去一小时内:
- 车辆 A 在第 12 小时完成了 10 次停靠,在第 13 小时完成了 8 次停靠。
- 车辆 B 在第 11 小时完成了 5 次停靠,在第 12 小时完成了 7 次停靠。
- 车辆 C 在第 13 小时完成了 12 次停靠,在第 14 小时完成了 9 次停靠。
另请参阅查看路由到 BigQuery 的日志。
将 BigQuery 与 Looker Studio 集成
BigQuery 可以与商业智能工具集成,以创建用于业务分析的信息中心。请参阅 Looker Studio。
以下示例展示了如何构建 Looker Studio 信息中心,以便在地图上直观呈现行程和车辆移动情况。
- 启动新的 Looker 数据洞察信息中心,然后选择 BigQuery 作为数据连接。
- 选择自定义查询,然后手动输入或选择应向哪个 Cloud 项目收取费用。
- 在查询框中输入以下任一查询。
按需行程查询示例
SELECT
timestamp,
labels.vehicle_id,
jsonpayload_v1_updatevehiclelog.response.lastlocation.location.latitude AS lat,
jsonpayload_v1_updatevehiclelog.response.lastlocation.location.longitude AS lng
FROM
`ProjectId.TableName.fleetengine_googleapis_com_update_vehicle`
计划任务示例查询
SELECT
labels.delivery_vehicle_id,
jsonpayload_v1_updatedeliveryvehiclelog.response.lastlocation.rawlocation.longitude as lat, jsonpayload_v1_updatedeliveryvehiclelog.response.lastlocation.rawlocation.latitude as lng
FROM `ProjectID.TableName.fleetengine_googleapis_com_update_delivery_vehicle`
- 选择图表类型为气泡地图,然后选择地理位置字段。
- 选择添加字段。
- 为该字段命名,然后添加以下公式:
CONCAT(lat, ",", lng)
。
- 将类型设置为 Geo->Latitude, Longitude。
- 您可以向信息中心添加控件来过滤数据。例如,选择日期范围过滤条件。
- 修改“日期范围”框以选择默认日期范围。
- 您可以为
vehicle_id
添加额外的下拉列表控件。借助这些控件,您可以直观呈现车辆的移动或行程中的移动。
Looker Studio 输出示例:

后续步骤
如需遵循数据保留政策,请参阅限制日志保留。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eBigQuery enables analysis of Fleet Engine logs via SQL-like queries after routing logs to a BigQuery dataset.\u003c/p\u003e\n"],["\u003cp\u003eRouting logs to BigQuery involves creating a sink in the Logs Explorer and selecting a BigQuery dataset as the destination.\u003c/p\u003e\n"],["\u003cp\u003eBigQuery automatically populates tables for each Fleet Engine log type under the specified dataset.\u003c/p\u003e\n"],["\u003cp\u003eExample queries demonstrate how to analyze trip creation, vehicle stops, and other data points within BigQuery.\u003c/p\u003e\n"],["\u003cp\u003eBigQuery integrates with Looker Studio for creating dashboards and visualizing data, such as vehicle movement on a map.\u003c/p\u003e\n"]]],[],null,["BigQuery is a powerful tool for performing analytics. You can use it to store\nlonger-term logs and to perform SQL-like queries against the data. To use\nBigQuery for analysis, you must explicitly route your logs to BigQuery, as\ndescribed in the next section.\n\nRoute logs to BigQuery\n\n1. In the [Logs Explorer](https://cloud.google.com/logging/docs/view/logs-explorer-interface), create a filter that isolates the Fleet Engine logs: `Fleetengine.googleapis.com/Fleet`.\n2. In the **Query Results pane** , click the **Actions** or **More Actions** menu and choose **Create Sink**.\n3. Specify a sink name (for example, *FleetEngineLogsSink* ). Click **Next**.\n4. In the **Sink Destination** , select **BigQuery dataset**.\n5. In **Select BigQuery dataset** , select **Create new BigQuery dataset**.\n6. In the **Create dataset** dialog, enter a **Dataset ID**.\n7. Leave everything else as is and click **Create dataset**.\n8. Check **Use partitioned tables** . Click **Next**.\n9. Leave **Choose logs to include in sink** and **Choose logs to filter out of\n sink** as they are.\n10. Click **Create Sink**.\n\nYour logs should now begin to populate the BigQuery dataset, which can take a\nshort while. See also [Route logs to supported destinations](https://cloud.google.com/logging/docs/export/configure_export_v2).\n\nOnce you are routing log data to BigQuery, several tables under the\n*FleetEngineLogs* dataset are automatically populated, one for each log type:\n\n- CreateVehicle\n- GetVehicle\n- ListVehicles\n- SearchVehicles\n- UpdateVehicle\n- CreateTrip\n- GetTrip\n- UpdateTrip\n- ListTrips\n\nThe table names use the following pattern: \n\n project_id.data_set.log_name\n\nFor example, if the project is called *test-project* and the dataset name is\n*FleetEngineLogs* , the `CreateTrip` table has the following name: \n\n test-project.FleetEngineLogs.fleetengine_googleapis_com_create_trip\n\nExample queries for BigQuery\n\nThe following example queries show how you can search for different log entries\nin BigQuery.\n\nNumber of CreateTrips logs grouped by hour \n\n SELECT TIMESTAMP_TRUNC(timestamp, HOUR) as hour,\n count(*) as num_trips_created\n FROM\n `ProjectId.FleetEngineLogs.fleetengine_googleapis_com_create_trip`\n GROUP BY hour\n ORDER by hour\n\nNumber of stops per vehicle per hour \n\n SELECT\n jsonpayload_v1_updatevehiclelog.request.vehicleid AS vehicle,\n TIMESTAMP_TRUNC(timestamp, HOUR) AS hour,\n COUNT(*) AS num_stops\n FROM\n `ProjectId.FleetEngineLogs.fleetengine_googleapis_com_update__vehicle`\n WHERE\n ARRAY_LENGTH(jsonpayload_v1_updatevehiclelog.request.vehicle.remainingvehiclejourneysegments) \u003e 0\n AND jsonpayload_v1_updatevehiclelog.request.vehicle.remainingvehiclejourneysegments[\n OFFSET\n (0)].stop.state = 'VEHICLE_STOP_STATE_LOG_ARRIVED'\n GROUP BY\n 1,\n 2\n ORDER BY\n 2\n\nFor example, this query could tell you that in the last hour:\n\n- Vehicle A completed 10 stops in hour 12 and 8 stops in hour 13.\n- Vehicle B completed 5 stops in hour 11 and 7 stops in hour 12.\n- Vehicle C completed 12 stops in hour 13 and 9 stops in hour 14.\n\nSee also [View logs routed to BigQuery](https://cloud.google.com/logging/docs/export/bigquery).\n\nIntegrate BigQuery with Looker Studio\n\nBigQuery can be integrated with business intelligence tools to create dashboards\nfor business analytics. See [Looker Studio](https://lookerstudio.google.com).\n\nThe following example shows how to build a Looker Studio dashboard for\nvisualizing trips and vehicle movements on a map.\n\n1. Launch a new [Looker Studio](https://lookerstudio.google.com) dashboard and select **BigQuery** as the data connection.\n2. Select **Custom Query** and manually enter or select the Cloud Project to which it should be billed.\n3. Enter one of the following queries into the query box.\n\nOn-demand trips example query \n\n SELECT\n timestamp,\n labels.vehicle_id,\n jsonpayload_v1_updatevehiclelog.response.lastlocation.location.latitude AS lat,\n jsonpayload_v1_updatevehiclelog.response.lastlocation.location.longitude AS lng\n FROM\n `ProjectId.TableName.fleetengine_googleapis_com_update_vehicle`\n\nScheduled Tasks example query \n\n SELECT\n labels.delivery_vehicle_id,\n jsonpayload_v1_updatedeliveryvehiclelog.response.lastlocation.rawlocation.longitude as lat, jsonpayload_v1_updatedeliveryvehiclelog.response.lastlocation.rawlocation.latitude as lng\n FROM `ProjectID.TableName.fleetengine_googleapis_com_update_delivery_vehicle`\n\n1. Select **Chart Type as Bubble Map** , and then select the **location** field.\n2. Select **Add a Field**.\n3. Name the field and add the following formula: `CONCAT(lat, \",\", lng)`.\n4. Set the type to **Geo-\\\u003eLatitude, Longitude**.\n5. You can add controls to the dashboard to filter data. For example, select the **Date-range** filter.\n6. Edit the date range box to select a default date range.\n7. You can add additional *drop-down list* controls for `vehicle_id`. With these controls, you can visualize the movement of the vehicle or the movement within a trip.\n\nLooker Studio example output:\n\nWhat's next\n\nTo comply with data retention policies, see [Restrict log\nretention](/maps/documentation/mobility/operations/cloud-logging/reduce-cost)."]]