cloud-sql-postgres-monitor

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Usage

使用说明

All scripts can be executed using Node.js. Replace
<param_name>
and
<param_value>
with actual values.
Bash:
node <skill_dir>/scripts/<script_name>.js '{"<param_name>": "<param_value>"}'
PowerShell:
node <skill_dir>/scripts/<script_name>.js '{\"<param_name>\": \"<param_value>\"}'
Note: The scripts automatically load the environment variables from various .env files. Do not ask the user to set vars unless skill executions fails due to env var absence.
所有脚本均可通过Node.js执行。将
<param_name>
<param_value>
替换为实际值。
Bash:
node <skill_dir>/scripts/<script_name>.js '{"<param_name>": "<param_value>"}'
PowerShell:
node <skill_dir>/scripts/<script_name>.js '{\"<param_name>\": \"<param_value>\"}'
注意:脚本会自动从各种.env文件加载环境变量。除非因缺少环境变量导致技能执行失败,否则无需让用户设置变量。

Scripts

脚本

get_query_metrics

get_query_metrics

Fetches query level cloudmonitoring data (timeseries metrics) for queries running in Postgres instance using a PromQL query. Take projectID and instanceID from the user for which the metrics timeseries data needs to be fetched. To use this tool, you must provide the Google Cloud
projectId
and a PromQL
query
.
Generate PromQL
query
for Postgres query metrics. Use the provided metrics and rules to construct queries, Get the labels like
instance_id
,
query_hash
from user intent. If query_hash is provided then use the per_query metrics. Query hash and query id are same.
Defaults:
  1. Interval: Use a default interval of
    5m
    for
    _over_time
    aggregation functions unless a different window is specified by the user.
PromQL Query Examples:
  1. Basic Time Series:
    avg_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m])
  2. Top K:
    topk(30, avg_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))
  3. Mean:
    avg(avg_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))
  4. Minimum:
    min(min_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))
  5. Maximum:
    max(max_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))
  6. Sum:
    sum(avg_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))
  7. Count streams:
    count(avg_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))
  8. Percentile with groupby on resource_id, database:
    quantile by ("resource_id","database")(0.99,avg_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))
