cloud-sql-postgres-monitor
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUsage
使用说明
All scripts can be executed using Node.js. Replace and with actual values.
<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>\"}'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 and a PromQL .
projectIdqueryGenerate PromQL for Postgres query metrics. Use the provided metrics and rules to construct queries, Get the labels like , from user intent. If query_hash is provided then use the per_query metrics. Query hash and query id are same.
queryinstance_idquery_hashDefaults:
- Interval: Use a default interval of for
5maggregation functions unless a different window is specified by the user._over_time
PromQL Query Examples:
- 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]) - 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])) - 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])) - 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])) - 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])) - 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])) - 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])) - 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 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.
project_id:instance_id- : Aggregated query latency distribution.
cloudsql.googleapis.com/database/postgresql/insights/aggregate/latencies.cloudsql_instance_database,user,client_addr,project_id.resource_id - : Accumulated aggregated query execution time since the last sample.
cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time.cloudsql_instance_database,user,client_addr,project_id.resource_id - : Accumulated aggregated IO time since the last sample.
cloudsql.googleapis.com/database/postgresql/insights/aggregate/io_time.cloudsql_instance_database,user,client_addr,io_type,project_id.resource_id - : Accumulated aggregated lock wait time since the last sample.
cloudsql.googleapis.com/database/postgresql/insights/aggregate/lock_time.cloudsql_instance_database,user,client_addr,lock_type,project_id.resource_id - : Aggregated number of retrieved or affected rows since the last sample.
cloudsql.googleapis.com/database/postgresql/insights/aggregate/row_count.cloudsql_instance_database,user,client_addr,project_id.resource_id - : Aggregated shared blocks accessed by statement execution.
cloudsql.googleapis.com/database/postgresql/insights/aggregate/shared_blk_access_count.cloudsql_instance_database,user,client_addr,access_type,project_id.resource_id - : Per query latency distribution.
cloudsql.googleapis.com/database/postgresql/insights/perquery/latencies.cloudsql_instance_database,user,client_addr,querystring,query_hash,project_id.resource_id - : Accumulated execution times per user per database per query.
cloudsql.googleapis.com/database/postgresql/insights/perquery/execution_time.cloudsql_instance_database,user,client_addr,querystring,query_hash,project_id.resource_id - : Accumulated IO time since the last sample per query.
cloudsql.googleapis.com/database/postgresql/insights/perquery/io_time.cloudsql_instance_database,user,client_addr,io_type,querystring,query_hash,project_id.resource_id - : Accumulated lock wait time since the last sample per query.
cloudsql.googleapis.com/database/postgresql/insights/perquery/lock_time.cloudsql_instance_database,user,client_addr,lock_type,querystring,query_hash,project_id.resource_id - : The number of retrieved or affected rows since the last sample per query.
cloudsql.googleapis.com/database/postgresql/insights/perquery/row_count.cloudsql_instance_database,user,client_addr,querystring,query_hash,project_id.resource_id - : Shared blocks accessed by statement execution per query.
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 - : Query latency distribution.
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 - : Accumulated execution times since the last sample.
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 - : Accumulated IO time since the last sample per tag.
cloudsql.googleapis.com/database/postgresql/insights/pertag/io_time.cloudsql_instance_database,user,client_addr,action,application,controller,db_driver,framework,route,io_type,tag_hash,project_id.resource_id - : Accumulated lock wait time since the last sample per tag.
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 - : Shared blocks accessed by statement execution per tag.
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 - : The number of retrieved or affected rows since the last sample per tag.
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
使用PromQL查询获取Postgres实例中运行的查询的查询级云监控数据(时间序列指标)。向用户获取需要获取指标时间序列数据的projectID和instanceID。
使用此工具时,你必须提供Google Cloud的和PromQL。
projectIdquery为Postgres查询指标生成PromQL。使用提供的指标和规则构建查询,从用户意图中获取、等标签。如果提供了query_hash,则使用per_query指标。Query hash和query id是相同的。
queryinstance_idquery_hash默认设置:
- 时间间隔:除非用户指定不同的窗口,否则聚合函数使用默认的
_over_time时间间隔。5m
PromQL查询示例:
- 基础时间序列:
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]) - 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])) - 平均值:
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])) - 最小值:
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])) - 最大值:
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])) - 求和:
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])) - 流计数:
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])) - 按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标签格式为,实际上仅为实例ID。aggregate是所有查询统计的聚合值,如果未提供query id,则使用聚合指标。对于perquery指标,除非用户特别指定,否则不要获取querystring。对query hash进行聚合以避免获取querystring。不要将延迟指标用于任何用途。
project_id:instance_id- :聚合查询延迟分布。
cloudsql.googleapis.com/database/postgresql/insights/aggregate/latencies。cloudsql_instance_database,user,client_addr,project_id.resource_id - :自上次采样以来累计的聚合查询执行时间。
cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time。cloudsql_instance_database,user,client_addr,project_id.resource_id - :自上次采样以来累计的聚合IO时间。
cloudsql.googleapis.com/database/postgresql/insights/aggregate/io_time。cloudsql_instance_database,user,client_addr,io_type,project_id.resource_id - :自上次采样以来累计的聚合锁等待时间。
cloudsql.googleapis.com/database/postgresql/insights/aggregate/lock_time。cloudsql_instance_database,user,client_addr,lock_type,project_id.resource_id - :自上次采样以来聚合的检索或受影响行数。
cloudsql.googleapis.com/database/postgresql/insights/aggregate/row_count。cloudsql_instance_database,user,client_addr,project_id.resource_id - :语句执行访问的聚合共享块数量。
cloudsql.googleapis.com/database/postgresql/insights/aggregate/shared_blk_access_count。cloudsql_instance_database,user,client_addr,access_type,project_id.resource_id - :单查询延迟分布。
cloudsql.googleapis.com/database/postgresql/insights/perquery/latencies。cloudsql_instance_database,user,client_addr,querystring,query_hash,project_id.resource_id - :每个用户、每个数据库、每个查询的累计执行时间。
cloudsql.googleapis.com/database/postgresql/insights/perquery/execution_time。cloudsql_instance_database,user,client_addr,querystring,query_hash,project_id.resource_id - :自上次采样以来每个查询的累计IO时间。
cloudsql.googleapis.com/database/postgresql/insights/perquery/io_time。cloudsql_instance_database,user,client_addr,io_type,querystring,query_hash,project_id.resource_id - :自上次采样以来每个查询的累计锁等待时间。
cloudsql.googleapis.com/database/postgresql/insights/perquery/lock_time。cloudsql_instance_database,user,client_addr,lock_type,querystring,query_hash,project_id.resource_id - :自上次采样以来每个查询检索或受影响的行数。
cloudsql.googleapis.com/database/postgresql/insights/perquery/row_count。cloudsql_instance_database,user,client_addr,querystring,query_hash,project_id.resource_id - :每个查询语句执行访问的共享块数量。
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 - :查询延迟分布。
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 - :自上次采样以来累计的执行时间。
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 - :自上次采样以来每个标签的累计IO时间。
cloudsql.googleapis.com/database/postgresql/insights/pertag/io_time。cloudsql_instance_database,user,client_addr,action,application,controller,db_driver,framework,route,io_type,tag_hash,project_id.resource_id - :自上次采样以来每个标签的累计锁等待时间。
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 - :每个标签的语句执行访问的共享块数量。
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 - :自上次采样以来每个标签检索或受影响的行数。
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
参数
| Name | Type | Description | Required | Default |
|---|---|---|---|---|
| projectId | string | The Id of the Google Cloud project. | Yes | |
| query | string | The promql query to execute. | Yes |
| 名称 | 类型 | 描述 | 必填 | 默认值 |
|---|---|---|---|---|
| projectId | string | Google Cloud项目的ID。 | 是 | |
| query | string | 要执行的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
参数
| Name | Type | Description | Required | Default |
|---|---|---|---|---|
| query | string | The SQL statement for which you want to generate plan (omit the EXPLAIN keyword). | Yes |
| 名称 | 类型 | 描述 | 必填 | 默认值 |
|---|---|---|---|---|
| query | string | 要生成执行计划的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 and a PromQL .
projectIdqueryGenerate PromQL for Postgres system metrics. Use the provided metrics and rules to construct queries, Get the labels like from user intent.
queryinstance_idDefaults:
- Interval: Use a default interval of for
5maggregation functions unless a different window is specified by the user._over_time
PromQL Query Examples:
- 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]) - 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])) - 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])) - 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])) - 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])) - 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])) - 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])) - 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- : Count of new connections added to the postgres instance.
cloudsql.googleapis.com/database/postgresql/new_connection_count.cloudsql_database,database,project_id.database_id - : Number of backends in wait in postgres instance.
cloudsql.googleapis.com/database/postgresql/backends_in_wait.cloudsql_database,backend_type,wait_event,wait_event_type,project_id.database_id - : Delta count of number of transactions.
cloudsql.googleapis.com/database/postgresql/transaction_count.cloudsql_database,database,transaction_type,project_id.database_id - : Memory stats components in percentage as usage, cache and free memory for the database.
cloudsql.googleapis.com/database/memory/components.cloudsql_database,component,project_id.database_id - : Replication lag in bytes for Postgres External Server (ES) replicas. Aggregated across all DBs on the replica.
cloudsql.googleapis.com/database/postgresql/external_sync/max_replica_byte_lag.cloudsql_database,project_id.database_id - : 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.googleapis.com/database/cpu/utilization.cloudsql_database,project_id.database_id - : Data utilization in bytes.
cloudsql.googleapis.com/database/disk/bytes_used_by_data_type.cloudsql_database,data_type,project_id.database_id - : Delta count of data disk read IO operations.
cloudsql.googleapis.com/database/disk/read_ops_count.cloudsql_database,project_id.database_id - : Delta count of data disk write IO operations.
cloudsql.googleapis.com/database/disk/write_ops_count.cloudsql_database,project_id.database_id - : Number of connections to the Cloud SQL PostgreSQL instance, grouped by its state.
cloudsql.googleapis.com/database/postgresql/num_backends_by_state.cloudsql_database,database,state,project_id.database_id - : Number of connections to the Cloud SQL PostgreSQL instance.
cloudsql.googleapis.com/database/postgresql/num_backends.cloudsql_database,database,project_id.database_id - : Delta count of bytes received through the network.
cloudsql.googleapis.com/database/network/received_bytes_count.cloudsql_database,project_id.database_id - : Delta count of bytes sent through the network.
cloudsql.googleapis.com/database/network/sent_bytes_count.cloudsql_database,destination,project_id.database_id - : Number of deadlocks detected for this database.
cloudsql.googleapis.com/database/postgresql/deadlock_count.cloudsql_database,database,project_id.database_id - : Number of disk blocks read by this database. The source field distingushes actual reads from disk versus reads from buffer cache.
cloudsql.googleapis.com/database/postgresql/blocks_read_count.cloudsql_database,database,source,project_id.database_id - : Number of tuples(rows) processed for a given database for operations like insert, update or delete.
cloudsql.googleapis.com/database/postgresql/tuples_processed_count.cloudsql_database,operation_type,database,project_id.database_id - : Number of tuples (rows) in the database.
cloudsql.googleapis.com/database/postgresql/tuple_size.cloudsql_database,database,tuple_state,project_id.database_id - : 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.googleapis.com/database/postgresql/vacuum/oldest_transaction_age.cloudsql_database,oldest_transaction_type,project_id.database_id - : Number of successful attempts for archiving replication log files.
cloudsql.googleapis.com/database/replication/log_archive_success_count.cloudsql_database,project_id.database_id - : Number of failed attempts for archiving replication log files.
cloudsql.googleapis.com/database/replication/log_archive_failure_count.cloudsql_database,project_id.database_id - : 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.googleapis.com/database/postgresql/transaction_id_utilization.cloudsql_database,project_id.database_id - : Number of connections to the Cloud SQL PostgreSQL instance, grouped by applications.
cloudsql.googleapis.com/database/postgresql/num_backends_by_application.cloudsql_database,application,project_id.database_id - : Total number of rows fetched as a result of queries per database in the PostgreSQL instance.
cloudsql.googleapis.com/database/postgresql/tuples_fetched_count.cloudsql_database,database,project_id.database_id - : Total number of rows scanned while processing the queries per database in the PostgreSQL instance.
cloudsql.googleapis.com/database/postgresql/tuples_returned_count.cloudsql_database,database,project_id.database_id - : Total amount of data (in bytes) written to temporary files by the queries per database.
cloudsql.googleapis.com/database/postgresql/temp_bytes_written_count.cloudsql_database,database,project_id.database_id - : Total number of temporary files used for writing data while performing algorithms such as join and sort.
cloudsql.googleapis.com/database/postgresql/temp_files_written_count.cloudsql_database,database,project_id.database_id
使用PromQL查询获取Postgres实例的系统级云监控数据(时间序列指标)。向用户获取需要获取指标时间序列数据的projectId和instanceId。
使用此工具时,你必须提供Google Cloud的和PromQL。
projectIdquery为Postgres系统指标生成PromQL。使用提供的指标和规则构建查询,从用户意图中获取等标签。
queryinstance_id默认设置:
- 时间间隔:除非用户指定不同的窗口,否则聚合函数使用默认的
_over_time时间间隔。5m
PromQL查询示例:
- 基础时间序列:
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]) - 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])) - 平均值:
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])) - 最小值:
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])) - 最大值:
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])) - 求和:
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])) - 流计数:
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])) - 按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- :添加到Postgres实例的新连接数。
cloudsql.googleapis.com/database/postgresql/new_connection_count。cloudsql_database,database,project_id.database_id - :Postgres实例中处于等待状态的后端进程数。
cloudsql.googleapis.com/database/postgresql/backends_in_wait。cloudsql_database,backend_type,wait_event,wait_event_type,project_id.database_id - :事务的增量计数。
cloudsql.googleapis.com/database/postgresql/transaction_count。cloudsql_database,database,transaction_type,project_id.database_id - :数据库内存统计组件,以使用率、缓存和空闲内存的百分比表示。
cloudsql.googleapis.com/database/memory/components。cloudsql_database,component,project_id.database_id - :Postgres外部服务器(ES)副本的复制延迟(字节数)。跨副本上的所有数据库聚合。
cloudsql.googleapis.com/database/postgresql/external_sync/max_replica_byte_lag。cloudsql_database,project_id.database_id - :当前CPU使用率,表示为已使用的预留CPU的百分比。值通常在0.0到1.0之间(但可能超过1.0)。图表显示为0%到100%(或更高)的百分比。
cloudsql.googleapis.com/database/cpu/utilization。cloudsql_database,project_id.database_id - :按数据类型划分的数据使用量(字节数)。
cloudsql.googleapis.com/database/disk/bytes_used_by_data_type。cloudsql_database,data_type,project_id.database_id - :数据磁盘读取IO操作的增量计数。
cloudsql.googleapis.com/database/disk/read_ops_count。cloudsql_database,project_id.database_id - :数据磁盘写入IO操作的增量计数。
cloudsql.googleapis.com/database/disk/write_ops_count。cloudsql_database,project_id.database_id - :按状态分组的Cloud SQL PostgreSQL实例连接数。
cloudsql.googleapis.com/database/postgresql/num_backends_by_state。cloudsql_database,database,state,project_id.database_id - :Cloud SQL PostgreSQL实例的连接数。
cloudsql.googleapis.com/database/postgresql/num_backends。cloudsql_database,database,project_id.database_id - :通过网络接收的字节数增量计数。
cloudsql.googleapis.com/database/network/received_bytes_count。cloudsql_database,project_id.database_id - :通过网络发送的字节数增量计数。
cloudsql.googleapis.com/database/network/sent_bytes_count。cloudsql_database,destination,project_id.database_id - :此数据库检测到的死锁数。
cloudsql.googleapis.com/database/postgresql/deadlock_count。cloudsql_database,database,project_id.database_id - :此数据库读取的磁盘块数。source字段区分实际从磁盘读取与从缓冲缓存读取。
cloudsql.googleapis.com/database/postgresql/blocks_read_count。cloudsql_database,database,source,project_id.database_id - :给定数据库中处理的元组(行)数,适用于插入、更新或删除等操作。
cloudsql.googleapis.com/database/postgresql/tuples_processed_count。cloudsql_database,operation_type,database,project_id.database_id - :数据库中的元组(行)数。
cloudsql.googleapis.com/database/postgresql/tuple_size。cloudsql_database,database,tuple_state,project_id.database_id - :Cloud SQL PostgreSQL实例中尚未清理的最旧事务的时长,以自该事务以来发生的事务数衡量。
cloudsql.googleapis.com/database/postgresql/vacuum/oldest_transaction_age。cloudsql_database,oldest_transaction_type,project_id.database_id - :归档复制日志文件的成功尝试次数。
cloudsql.googleapis.com/database/replication/log_archive_success_count。cloudsql_database,project_id.database_id - :归档复制日志文件的失败尝试次数。
cloudsql.googleapis.com/database/replication/log_archive_failure_count。cloudsql_database,project_id.database_id - :当前事务ID使用率,表示为Cloud SQL PostgreSQL实例已消耗的事务ID的百分比。值通常在0.0到1.0之间。图表显示为0%到100%的百分比。
cloudsql.googleapis.com/database/postgresql/transaction_id_utilization。cloudsql_database,project_id.database_id - :按应用分组的Cloud SQL PostgreSQL实例连接数。
cloudsql.googleapis.com/database/postgresql/num_backends_by_application。cloudsql_database,application,project_id.database_id - :PostgreSQL实例中每个数据库的查询结果获取的总行数。
cloudsql.googleapis.com/database/postgresql/tuples_fetched_count。cloudsql_database,database,project_id.database_id - :PostgreSQL实例中每个数据库处理查询时扫描的总行数。
cloudsql.googleapis.com/database/postgresql/tuples_returned_count。cloudsql_database,database,project_id.database_id - :PostgreSQL实例中每个数据库的查询写入临时文件的数据总量(字节数)。
cloudsql.googleapis.com/database/postgresql/temp_bytes_written_count。cloudsql_database,database,project_id.database_id - :执行连接和排序等算法时用于写入数据的临时文件总数。
cloudsql.googleapis.com/database/postgresql/temp_files_written_count。cloudsql_database,database,project_id.database_id
Parameters
参数
| Name | Type | Description | Required | Default |
|---|---|---|---|---|
| projectId | string | The Id of the Google Cloud project. | Yes | |
| query | string | The promql query to execute. | Yes |
| 名称 | 类型 | 描述 | 必填 | 默认值 |
|---|---|---|---|---|
| projectId | string | Google Cloud项目的ID。 | 是 | |
| query | string | 要执行的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
参数
| Name | Type | Description | Required | Default |
|---|---|---|---|---|
| min_duration | string | Optional: Only show queries running at least this long (e.g., '1 minute', '1 second', '2 seconds'). | No | |
| exclude_application_names | string | Optional: 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 | `` |
| limit | integer | Optional: The maximum number of rows to return. | No | |
| 名称 | 类型 | 描述 | 必填 | 默认值 |
|---|---|---|---|---|
| min_duration | string | 可选:仅显示运行时长至少达到此值的查询(例如:'1 minute'、'1 second'、'2 seconds')。 | 否 | |
| exclude_application_names | string | 可选:要从查询结果中排除的应用名称列表,以逗号分隔。这有助于过滤掉特定应用的查询(例如:'psql'、'pgAdmin'、'DBeaver')。匹配区分大小写。自动处理逗号和名称周围的空格。如果省略此参数,则不排除任何应用。 | 否 | `` |
| limit | integer | 可选:返回的最大行数。 | 否 | |
list_database_stats
list_database_stats
Parameters
参数
| Name | Type | Description | Required | Default |
|---|---|---|---|---|
| database_name | string | Optional: A specific database name pattern to search for. | No | `` |
| include_templates | boolean | Optional: Whether to include template databases in the results. | No | |
| database_owner | string | Optional: A specific database owner name pattern to search for. | No | `` |
| default_tablespace | string | Optional: A specific default tablespace name pattern to search for. | No | `` |
| order_by | string | Optional: The field to order the results by. Valid values are 'size' and 'commit'. | No | `` |
| limit | integer | Optional: The maximum number of rows to return. | No | |
| 名称 | 类型 | 描述 | 必填 | 默认值 |
|---|---|---|---|---|
| database_name | string | 可选:要搜索的特定数据库名称模式。 | 否 | `` |
| include_templates | boolean | 可选:是否在结果中包含模板数据库。 | 否 | |
| database_owner | string | 可选:要搜索的特定数据库所有者名称模式。 | 否 | `` |
| default_tablespace | string | 可选:要搜索的特定默认表空间名称模式。 | 否 | `` |
| order_by | string | 可选:结果排序的字段。有效值为'size'和'commit'。 | 否 | `` |
| limit | integer | 可选:返回的最大行数。 | 否 | |
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
参数
| Name | Type | Description | Required | Default |
|---|---|---|---|---|
| database_name | string | Optional: The database name to list query stats for. | No | `` |
| limit | integer | Optional: The maximum number of results to return. Defaults to 50. | No | |
| 名称 | 类型 | 描述 | 必填 | 默认值 |
|---|---|---|---|---|
| database_name | string | 可选:要列出查询统计信息的数据库名称。 | 否 | `` |
| limit | integer | 可选:返回的最大结果数。默认值为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
参数
| Name | Type | Description | Required | Default |
|---|---|---|---|---|
| min_duration | string | Optional: Only show transactions running at least this long (e.g., '1 minute', '15 minutes', '30 seconds'). | No | |
| limit | integer | Optional: The maximum number of long-running transactions to return. Defaults to 20. | No | |
| 名称 | 类型 | 描述 | 必填 | 默认值 |
|---|---|---|---|---|
| min_duration | string | 可选:仅显示运行时长至少达到此值的事务(例如:'1 minute'、'15 minutes'、'30 seconds')。 | 否 | |
| limit | integer | 可选:返回的长运行事务最大数量。默认值为20。 | 否 | |