RESERVATIONS_TIMELINE 视图
INFORMATION_SCHEMA.RESERVATIONS_TIMELINE
视图显示每个预留管理项目每分钟的预留元数据时间片。要将槽用量与槽容量进行比较,您可以使用预留时间轴视图将预留信息与作业时间轴相结合。
架构
查询 INFORMATION_SCHEMA.RESERVATIONS_TIMELINE_BY_*
视图时,每个 BigQuery 预留的每分钟都有一行对应的查询结果。每个时间段均以一分钟为间隔,且刚好持续一分钟。
INFORMATION_SCHEMA.RESERVATIONS_TIMELINE_BY_PROJECT
视图具有如下架构:
列名 | 数据类型 | 值 |
---|---|---|
period_start |
TIMESTAMP |
一分钟时间段的开始时间。 |
project_id |
STRING |
预留管理项目的 ID。 |
project_number |
INTEGER |
项目编号。 |
reservation_name |
STRING |
预留的名称。 |
ignore_idle_slots |
BOOL |
如果已启用槽共享,则为 false,否则为 true。 |
slots_assigned |
INTEGER |
分配给此预留的槽数。 |
slots_max_assigned |
INTEGER |
此预留的槽容量上限,包括槽共享。如果 ignore_idle_slots 为 true,则此项与 slots_assigned 相同,否则为管理项目中所有容量承诺的槽总数。 |
autoscale |
STRUCT |
有关预留的自动扩缩容量的信息。包括以下字段:
|
reservation_id |
STRING |
用于与 jobs_timeline 表联接。格式为 project_id:location.reservation_name。 |
范围和语法
针对此视图的查询必须包含区域限定符。如果您未指定区域限定符,则会从所有区域检索元数据。下表说明了此视图的区域和资源范围:
视图名称 | 资源范围 | 区域范围 |
---|---|---|
[PROJECT_ID.]`region-REGION`.INFORMATION_SCHEMA.RESERVATIONS_TIMELINE[_BY_PROJECT] |
项目级 | REGION |
- 可选:
PROJECT_ID
:您的 Google Cloud 项目的 ID。如果未指定,则使用默认项目。 REGION
:任何数据集区域名称。例如region-us
。
示例
示例:查看每分钟的槽总用量
如需对非默认项目运行查询,请按以下格式添加项目 ID:
`PROJECT_ID`.`region-REGION_NAME`.INFORMATION_SCHEMA.JOBS_TIMELINE_BY_ORGANIZATION
`myproject`.`region-us`.INFORMATION_SCHEMA.JOBS_TIMELINE_BY_ORGANIZATION
。
以下示例展示分配给 YOUR_RESERVATION_ID
的所有项目在所有作业中的每分钟槽用量:
SELECT res.period_start, SUM(jobs.period_slot_ms) / 1000 / 60 AS period_slot_minutes, ANY_VALUE(res.slots_assigned) AS slot_assigned, ANY_VALUE(res.slots_max_assigned) AS slots_max_assigned FROM `region-us`.INFORMATION_SCHEMA.JOBS_TIMELINE_BY_ORGANIZATION jobs JOIN `region-us`.INFORMATION_SCHEMA.RESERVATIONS_TIMELINE res ON TIMESTAMP_TRUNC(jobs.period_start, MINUTE) = res.period_start AND jobs.reservation_id = res.reservation_id WHERE jobs.job_creation_time BETWEEN TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 DAY) AND CURRENT_TIMESTAMP() AND res.reservation_id = 'YOUR_RESERVATION_ID' AND (jobs.statement_type != "SCRIPT" OR jobs.statement_type IS NULL) -- Avoid duplicate byte counting in parent and children jobs. GROUP BY period_start ORDER BY period_start DESC;
结果类似于以下内容:
+-----------------------+---------------------+---------------+-------------------+ | period_start | period_slot_minutes | slots_assigned| slots_max_assigned| +-----------------------+---------------------+---------------+-------------------+ |2021-06-08 21:33:00 UTC| 100.000 | 100 | 100 | |2021-06-08 21:32:00 UTC| 96.753 | 100 | 100 | |2021-06-08 21:31:00 UTC| 41.668 | 100 | 100 | +-----------------------+---------------------+---------------+-------------------+
示例:预留的槽用量
以下示例展示了过去一天中每个预留的每分钟槽用量:
SELECT res.period_start, res.reservation_id, SUM(jobs.period_slot_ms) / 1000 / 60 AS period_slot_minutes, ANY_VALUE(res.slots_assigned) AS slots_assigned, ANY_VALUE(res.slots_max_assigned) AS slots_max_assigned, FROM `region-us`.INFORMATION_SCHEMA.JOBS_TIMELINE_BY_ORGANIZATION jobs JOIN `region-us`.INFORMATION_SCHEMA.RESERVATIONS_TIMELINE res ON TIMESTAMP_TRUNC(jobs.period_start, MINUTE) = res.period_start AND jobs.reservation_id = res.reservation_id WHERE jobs.job_creation_time BETWEEN TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 DAY) AND CURRENT_TIMESTAMP() AND (jobs.statement_type != "SCRIPT" OR jobs.statement_type IS NULL) -- Avoid duplicate byte counting in parent and children jobs. GROUP BY period_start, reservation_id ORDER BY period_start DESC, reservation_id;
结果类似于以下内容:
+-----------------------+----------------+---------------------+---------------+--------------------+ | period_start | reservation_id | period_slot_minutes | slot_assigned | slots_max_assigned | +-----------------------+----------------+---------------------+---------------+--------------------+ |2021-06-08 21:33:00 UTC| prod01 | 100.000 | 100 | 100 | |2021-06-08 21:33:00 UTC| prod02 | 177.201 | 200 | 500 | |2021-06-08 21:32:00 UTC| prod01 | 96.753 | 100 | 100 | |2021-06-08 21:32:00 UTC| prod02 | 182.329 | 200 | 500 | +-----------------------+----------------+---------------------+---------------+--------------------+