Available Metrics List: metricname. description. monitored resource. labels. resource_id label format is
project_id:instance_id
which is actually instance id only. aggregate is the aggregated values for all query stats, Use aggregate metrics if query id is not provided. For perquery metrics do not fetch querystring unless specified by user specifically. Have the aggregation on query hash to avoid fetching the querystring. Do not use latency metrics for anything.
  1. cloudsql.googleapis.com/database/postgresql/insights/aggregate/latencies
    : Aggregated query latency distribution.
    cloudsql_instance_database
    .
    user
    ,
    client_addr
    ,
    project_id
    ,
    resource_id
    .
  2. cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time
    : Accumulated aggregated query execution time since the last sample.
    cloudsql_instance_database
    .
    user
    ,
    client_addr
    ,
    project_id
    ,
    resource_id
    .
  3. cloudsql.googleapis.com/database/postgresql/insights/aggregate/io_time
    : Accumulated aggregated IO time since the last sample.
    cloudsql_instance_database
    .
    user
    ,
    client_addr
    ,
    io_type
    ,
    project_id
    ,
    resource_id
    .
  4. cloudsql.googleapis.com/database/postgresql/insights/aggregate/lock_time
    : Accumulated aggregated lock wait time since the last sample.
    cloudsql_instance_database
    .
    user
    ,
    client_addr
    ,
    lock_type
    ,
    project_id
    ,
    resource_id
    .
  5. cloudsql.googleapis.com/database/postgresql/insights/aggregate/row_count
    : Aggregated number of retrieved or affected rows since the last sample.
    cloudsql_instance_database
    .
    user
    ,
    client_addr
    ,
    project_id
    ,
    resource_id
    .
  6. cloudsql.googleapis.com/database/postgresql/insights/aggregate/shared_blk_access_count
    : Aggregated shared blocks accessed by statement execution.
    cloudsql_instance_database
    .
    user
    ,
    client_addr
    ,
    access_type
    ,
    project_id
    ,
    resource_id
    .
  7. cloudsql.googleapis.com/database/postgresql/insights/perquery/latencies
    : Per query latency distribution.
    cloudsql_instance_database
    .
    user
    ,
    client_addr
    ,
    querystring
    ,
    query_hash
    ,
    project_id
    ,
    resource_id
    .
  8. cloudsql.googleapis.com/database/postgresql/insights/perquery/execution_time
    : Accumulated execution times per user per database per query.
    cloudsql_instance_database
    .
    user
    ,
    client_addr
    ,
    querystring
    ,
    query_hash
    ,
    project_id
    ,
    resource_id
    .
  9. cloudsql.googleapis.com/database/postgresql/insights/perquery/io_time
    : Accumulated IO time since the last sample per query.
    cloudsql_instance_database
    .
    user
    ,
    client_addr
    ,
    io_type
    ,
    querystring
    ,
    query_hash
    ,
    project_id
    ,
    resource_id
    .
  10. cloudsql.googleapis.com/database/postgresql/insights/perquery/lock_time
    : Accumulated lock wait time since the last sample per query.
    cloudsql_instance_database
    .
    user
    ,
    client_addr
    ,
    lock_type
    ,
    querystring
    ,
    query_hash
    ,
    project_id
    ,
    resource_id
    .
  11. cloudsql.googleapis.com/database/postgresql/insights/perquery/row_count
    : The number of retrieved or affected rows since the last sample per query.
    cloudsql_instance_database
    .
    user
    ,
    client_addr
    ,
    querystring
    ,
    query_hash
    ,
    project_id
    ,
    resource_id
    .
  12. cloudsql.googleapis.com/database/postgresql/insights/perquery/shared_blk_access_count
    : Shared blocks accessed by statement execution per query.
    cloudsql_instance_database
    .
    user
    ,
    client_addr
    ,
    access_type
    ,
    querystring
    ,
    query_hash
    ,
    project_id
    ,
    resource_id
    .
  13. cloudsql.googleapis.com/database/postgresql/insights/pertag/latencies
    : Query latency distribution.
    cloudsql_instance_database
    .
    user
    ,
    client_addr
    ,
    action
    ,
    application
    ,
    controller
    ,
    db_driver
    ,
    framework
    ,
    route
    ,
    tag_hash
    ,
    project_id
    ,
    resource_id
    .
  14. cloudsql.googleapis.com/database/postgresql/insights/pertag/execution_time
    : Accumulated execution times since the last sample.
    cloudsql_instance_database
    .
    user
    ,
    client_addr
    ,
    action
    ,
    application
    ,
    controller
    ,
    db_driver
    ,
    framework
    ,
    route
    ,
    tag_hash
    ,
    project_id
    ,
    resource_id
    .
  15. cloudsql.googleapis.com/database/postgresql/insights/pertag/io_time
    : Accumulated IO time since the last sample per tag.
    cloudsql_instance_database
    .
    user
    ,
    client_addr
    ,
    action
    ,
    application
    ,
    controller
    ,
    db_driver
    ,
    framework
    ,
    route
    ,
    io_type
    ,
    tag_hash
    ,
    project_id
    ,
    resource_id
    .
  16. cloudsql.googleapis.com/database/postgresql/insights/pertag/lock_time
    : Accumulated lock wait time since the last sample per tag.
    cloudsql_instance_database
    .
    user
    ,
    client_addr
    ,
    action
    ,
    application
    ,
    controller
    ,
    db_driver
    ,
    framework
    ,
    route
    ,
    lock_type
    ,
    tag_hash
    ,
    project_id
    ,
    resource_id
    .
  17. cloudsql.googleapis.com/database/postgresql/insights/pertag/shared_blk_access_count
    : Shared blocks accessed by statement execution per tag.
    cloudsql_instance_database
    .
    user
    ,
    client_addr
    ,
    action
    ,
    application
    ,
    controller
    ,
    db_driver
    ,
    framework
    ,
    route
    ,
    access_type
    ,
    tag_hash
    ,
    project_id
    ,
    resource_id
    .
  18. cloudsql.googleapis.com/database/postgresql/insights/pertag/row_count
    : The number of retrieved or affected rows since the last sample per tag.
    cloudsql_instance_database
    .
    user
    ,
    client_addr
    ,
    action
    ,
    application
    ,
    controller
    ,
    db_driver
    ,
    framework
    ,
    route
    ,
    tag_hash
    ,
    project_id
    ,
    resource_id
    .
使用PromQL查询获取Postgres实例中运行的查询的查询级云监控数据(时间序列指标)。向用户获取需要获取指标时间序列数据的projectID和instanceID。 使用此工具时,你必须提供Google Cloud的
projectId
和PromQL
query
为Postgres查询指标生成PromQL
query
。使用提供的指标和规则构建查询,从用户意图中获取
instance_id
query_hash
等标签。如果提供了query_hash,则使用per_query指标。Query hash和query id是相同的。
默认设置:
  1. 时间间隔:除非用户指定不同的窗口,否则
    _over_time
    聚合函数使用默认的
    5m
    时间间隔。
PromQL查询示例:
  1. 基础时间序列:
    avg_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m])
  2. Top K:
    topk(30, avg_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))
  3. 平均值:
    avg(avg_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))
  4. 最小值:
    min(min_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))
  5. 最大值:
    max(max_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))
  6. 求和:
    sum(avg_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))
  7. 流计数:
    count(avg_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))
  8. 按resource_id、database分组的百分位数:
    quantile by ("resource_id","database")(0.99,avg_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))
可用指标列表:指标名称. 描述. 监控资源. 标签. resource_id标签格式为
project_id:instance_id
,实际上仅为实例ID。aggregate是所有查询统计的聚合值,如果未提供query id,则使用聚合指标。对于perquery指标,除非用户特别指定,否则不要获取querystring。对query hash进行聚合以避免获取querystring。不要将延迟指标用于任何用途。
  1. cloudsql.googleapis.com/database/postgresql/insights/aggregate/latencies
    :聚合查询延迟分布。
    cloudsql_instance_database
    user
    ,
    client_addr
    ,
    project_id
    ,
    resource_id
    .
  2. cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time
    :自上次采样以来累计的聚合查询执行时间。
    cloudsql_instance_database
    user
    ,
    client_addr
    ,
    project_id
    ,
    resource_id
    .
  3. cloudsql.googleapis.com/database/postgresql/insights/aggregate/io_time
    :自上次采样以来累计的聚合IO时间。
    cloudsql_instance_database
    user
    ,
    client_addr
    ,
    io_type
    ,
    project_id
    ,
    resource_id
    .
  4. cloudsql.googleapis.com/database/postgresql/insights/aggregate/lock_time
    :自上次采样以来累计的聚合锁等待时间。
    cloudsql_instance_database
    user
    ,
    client_addr
    ,
    lock_type
    ,
    project_id
    ,
    resource_id
    .
  5. cloudsql.googleapis.com/database/postgresql/insights/aggregate/row_count
    :自上次采样以来聚合的检索或受影响行数。
    cloudsql_instance_database
    user
    ,
    client_addr
    ,
    project_id
    ,
    resource_id
    .
  6. cloudsql.googleapis.com/database/postgresql/insights/aggregate/shared_blk_access_count
    :语句执行访问的聚合共享块数量。
    cloudsql_instance_database
    user
    ,
    client_addr
    ,
    access_type
    ,
    project_id
    ,
    resource_id
    .
  7. cloudsql.googleapis.com/database/postgresql/insights/perquery/latencies
    :单查询延迟分布。
    cloudsql_instance_database
    user
    ,
    client_addr
    ,
    querystring
    ,
    query_hash
    ,
    project_id
    ,
    resource_id
    .
  8. cloudsql.googleapis.com/database/postgresql/insights/perquery/execution_time
    :每个用户、每个数据库、每个查询的累计执行时间。
    cloudsql_instance_database
    user
    ,
    client_addr
    ,
    querystring
    ,
    query_hash
    ,
    project_id
    ,
    resource_id
    .
  9. cloudsql.googleapis.com/database/postgresql/insights/perquery/io_time
    :自上次采样以来每个查询的累计IO时间。
    cloudsql_instance_database
    user
    ,
    client_addr
    ,
    io_type
    ,
    querystring
    ,
    query_hash
    ,
    project_id
    ,
    resource_id
    .
  10. cloudsql.googleapis.com/database/postgresql/insights/perquery/lock_time
    :自上次采样以来每个查询的累计锁等待时间。
    cloudsql_instance_database
    user
    ,
    client_addr
    ,
    lock_type
    ,
    querystring
    ,
    query_hash
    ,
    project_id
    ,
    resource_id
    .
  11. cloudsql.googleapis.com/database/postgresql/insights/perquery/row_count
    :自上次采样以来每个查询检索或受影响的行数。
    cloudsql_instance_database
    user
    ,
    client_addr
    ,
    querystring
    ,
    query_hash
    ,
    project_id
    ,
    resource_id
    .
  12. cloudsql.googleapis.com/database/postgresql/insights/perquery/shared_blk_access_count
    :每个查询语句执行访问的共享块数量。
    cloudsql_instance_database
    user
    ,
    client_addr
    ,
    access_type
    ,
    querystring
    ,
    query_hash
    ,
    project_id
    ,
    resource_id
    .
  13. cloudsql.googleapis.com/database/postgresql/insights/pertag/latencies
    :查询延迟分布。
    cloudsql_instance_database
    user
    ,
    client_addr
    ,
    action
    ,
    application
    ,
    controller
    ,
    db_driver
    ,
    framework
    ,
    route
    ,
    tag_hash
    ,
    project_id
    ,
    resource_id
    .
  14. cloudsql.googleapis.com/database/postgresql/insights/pertag/execution_time
    :自上次采样以来累计的执行时间。
    cloudsql_instance_database
    user
    ,
    client_addr
    ,
    action
    ,
    application
    ,
    controller
    ,
    db_driver
    ,
    framework
    ,
    route
    ,
    tag_hash
    ,
    project_id
    ,
    resource_id
    .
  15. cloudsql.googleapis.com/database/postgresql/insights/pertag/io_time
    :自上次采样以来每个标签的累计IO时间。
    cloudsql_instance_database
    user
    ,
    client_addr
    ,
    action
    ,
    application
    ,
    controller
    ,
    db_driver
    ,
    framework
    ,
    route
    ,
    io_type
    ,
    tag_hash
    ,
    project_id
    ,
    resource_id
    .
  16. cloudsql.googleapis.com/database/postgresql/insights/pertag/lock_time
    :自上次采样以来每个标签的累计锁等待时间。
    cloudsql_instance_database
    user
    ,
    client_addr
    ,
    action
    ,
    application
    ,
    controller
    ,
    db_driver
    ,
    framework
    ,
    route
    ,
    lock_type
    ,
    tag_hash
    ,
    project_id
    ,
    resource_id
    .
  17. cloudsql.googleapis.com/database/postgresql/insights/pertag/shared_blk_access_count
    :每个标签的语句执行访问的共享块数量。
    cloudsql_instance_database
    user
    ,
    client_addr
    ,
    action
    ,
    application
    ,
    controller
    ,
    db_driver
    ,
    framework
    ,
    route
    ,
    access_type
    ,
    tag_hash
    ,
    project_id
    ,
    resource_id
    .
  18. cloudsql.googleapis.com/database/postgresql/insights/pertag/row_count
    :自上次采样以来每个标签检索或受影响的行数。
    cloudsql_instance_database
    user
    ,
    client_addr
    ,
    action
    ,
    application
    ,
    controller
    ,
    db_driver
    ,
    framework
    ,
    route
    ,
    tag_hash
    ,
    project_id
    ,
    resource_id
    .

Parameters

参数

NameTypeDescriptionRequiredDefault
projectIdstringThe Id of the Google Cloud project.Yes
querystringThe promql query to execute.Yes

名称类型描述必填默认值
projectIdstringGoogle Cloud项目的ID。
querystring要执行的PromQL查询。

get_query_plan

get_query_plan

Generate a PostgreSQL EXPLAIN plan in JSON format for a single SQL statement—without executing it. This returns the optimizer's estimated plan, costs, and rows (no ANALYZE, no extra options). Use in production safely for plan inspection, regression checks, and query tuning workflows.
为单个SQL语句生成JSON格式的PostgreSQL EXPLAIN执行计划——无需执行该语句。返回优化器的预估计划、成本和行数(不包含ANALYZE,无额外选项)。可安全用于生产环境中的计划检查、回归测试和查询调优工作流。

Parameters

参数

NameTypeDescriptionRequiredDefault
querystringThe SQL statement for which you want to generate plan (omit the EXPLAIN keyword).Yes

名称类型描述必填默认值
querystring要生成执行计划的SQL语句(省略EXPLAIN关键字)。

get_system_metrics

get_system_metrics

Fetches system level cloudmonitoring data (timeseries metrics) for a Postgres instance using a PromQL query. Take projectId and instanceId from the user for which the metrics timeseries data needs to be fetched. To use this tool, you must provide the Google Cloud
projectId
and a PromQL
query
.
Generate PromQL
query
for Postgres system metrics. Use the provided metrics and rules to construct queries, Get the labels like
instance_id
from user intent.
Defaults:
  1. Interval: Use a default interval of
    5m
    for
    _over_time
    aggregation functions unless a different window is specified by the user.
PromQL Query Examples:
  1. Basic Time Series:
    avg_over_time({"__name__"="cloudsql.googleapis.com/database/cpu/utilization","monitored_resource"="cloudsql_database","project_id"="my-projectId","database_id"="my-projectId:my-instanceId"}[5m])
  2. Top K:
    topk(30, avg_over_time({"__name__"="cloudsql.googleapis.com/database/cpu/utilization","monitored_resource"="cloudsql_database","project_id"="my-projectId","database_id"="my-projectId:my-instanceId"}[5m]))
  3. Mean:
    avg(avg_over_time({"__name__"="cloudsql.googleapis.com/database/cpu/utilization","monitored_resource"="cloudsql_database","project_id"="my-projectId","database_id"="my-projectId:my-instanceId"}[5m]))
  4. Minimum:
    min(min_over_time({"__name__"="cloudsql.googleapis.com/database/cpu/utilization","monitored_resource"="cloudsql_database","project_id"="my-projectId","database_id"="my-projectId:my-instanceId"}[5m]))
  5. Maximum:
    max(max_over_time({"__name__"="cloudsql.googleapis.com/database/cpu/utilization","monitored_resource"="cloudsql_database","project_id"="my-projectId","database_id"="my-projectId:my-instanceId"}[5m]))
  6. Sum:
    sum(avg_over_time({"__name__"="cloudsql.googleapis.com/database/cpu/utilization","monitored_resource"="cloudsql_database","project_id"="my-projectId","database_id"="my-projectId:my-instanceId"}[5m]))
  7. Count streams:
    count(avg_over_time({"__name__"="cloudsql.googleapis.com/database/cpu/utilization","monitored_resource"="cloudsql_database","project_id"="my-projectId","database_id"="my-projectId:my-instanceId"}[5m]))
  8. Percentile with groupby on database_id:
    quantile by ("database_id")(0.99,avg_over_time({"__name__"="cloudsql.googleapis.com/database/cpu/utilization","monitored_resource"="cloudsql_database","project_id"="my-projectId","database_id"="my-projectId:my-instanceId"}[5m]))
Available Metrics List: metricname. description. monitored resource. labels. database_id is actually the instance id and the format is
project_id:instance_id
.
  1. cloudsql.googleapis.com/database/postgresql/new_connection_count
    : Count of new connections added to the postgres instance.
    cloudsql_database
    .
    database
    ,
    project_id
    ,
    database_id
    .
  2. cloudsql.googleapis.com/database/postgresql/backends_in_wait
    : Number of backends in wait in postgres instance.
    cloudsql_database
    .
    backend_type
    ,
    wait_event
    ,
    wait_event_type
    ,
    project_id
    ,
    database_id
    .
  3. cloudsql.googleapis.com/database/postgresql/transaction_count
    : Delta count of number of transactions.
    cloudsql_database
    .
    database
    ,
    transaction_type
    ,
    project_id
    ,
    database_id
    .
  4. cloudsql.googleapis.com/database/memory/components
    : Memory stats components in percentage as usage, cache and free memory for the database.
    cloudsql_database
    .
    component
    ,
    project_id
    ,
    database_id
    .
  5. cloudsql.googleapis.com/database/postgresql/external_sync/max_replica_byte_lag
    : Replication lag in bytes for Postgres External Server (ES) replicas. Aggregated across all DBs on the replica.
    cloudsql_database
    .
    project_id
    ,
    database_id
    .
  6. cloudsql.googleapis.com/database/cpu/utilization
    : Current CPU utilization represented as a percentage of the reserved CPU that is currently in use. Values are typically numbers between 0.0 and 1.0 (but might exceed 1.0). Charts display the values as a percentage between 0% and 100% (or more).
    cloudsql_database
    .
    project_id
    ,
    database_id
    .
  7. cloudsql.googleapis.com/database/disk/bytes_used_by_data_type
    : Data utilization in bytes.
    cloudsql_database
    .
    data_type
    ,
    project_id
    ,
    database_id
    .
  8. cloudsql.googleapis.com/database/disk/read_ops_count
    : Delta count of data disk read IO operations.
    cloudsql_database
    .
    project_id
    ,
    database_id
    .
  9. cloudsql.googleapis.com/database/disk/write_ops_count
    : Delta count of data disk write IO operations.
    cloudsql_database
    .
    project_id
    ,
    database_id
    .
  10. cloudsql.googleapis.com/database/postgresql/num_backends_by_state
    : Number of connections to the Cloud SQL PostgreSQL instance, grouped by its state.
    cloudsql_database
    .
    database
    ,
    state
    ,
    project_id
    ,
    database_id
    .
  11. cloudsql.googleapis.com/database/postgresql/num_backends
    : Number of connections to the Cloud SQL PostgreSQL instance.
    cloudsql_database
    .
    database
    ,
    project_id
    ,
    database_id
    .
  12. cloudsql.googleapis.com/database/network/received_bytes_count
    : Delta count of bytes received through the network.
    cloudsql_database
    .
    project_id
    ,
    database_id
    .
  13. cloudsql.googleapis.com/database/network/sent_bytes_count
    : Delta count of bytes sent through the network.
    cloudsql_database
    .
    destination
    ,
    project_id
    ,
    database_id
    .
  14. cloudsql.googleapis.com/database/postgresql/deadlock_count
    : Number of deadlocks detected for this database.
    cloudsql_database
    .
    database
    ,
    project_id
    ,
    database_id
    .
  15. cloudsql.googleapis.com/database/postgresql/blocks_read_count
    : Number of disk blocks read by this database. The source field distingushes actual reads from disk versus reads from buffer cache.
    cloudsql_database
    .
    database
    ,
    source
    ,
    project_id
    ,
    database_id
    .
  16. cloudsql.googleapis.com/database/postgresql/tuples_processed_count
    : Number of tuples(rows) processed for a given database for operations like insert, update or delete.
    cloudsql_database
    .
    operation_type
    ,
    database
    ,
    project_id
    ,
    database_id
    .
  17. cloudsql.googleapis.com/database/postgresql/tuple_size
    : Number of tuples (rows) in the database.
    cloudsql_database
    .
    database
    ,
    tuple_state
    ,
    project_id
    ,
    database_id
    .
  18. cloudsql.googleapis.com/database/postgresql/vacuum/oldest_transaction_age
    : Age of the oldest transaction yet to be vacuumed in the Cloud SQL PostgreSQL instance, measured in number of transactions that have happened since the oldest transaction.
    cloudsql_database
    .
    oldest_transaction_type
    ,
    project_id
    ,
    database_id
    .
  19. cloudsql.googleapis.com/database/replication/log_archive_success_count
    : Number of successful attempts for archiving replication log files.
    cloudsql_database
    .
    project_id
    ,
    database_id
    .
  20. cloudsql.googleapis.com/database/replication/log_archive_failure_count
    : Number of failed attempts for archiving replication log files.
    cloudsql_database
    .
    project_id
    ,
    database_id
    .
  21. cloudsql.googleapis.com/database/postgresql/transaction_id_utilization
    : Current utilization represented as a percentage of transaction IDs consumed by the Cloud SQL PostgreSQL instance. Values are typically numbers between 0.0 and 1.0. Charts display the values as a percentage between 0% and 100% .
    cloudsql_database
    .
    project_id
    ,
    database_id
    .
  22. cloudsql.googleapis.com/database/postgresql/num_backends_by_application
    : Number of connections to the Cloud SQL PostgreSQL instance, grouped by applications.
    cloudsql_database
    .
    application
    ,
    project_id
    ,
    database_id
    .
  23. cloudsql.googleapis.com/database/postgresql/tuples_fetched_count
    : Total number of rows fetched as a result of queries per database in the PostgreSQL instance.
    cloudsql_database
    .
    database
    ,
    project_id
    ,
    database_id
    .
  24. cloudsql.googleapis.com/database/postgresql/tuples_returned_count
    : Total number of rows scanned while processing the queries per database in the PostgreSQL instance.
    cloudsql_database
    .
    database
    ,
    project_id
    ,
    database_id
    .
  25. cloudsql.googleapis.com/database/postgresql/temp_bytes_written_count
    : Total amount of data (in bytes) written to temporary files by the queries per database.
    cloudsql_database
    .
    database
    ,
    project_id
    ,
    database_id
    .
  26. cloudsql.googleapis.com/database/postgresql/temp_files_written_count
    : Total number of temporary files used for writing data while performing algorithms such as join and sort.
    cloudsql_database
    .
    database
    ,
    project_id
    ,
    database_id
    .
使用PromQL查询获取Postgres实例的系统级云监控数据(时间序列指标)。向用户获取需要获取指标时间序列数据的projectId和instanceId。 使用此工具时,你必须提供Google Cloud的
projectId
和PromQL
query
为Postgres系统指标生成PromQL
query
。使用提供的指标和规则构建查询,从用户意图中获取
instance_id
等标签。
默认设置:
  1. 时间间隔:除非用户指定不同的窗口,否则
    _over_time
    聚合函数使用默认的
    5m
    时间间隔。
PromQL查询示例:
  1. 基础时间序列:
    avg_over_time({"__name__"="cloudsql.googleapis.com/database/cpu/utilization","monitored_resource"="cloudsql_database","project_id"="my-projectId","database_id"="my-projectId:my-instanceId"}[5m])
  2. Top K:
    topk(30, avg_over_time({"__name__"="cloudsql.googleapis.com/database/cpu/utilization","monitored_resource"="cloudsql_database","project_id"="my-projectId","database_id"="my-projectId:my-instanceId"}[5m]))
  3. 平均值:
    avg(avg_over_time({"__name__"="cloudsql.googleapis.com/database/cpu/utilization","monitored_resource"="cloudsql_database","project_id"="my-projectId","database_id"="my-projectId:my-instanceId"}[5m]))
  4. 最小值:
    min(min_over_time({"__name__"="cloudsql.googleapis.com/database/cpu/utilization","monitored_resource"="cloudsql_database","project_id"="my-projectId","database_id"="my-projectId:my-instanceId"}[5m]))
  5. 最大值:
    max(max_over_time({"__name__"="cloudsql.googleapis.com/database/cpu/utilization","monitored_resource"="cloudsql_database","project_id"="my-projectId","database_id"="my-projectId:my-instanceId"}[5m]))
  6. 求和:
    sum(avg_over_time({"__name__"="cloudsql.googleapis.com/database/cpu/utilization","monitored_resource"="cloudsql_database","project_id"="my-projectId","database_id"="my-projectId:my-instanceId"}[5m]))
  7. 流计数:
    count(avg_over_time({"__name__"="cloudsql.googleapis.com/database/cpu/utilization","monitored_resource"="cloudsql_database","project_id"="my-projectId","database_id"="my-projectId:my-instanceId"}[5m]))
  8. 按database_id分组的百分位数:
    quantile by ("database_id")(0.99,avg_over_time({"__name__"="cloudsql.googleapis.com/database/cpu/utilization","monitored_resource"="cloudsql_database","project_id"="my-projectId","database_id"="my-projectId:my-instanceId"}[5m]))
可用指标列表:指标名称. 描述. 监控资源. 标签. database_id实际上是实例ID,格式为
project_id:instance_id
  1. cloudsql.googleapis.com/database/postgresql/new_connection_count
    :添加到Postgres实例的新连接数。
    cloudsql_database
    database
    ,
    project_id
    ,
    database_id
    .
  2. cloudsql.googleapis.com/database/postgresql/backends_in_wait
    :Postgres实例中处于等待状态的后端进程数。
    cloudsql_database
    backend_type
    ,
    wait_event
    ,
    wait_event_type
    ,
    project_id
    ,
    database_id
    .
  3. cloudsql.googleapis.com/database/postgresql/transaction_count
    :事务的增量计数。
    cloudsql_database
    database
    ,
    transaction_type
    ,
    project_id
    ,
    database_id
    .
  4. cloudsql.googleapis.com/database/memory/components
    :数据库内存统计组件,以使用率、缓存和空闲内存的百分比表示。
    cloudsql_database
    component
    ,
    project_id
    ,
    database_id
    .
  5. cloudsql.googleapis.com/database/postgresql/external_sync/max_replica_byte_lag
    :Postgres外部服务器(ES)副本的复制延迟(字节数)。跨副本上的所有数据库聚合。
    cloudsql_database
    project_id
    ,
    database_id
    .
  6. cloudsql.googleapis.com/database/cpu/utilization
    :当前CPU使用率,表示为已使用的预留CPU的百分比。值通常在0.0到1.0之间(但可能超过1.0)。图表显示为0%到100%(或更高)的百分比。
    cloudsql_database
    project_id
    ,
    database_id
    .
  7. cloudsql.googleapis.com/database/disk/bytes_used_by_data_type
    :按数据类型划分的数据使用量(字节数)。
    cloudsql_database
    data_type
    ,
    project_id
    ,
    database_id
    .
  8. cloudsql.googleapis.com/database/disk/read_ops_count
    :数据磁盘读取IO操作的增量计数。
    cloudsql_database
    project_id
    ,
    database_id
    .
  9. cloudsql.googleapis.com/database/disk/write_ops_count
    :数据磁盘写入IO操作的增量计数。
    cloudsql_database
    project_id
    ,
    database_id
    .
  10. cloudsql.googleapis.com/database/postgresql/num_backends_by_state
    :按状态分组的Cloud SQL PostgreSQL实例连接数。
    cloudsql_database
    database
    ,
    state
    ,
    project_id
    ,
    database_id
    .
  11. cloudsql.googleapis.com/database/postgresql/num_backends
    :Cloud SQL PostgreSQL实例的连接数。
    cloudsql_database
    database
    ,
    project_id
    ,
    database_id
    .
  12. cloudsql.googleapis.com/database/network/received_bytes_count
    :通过网络接收的字节数增量计数。
    cloudsql_database
    project_id
    ,
    database_id
    .
  13. cloudsql.googleapis.com/database/network/sent_bytes_count
    :通过网络发送的字节数增量计数。
    cloudsql_database
    destination
    ,
    project_id
    ,
    database_id
    .
  14. cloudsql.googleapis.com/database/postgresql/deadlock_count
    :此数据库检测到的死锁数。
    cloudsql_database
    database
    ,
    project_id
    ,
    database_id
    .
  15. cloudsql.googleapis.com/database/postgresql/blocks_read_count
    :此数据库读取的磁盘块数。source字段区分实际从磁盘读取与从缓冲缓存读取。
    cloudsql_database
    database
    ,
    source
    ,
    project_id
    ,
    database_id
    .
  16. cloudsql.googleapis.com/database/postgresql/tuples_processed_count
    :给定数据库中处理的元组(行)数,适用于插入、更新或删除等操作。
    cloudsql_database
    operation_type
    ,
    database
    ,
    project_id
    ,
    database_id
    .
  17. cloudsql.googleapis.com/database/postgresql/tuple_size
    :数据库中的元组(行)数。
    cloudsql_database
    database
    ,
    tuple_state
    ,
    project_id
    ,
    database_id
    .
  18. cloudsql.googleapis.com/database/postgresql/vacuum/oldest_transaction_age
    :Cloud SQL PostgreSQL实例中尚未清理的最旧事务的时长,以自该事务以来发生的事务数衡量。
    cloudsql_database
    oldest_transaction_type
    ,
    project_id
    ,
    database_id
    .
  19. cloudsql.googleapis.com/database/replication/log_archive_success_count
    :归档复制日志文件的成功尝试次数。
    cloudsql_database
    project_id
    ,
    database_id
    .
  20. cloudsql.googleapis.com/database/replication/log_archive_failure_count
    :归档复制日志文件的失败尝试次数。
    cloudsql_database
    project_id
    ,
    database_id
    .
  21. cloudsql.googleapis.com/database/postgresql/transaction_id_utilization
    :当前事务ID使用率,表示为Cloud SQL PostgreSQL实例已消耗的事务ID的百分比。值通常在0.0到1.0之间。图表显示为0%到100%的百分比。
    cloudsql_database
    project_id
    ,
    database_id
    .
  22. cloudsql.googleapis.com/database/postgresql/num_backends_by_application
    :按应用分组的Cloud SQL PostgreSQL实例连接数。
    cloudsql_database
    application
    ,
    project_id
    ,
    database_id
    .
  23. cloudsql.googleapis.com/database/postgresql/tuples_fetched_count
    :PostgreSQL实例中每个数据库的查询结果获取的总行数。
    cloudsql_database
    database
    ,
    project_id
    ,
    database_id
    .
  24. cloudsql.googleapis.com/database/postgresql/tuples_returned_count
    :PostgreSQL实例中每个数据库处理查询时扫描的总行数。
    cloudsql_database
    database
    ,
    project_id
    ,
    database_id
    .
  25. cloudsql.googleapis.com/database/postgresql/temp_bytes_written_count
    :PostgreSQL实例中每个数据库的查询写入临时文件的数据总量(字节数)。
    cloudsql_database
    database
    ,
    project_id
    ,
    database_id
    .
  26. cloudsql.googleapis.com/database/postgresql/temp_files_written_count
    :执行连接和排序等算法时用于写入数据的临时文件总数。
    cloudsql_database
    database
    ,
    project_id
    ,
    database_id
    .

Parameters

参数

NameTypeDescriptionRequiredDefault
projectIdstringThe Id of the Google Cloud project.Yes
querystringThe promql query to execute.Yes

名称类型描述必填默认值
projectIdstringGoogle Cloud项目的ID。
querystring要执行的PromQL查询。

list_active_queries

list_active_queries

List the top N (default 50) currently running queries (state='active') from pg_stat_activity, ordered by longest-running first. Returns pid, user, database, application_name, client_addr, state, wait_event_type/wait_event, backend/xact/query start times, computed query_duration, and the SQL text.
列出pg_stat_activity中当前运行的前N个(默认50个)查询(state='active'),按运行时长从长到短排序。返回pid、user、database、application_name、client_addr、state、wait_event_type/wait_event、backend/xact/query启动时间、计算出的query_duration以及SQL文本。

Parameters

参数

NameTypeDescriptionRequiredDefault
min_durationstringOptional: Only show queries running at least this long (e.g., '1 minute', '1 second', '2 seconds').No
1 minute
exclude_application_namesstringOptional: A comma-separated list of application names to exclude from the query results. This is useful for filtering out queries from specific applications (e.g., 'psql', 'pgAdmin', 'DBeaver'). The match is case-sensitive. Whitespace around commas and names is automatically handled. If this parameter is omitted, no applications are excluded.No``
limitintegerOptional: The maximum number of rows to return.No
50

名称类型描述必填默认值
min_durationstring可选:仅显示运行时长至少达到此值的查询(例如:'1 minute'、'1 second'、'2 seconds')。
1 minute
exclude_application_namesstring可选:要从查询结果中排除的应用名称列表,以逗号分隔。这有助于过滤掉特定应用的查询(例如:'psql'、'pgAdmin'、'DBeaver')。匹配区分大小写。自动处理逗号和名称周围的空格。如果省略此参数,则不排除任何应用。``
limitinteger可选:返回的最大行数。
50

list_database_stats

list_database_stats

Parameters

参数

NameTypeDescriptionRequiredDefault
database_namestringOptional: A specific database name pattern to search for.No``
include_templatesbooleanOptional: Whether to include template databases in the results.No
false
database_ownerstringOptional: A specific database owner name pattern to search for.No``
default_tablespacestringOptional: A specific default tablespace name pattern to search for.No``
order_bystringOptional: The field to order the results by. Valid values are 'size' and 'commit'.No``
limitintegerOptional: The maximum number of rows to return.No
10

名称类型描述必填默认值
database_namestring可选:要搜索的特定数据库名称模式。``
include_templatesboolean可选:是否在结果中包含模板数据库。
false
database_ownerstring可选:要搜索的特定数据库所有者名称模式。``
default_tablespacestring可选:要搜索的特定默认表空间名称模式。``
order_bystring可选:结果排序的字段。有效值为'size'和'commit'。``
limitinteger可选:返回的最大行数。
10

list_locks

list_locks

Identifies all locks held by active processes showing the process ID, user, query text, and an aggregated list of all transactions and specific locks (relation, mode, grant status) associated with each process.

识别活动进程持有的所有锁,显示进程ID、用户、查询文本,以及每个进程关联的所有事务和特定锁(关系、模式、授予状态)的聚合列表。

list_query_stats

list_query_stats

Lists performance statistics for executed queries ordered by total time, filtering by database name pattern if provided. This tool requires the pg_stat_statements extension to be installed. The tool returns the database name, query text, execution count, timing metrics (total, min, max, mean), rows affected, and buffer cache I/O statistics (hits and reads).
按总时间排序列出已执行查询的性能统计信息,如果提供数据库名称模式则进行过滤。此工具需要安装pg_stat_statements扩展。工具返回数据库名称、查询文本、执行次数、计时指标(总计、最小、最大、平均)、受影响行数以及缓冲缓存IO统计信息(命中数和读取数)。

Parameters

参数

NameTypeDescriptionRequiredDefault
database_namestringOptional: The database name to list query stats for.No``
limitintegerOptional: The maximum number of results to return. Defaults to 50.No
50

名称类型描述必填默认值
database_namestring可选:要列出查询统计信息的数据库名称。``
limitinteger可选:返回的最大结果数。默认值为50。
50

long_running_transactions

long_running_transactions

Identifies and lists database transactions that exceed a specified time limit. For each of the long running transactions, the output contains the process id, database name, user name, application name, client address, state, connection age, transaction age, query age, last activity age, wait event type, wait event, and query string.
识别并列出超过指定时间限制的数据库事务。对于每个长运行事务,输出包含进程ID、数据库名称、用户名、应用名称、客户端地址、状态、连接时长、事务时长、查询时长、最后活动时长、等待事件类型、等待事件以及查询字符串。

Parameters

参数

NameTypeDescriptionRequiredDefault
min_durationstringOptional: Only show transactions running at least this long (e.g., '1 minute', '15 minutes', '30 seconds').No
5 minutes
limitintegerOptional: The maximum number of long-running transactions to return. Defaults to 20.No
20

名称类型描述必填默认值
min_durationstring可选:仅显示运行时长至少达到此值的事务(例如:'1 minute'、'15 minutes'、'30 seconds')。
5 minutes
limitinteger可选:返回的长运行事务最大数量。默认值为20。
20