alloydb-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 an AlloyDB instance.
To use this tool, you must provide the Google Cloud and a PromQL .
projectIdqueryGenerate the PromQL for AlloyDB query metrics using the provided metrics and rules. Get labels like , , and from the user's intent. If is provided, use the per-query metrics.
querycluster_idinstance_idquery_hashquery_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__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance"}[5m]) - Top K:
topk(30, avg_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance"}[5m])) - Mean:
avg(avg_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="my-instance","cluster_id"="my-cluster"}[5m])) - Minimum:
min(min_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance","cluster_id"="alloydb-cluster"}[5m])) - Maximum:
max(max_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance","cluster_id"="alloydb-cluster"}[5m])) - Sum:
sum(avg_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance","cluster_id"="alloydb-cluster"}[5m])) - Count streams:
count(avg_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance","cluster_id"="alloydb-cluster"}[5m])) - Percentile with groupby on instanceid, clusterid:
quantile by ("instance_id","cluster_id")(0.99,avg_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","cluster_id"="my-cluster","instance_id"="my-instance"}[5m]))
Available Metrics List: metricname. description. monitored resource. labels. 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.
- : Aggregated query latency distribution.
alloydb.googleapis.com/database/postgresql/insights/aggregate/latencies.alloydb.googleapis.com/Database,user.client_addr - : Accumulated aggregated query execution time since the last sample.
alloydb.googleapis.com/database/postgresql/insights/aggregate/execution_time.alloydb.googleapis.com/Database,user.client_addr - : Accumulated aggregated IO time since the last sample.
alloydb.googleapis.com/database/postgresql/insights/aggregate/io_time.alloydb.googleapis.com/Database,user,client_addr.io_type - : Accumulated aggregated lock wait time since the last sample.
alloydb.googleapis.com/database/postgresql/insights/aggregate/lock_time.alloydb.googleapis.com/Database,user,client_addr.lock_type - : Aggregated number of retrieved or affected rows since the last sample.
alloydb.googleapis.com/database/postgresql/insights/aggregate/row_count.alloydb.googleapis.com/Database,user.client_addr - : Aggregated shared blocks accessed by statement execution.
alloydb.googleapis.com/database/postgresql/insights/aggregate/shared_blk_access_count.alloydb.googleapis.com/Database,user,client_addr.access_type - : Per query latency distribution.
alloydb.googleapis.com/database/postgresql/insights/perquery/latencies.alloydb.googleapis.com/Database,user,client_addr,querystring.query_hash - : Accumulated execution times per user per database per query.
alloydb.googleapis.com/database/postgresql/insights/perquery/execution_time.alloydb.googleapis.com/Database,user,client_addr,querystring.query_hash - : Accumulated IO time since the last sample per query.
alloydb.googleapis.com/database/postgresql/insights/perquery/io_time.alloydb.googleapis.com/Database,user,client_addr,io_type,querystring.query_hash - : Accumulated lock wait time since the last sample per query.
alloydb.googleapis.com/database/postgresql/insights/perquery/lock_time.alloydb.googleapis.com/Database,user,client_addr,lock_type,querystring.query_hash - : The number of retrieved or affected rows since the last sample per query.
alloydb.googleapis.com/database/postgresql/insights/perquery/row_count.alloydb.googleapis.com/Database,user,client_addr,querystring.query_hash - : Shared blocks accessed by statement execution per query.
alloydb.googleapis.com/database/postgresql/insights/perquery/shared_blk_access_count.alloydb.googleapis.com/Database,user,client_addr,access_type,querystring.query_hash - : Query latency distribution.
alloydb.googleapis.com/database/postgresql/insights/pertag/latencies.alloydb.googleapis.com/Database,user,client_addr,action,application,controller,db_driver,framework,route.tag_hash - : Accumulated execution times since the last sample.
alloydb.googleapis.com/database/postgresql/insights/pertag/execution_time.alloydb.googleapis.com/Database,user,client_addr,action,application,controller,db_driver,framework,route.tag_hash - : Accumulated IO time since the last sample per tag.
alloydb.googleapis.com/database/postgresql/insights/pertag/io_time.alloydb.googleapis.com/Database,user,client_addr,action,application,controller,db_driver,framework,route,io_type.tag_hash - : Accumulated lock wait time since the last sample per tag.
alloydb.googleapis.com/database/postgresql/insights/pertag/lock_time.alloydb.googleapis.com/Database,user,client_addr,action,application,controller,db_driver,framework,route,lock_type.tag_hash - : Shared blocks accessed by statement execution per tag.
alloydb.googleapis.com/database/postgresql/insights/pertag/shared_blk_access_count.alloydb.googleapis.com/Database,user,client_addr,action,application,controller,db_driver,framework,route,access_type.tag_hash - : The number of retrieved or affected rows since the last sample per tag.
alloydb.googleapis.com/database/postgresql/insights/pertag/row_count.alloydb.googleapis.com/Database,user,client_addr,action,application,controller,db_driver,framework,route.tag_hash
获取AlloyDB实例中运行的查询的查询级云监控数据(时间序列指标)。
使用此工具时,你必须提供Google Cloud的和PromQL。
projectIdquery使用提供的指标和规则生成AlloyDB查询指标的PromQL。从用户的需求中获取、和等标签。如果提供了,则使用单查询指标。
querycluster_idinstance_idquery_hashquery_hash默认设置:
- 时间间隔:对于聚合函数,默认使用
_over_time的时间间隔,除非用户指定了不同的窗口。5m
PromQL查询示例:
- 基础时间序列:
avg_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance"}[5m]) - Top K:
topk(30, avg_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance"}[5m])) - 平均值:
avg(avg_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="my-instance","cluster_id"="my-cluster"}[5m])) - 最小值:
min(min_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance","cluster_id"="alloydb-cluster"}[5m])) - 最大值:
max(max_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance","cluster_id"="alloydb-cluster"}[5m])) - 求和:
sum(avg_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance","cluster_id"="alloydb-cluster"}[5m])) - 流计数:
count(avg_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance","cluster_id"="alloydb-cluster"}[5m])) - 按实例ID、集群ID分组的百分位数:
quantile by ("instance_id","cluster_id")(0.99,avg_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","cluster_id"="my-cluster","instance_id"="my-instance"}[5m]))
可用指标列表:指标名称、描述、监控资源、标签。aggregate是所有查询统计的聚合值,如果未提供查询ID,请使用聚合指标。对于单查询指标,除非用户特别指定,否则不要获取querystring。基于query_hash进行聚合,避免获取querystring。不要将延迟指标用于任何场景。
- :聚合查询延迟分布。
alloydb.googleapis.com/database/postgresql/insights/aggregate/latencies。alloydb.googleapis.com/Database、user。client_addr - :自上次采样以来的累计聚合查询执行时间。
alloydb.googleapis.com/database/postgresql/insights/aggregate/execution_time。alloydb.googleapis.com/Database、user。client_addr - :自上次采样以来的累计聚合IO时间。
alloydb.googleapis.com/database/postgresql/insights/aggregate/io_time。alloydb.googleapis.com/Database、user、client_addr。io_type - :自上次采样以来的累计聚合锁等待时间。
alloydb.googleapis.com/database/postgresql/insights/aggregate/lock_time。alloydb.googleapis.com/Database、user、client_addr。lock_type - :自上次采样以来检索或影响的聚合行数。
alloydb.googleapis.com/database/postgresql/insights/aggregate/row_count。alloydb.googleapis.com/Database、user。client_addr - :语句执行访问的聚合共享块数。
alloydb.googleapis.com/database/postgresql/insights/aggregate/shared_blk_access_count。alloydb.googleapis.com/Database、user、client_addr。access_type - :单查询延迟分布。
alloydb.googleapis.com/database/postgresql/insights/perquery/latencies。alloydb.googleapis.com/Database、user、client_addr、querystring。query_hash - :每个用户、每个数据库、每个查询的累计执行时间。
alloydb.googleapis.com/database/postgresql/insights/perquery/execution_time。alloydb.googleapis.com/Database、user、client_addr、querystring。query_hash - :自上次采样以来每个查询的累计IO时间。
alloydb.googleapis.com/database/postgresql/insights/perquery/io_time。alloydb.googleapis.com/Database、user、client_addr、io_type、querystring。query_hash - :自上次采样以来每个查询的累计锁等待时间。
alloydb.googleapis.com/database/postgresql/insights/perquery/lock_time。alloydb.googleapis.com/Database、user、client_addr、lock_type、querystring。query_hash - :自上次采样以来每个查询检索或影响的行数。
alloydb.googleapis.com/database/postgresql/insights/perquery/row_count。alloydb.googleapis.com/Database、user、client_addr、querystring。query_hash - :每个查询语句执行访问的共享块数。
alloydb.googleapis.com/database/postgresql/insights/perquery/shared_blk_access_count。alloydb.googleapis.com/Database、user、client_addr、access_type、querystring。query_hash - :查询延迟分布。
alloydb.googleapis.com/database/postgresql/insights/pertag/latencies。alloydb.googleapis.com/Database、user、client_addr、action、application、controller、db_driver、framework、route。tag_hash - :自上次采样以来的累计执行时间。
alloydb.googleapis.com/database/postgresql/insights/pertag/execution_time。alloydb.googleapis.com/Database、user、client_addr、action、application、controller、db_driver、framework、route。tag_hash - :自上次采样以来每个标签的累计IO时间。
alloydb.googleapis.com/database/postgresql/insights/pertag/io_time。alloydb.googleapis.com/Database、user、client_addr、action、application、controller、db_driver、framework、route、io_type。tag_hash - :自上次采样以来每个标签的累计锁等待时间。
alloydb.googleapis.com/database/postgresql/insights/pertag/lock_time。alloydb.googleapis.com/Database、user、client_addr、action、application、controller、db_driver、framework、route、lock_type。tag_hash - :每个标签的语句执行访问的共享块数。
alloydb.googleapis.com/database/postgresql/insights/pertag/shared_blk_access_count。alloydb.googleapis.com/Database、user、client_addr、action、application、controller、db_driver、framework、route、access_type。tag_hash - :自上次采样以来每个标签检索或影响的行数。
alloydb.googleapis.com/database/postgresql/insights/pertag/row_count。alloydb.googleapis.com/Database、user、client_addr、action、application、controller、db_driver、framework、route。tag_hash
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 an AlloyDB cluster, instance.
To use this tool, you must provide the Google Cloud and a PromQL .
projectIdqueryGenerate the PromQL for AlloyDB system metrics using the provided metrics and rules. Get labels like and from the user's intent.
querycluster_idinstance_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__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance"}[5m]) - Top K:
topk(30, avg_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance"}[5m])) - Mean:
avg(avg_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="my-instance","cluster_id"="my-cluster"}[5m])) - Minimum:
min(min_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance","cluster_id"="alloydb-cluster"}[5m])) - Maximum:
max(max_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance","cluster_id"="alloydb-cluster"}[5m])) - Sum:
sum(avg_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance","cluster_id"="alloydb-cluster"}[5m])) - Count streams:
count(avg_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance","cluster_id"="alloydb-cluster"}[5m])) - Percentile with groupby on instanceid, clusterid:
quantile by ("instance_id","cluster_id")(0.99,avg_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","cluster_id"="my-cluster","instance_id"="my-instance"}[5m]))
Available Metrics List: metricname. description. monitored resource. labels
- : The percentage of CPU being used on an instance.
alloydb.googleapis.com/instance/cpu/average_utilization.alloydb.googleapis.com/Instance,cluster_id.instance_id - : Maximum CPU utilization across all currently serving nodes of the instance from 0 to 100.
alloydb.googleapis.com/instance/cpu/maximum_utilization.alloydb.googleapis.com/Instance,cluster_id.instance_id - : The total AlloyDB storage in bytes across the entire cluster.
alloydb.googleapis.com/cluster/storage/usage.alloydb.googleapis.com/Cluster.cluster_id - : The number of read replicas connected to the primary instance.
alloydb.googleapis.com/instance/postgres/replication/replicas.alloydb.googleapis.com/Instance,cluster_id,instance_id,state.replica_instance_id - : The maximum replication time lag calculated across all serving read replicas of the instance.
alloydb.googleapis.com/instance/postgres/replication/maximum_lag.alloydb.googleapis.com/Instance,cluster_id,instance_id.replica_instance_id - : The minimum available memory across all currently serving nodes of the instance.
alloydb.googleapis.com/instance/memory/min_available_memory.alloydb.googleapis.com/Instance,cluster_id.instance_id - : The number of nodes in the instance, along with their status, which can be either up or down.
alloydb.googleapis.com/instance/postgres/instances.alloydb.googleapis.com/Instance,cluster_id,instance_id.status - : Number of tuples (rows) by state per database in the instance.
alloydb.googleapis.com/database/postgresql/tuples.alloydb.googleapis.com/Database,cluster_id,instance_id,database.state - : The total amount of data(in bytes) written to temporary files by the queries per database for top 500 dbs.
alloydb.googleapis.com/database/postgresql/temp_bytes_written_for_top_databases.alloydb.googleapis.com/Database,cluster_id,instance_id.database - : The number of temporary files used for writing data per database while performing internal algorithms like join, sort etc for top 500 dbs.
alloydb.googleapis.com/database/postgresql/temp_files_written_for_top_databases.alloydb.googleapis.com/Database,cluster_id,instance_id.database - : The total number of rows inserted per db for top 500 dbs as a result of the queries in the instance.
alloydb.googleapis.com/database/postgresql/inserted_tuples_count_for_top_databases.alloydb.googleapis.com/Database,cluster_id,instance_id.database - : The total number of rows updated per db for top 500 dbs as a result of the queries in the instance.
alloydb.googleapis.com/database/postgresql/updated_tuples_count_for_top_databases.alloydb.googleapis.com/Database,cluster_id,instance_id.database - : The total number of rows deleted per db for top 500 dbs as a result of the queries in the instance.
alloydb.googleapis.com/database/postgresql/deleted_tuples_count_for_top_databases.alloydb.googleapis.com/Database,cluster_id,instance_id.database - : The current number of connections per database to the instance for top 500 dbs.
alloydb.googleapis.com/database/postgresql/backends_for_top_databases.alloydb.googleapis.com/Database,cluster_id,instance_id.database - : The current number of connections to the instance grouped by the state like idle, active, idle_in_transaction, idle_in_transaction_aborted, disabled, and fastpath_function_call.
alloydb.googleapis.com/instance/postgresql/backends_by_state.alloydb.googleapis.com/Instance,cluster_id,instance_id.state - : The current number of connections to the AlloyDB instance, grouped by applications for top 500 applications.
alloydb.googleapis.com/instance/postgresql/backends_for_top_applications.alloydb.googleapis.com/Instance,cluster_id,instance_id.application_name - : Total number of new connections added per database for top 500 databases to the instance.
alloydb.googleapis.com/database/postgresql/new_connections_for_top_databases.alloydb.googleapis.com/Database,cluster_id,instance_id.database - : Total number of deadlocks detected in the instance per database for top 500 dbs.
alloydb.googleapis.com/database/postgresql/deadlock_count_for_top_databases.alloydb.googleapis.com/Database,cluster_id,instance_id.database - : Total count of statements executed in the instance per database per operation_type.
alloydb.googleapis.com/database/postgresql/statements_executed_count.alloydb.googleapis.com/Database,cluster_id,instance_id,database.operation_type - : Number of rows scanned while processing the queries in the instance since the last sample.
alloydb.googleapis.com/instance/postgresql/returned_tuples_count.alloydb.googleapis.com/Instance,cluster_id.instance_id - : Number of rows fetched while processing the queries in the instance since the last sample.
alloydb.googleapis.com/instance/postgresql/fetched_tuples_count.alloydb.googleapis.com/Instance,cluster_id.instance_id - : Number of rows updated while processing the queries in the instance since the last sample.
alloydb.googleapis.com/instance/postgresql/updated_tuples_count.alloydb.googleapis.com/Instance,cluster_id.instance_id - : Number of rows inserted while processing the queries in the instance since the last sample.
alloydb.googleapis.com/instance/postgresql/inserted_tuples_count.alloydb.googleapis.com/Instance,cluster_id.instance_id - : Number of rows deleted while processing the queries in the instance since the last sample.
alloydb.googleapis.com/instance/postgresql/deleted_tuples_count.alloydb.googleapis.com/Instance,cluster_id.instance_id - : Number of rows written while processing the queries in the instance since the last sample.
alloydb.googleapis.com/instance/postgresql/written_tuples_count.alloydb.googleapis.com/Instance,cluster_id.instance_id - : Number of deadlocks detected in the instance.
alloydb.googleapis.com/instance/postgresql/deadlock_count.alloydb.googleapis.com/Instance,cluster_id.instance_id - : Number of blocks read by Postgres that were not in the buffer cache.
alloydb.googleapis.com/instance/postgresql/blks_read.alloydb.googleapis.com/Instance,cluster_id.instance_id - : Number of times Postgres found the requested block in the buffer cache.
alloydb.googleapis.com/instance/postgresql/blks_hit.alloydb.googleapis.com/Instance,cluster_id.instance_id - : The total amount of data(in bytes) written to temporary files by the queries while performing internal algorithms like join, sort etc.
alloydb.googleapis.com/instance/postgresql/temp_bytes_written_count.alloydb.googleapis.com/Instance,cluster_id.instance_id - : The number of temporary files used for writing data in the instance while performing internal algorithms like join, sort etc.
alloydb.googleapis.com/instance/postgresql/temp_files_written_count.alloydb.googleapis.com/Instance,cluster_id.instance_id - : The number new connections added to the instance.
alloydb.googleapis.com/instance/postgresql/new_connections_count.alloydb.googleapis.com/Instance,cluster_id.instance_id - : Total number of times processes waited for each wait event in the instance.
alloydb.googleapis.com/instance/postgresql/wait_count.alloydb.googleapis.com/Instance,cluster_id,instance_id,wait_event_type.wait_event_name - : Total elapsed wait time for each wait event in the instance.
alloydb.googleapis.com/instance/postgresql/wait_time.alloydb.googleapis.com/Instance,cluster_id,instance_id,wait_event_type.wait_event_name - : The number of committed and rolled back transactions across all serving nodes of the instance.
alloydb.googleapis.com/instance/postgres/transaction_count.alloydb.googleapis.com/Instance,cluster_id.instance_id
获取AlloyDB集群、实例的系统级云监控数据(时间序列指标)。
使用此工具时,你必须提供Google Cloud的和PromQL。
projectIdquery使用提供的指标和规则生成AlloyDB系统指标的PromQL。从用户的需求中获取和等标签。
querycluster_idinstance_id默认设置:
- 时间间隔:对于聚合函数,默认使用
_over_time的时间间隔,除非用户指定了不同的窗口。5m
PromQL查询示例:
- 基础时间序列:
avg_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance"}[5m]) - Top K:
topk(30, avg_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance"}[5m])) - 平均值:
avg(avg_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="my-instance","cluster_id"="my-cluster"}[5m])) - 最小值:
min(min_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance","cluster_id"="alloydb-cluster"}[5m])) - 最大值:
max(max_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance","cluster_id"="alloydb-cluster"}[5m])) - 求和:
sum(avg_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance","cluster_id"="alloydb-cluster"}[5m])) - 流计数:
count(avg_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","instance_id"="alloydb-instance","cluster_id"="alloydb-cluster"}[5m])) - 按实例ID、集群ID分组的百分位数:
quantile by ("instance_id","cluster_id")(0.99,avg_over_time({"__name__"="alloydb.googleapis.com/instance/cpu/average_utilization","monitored_resource"="alloydb.googleapis.com/Instance","cluster_id"="my-cluster","instance_id"="my-instance"}[5m]))
可用指标列表:指标名称、描述、监控资源、标签
- :实例上CPU的使用率百分比。
alloydb.googleapis.com/instance/cpu/average_utilization。alloydb.googleapis.com/Instance、cluster_id。instance_id - :实例所有当前服务节点的最大CPU使用率(0到100)。
alloydb.googleapis.com/instance/cpu/maximum_utilization。alloydb.googleapis.com/Instance、cluster_id。instance_id - :整个集群的AlloyDB总存储量(字节)。
alloydb.googleapis.com/cluster/storage/usage。alloydb.googleapis.com/Cluster。cluster_id - :连接到主实例的只读副本数量。
alloydb.googleapis.com/instance/postgres/replication/replicas。alloydb.googleapis.com/Instance、cluster_id、instance_id、state。replica_instance_id - :实例所有服务只读副本的最大复制时间延迟。
alloydb.googleapis.com/instance/postgres/replication/maximum_lag。alloydb.googleapis.com/Instance、cluster_id、instance_id。replica_instance_id - :实例所有当前服务节点的最小可用内存。
alloydb.googleapis.com/instance/memory/min_available_memory。alloydb.googleapis.com/Instance、cluster_id。instance_id - :实例中的节点数量及其状态(运行中或停止)。
alloydb.googleapis.com/instance/postgres/instances。alloydb.googleapis.com/Instance、cluster_id、instance_id。status - :实例中每个数据库按状态统计的元组(行)数量。
alloydb.googleapis.com/database/postgresql/tuples。alloydb.googleapis.com/Database、cluster_id、instance_id、database。state - :前500个数据库的查询写入临时文件的总数据量(字节)。
alloydb.googleapis.com/database/postgresql/temp_bytes_written_for_top_databases。alloydb.googleapis.com/Database、cluster_id、instance_id。database - :前500个数据库在执行连接、排序等内部算法时,查询使用的临时文件数量。
alloydb.googleapis.com/database/postgresql/temp_files_written_for_top_databases。alloydb.googleapis.com/Database、cluster_id、instance_id。database - :实例中的查询在前500个数据库中插入的总行数。
alloydb.googleapis.com/database/postgresql/inserted_tuples_count_for_top_databases。alloydb.googleapis.com/Database、cluster_id、instance_id。database - :实例中的查询在前500个数据库中更新的总行数。
alloydb.googleapis.com/database/postgresql/updated_tuples_count_for_top_databases。alloydb.googleapis.com/Database、cluster_id、instance_id。database - :实例中的查询在前500个数据库中删除的总行数。
alloydb.googleapis.com/database/postgresql/deleted_tuples_count_for_top_databases。alloydb.googleapis.com/Database、cluster_id、instance_id。database - :前500个数据库当前连接到实例的连接数。
alloydb.googleapis.com/database/postgresql/backends_for_top_databases。alloydb.googleapis.com/Database、cluster_id、instance_id。database - :实例当前的连接数按状态分组(空闲、活跃、事务中空闲、事务中止空闲、禁用、快速路径函数调用)。
alloydb.googleapis.com/instance/postgresql/backends_by_state。alloydb.googleapis.com/Instance、cluster_id、instance_id。state - :前500个应用程序连接到AlloyDB实例的当前连接数,按应用分组。
alloydb.googleapis.com/instance/postgresql/backends_for_top_applications。alloydb.googleapis.com/Instance、cluster_id、instance_id。application_name - :前500个数据库新增到实例的连接总数。
alloydb.googleapis.com/database/postgresql/new_connections_for_top_databases。alloydb.googleapis.com/Database、cluster_id、instance_id。database - :实例中前500个数据库检测到的死锁总数。
alloydb.googleapis.com/database/postgresql/deadlock_count_for_top_databases。alloydb.googleapis.com/Database、cluster_id、instance_id。database - :实例中每个数据库按操作类型统计的语句执行总数。
alloydb.googleapis.com/database/postgresql/statements_executed_count。alloydb.googleapis.com/Database、cluster_id、instance_id、database。operation_type - :自上次采样以来,实例中查询处理时扫描的行数。
alloydb.googleapis.com/instance/postgresql/returned_tuples_count。alloydb.googleapis.com/Instance、cluster_id。instance_id - :自上次采样以来,实例中查询处理时获取的行数。
alloydb.googleapis.com/instance/postgresql/fetched_tuples_count。alloydb.googleapis.com/Instance、cluster_id。instance_id - :自上次采样以来,实例中查询处理时更新的行数。
alloydb.googleapis.com/instance/postgresql/updated_tuples_count。alloydb.googleapis.com/Instance、cluster_id。instance_id - :自上次采样以来,实例中查询处理时插入的行数。
alloydb.googleapis.com/instance/postgresql/inserted_tuples_count。alloydb.googleapis.com/Instance、cluster_id。instance_id - :自上次采样以来,实例中查询处理时删除的行数。
alloydb.googleapis.com/instance/postgresql/deleted_tuples_count。alloydb.googleapis.com/Instance、cluster_id。instance_id - :自上次采样以来,实例中查询处理时写入的行数。
alloydb.googleapis.com/instance/postgresql/written_tuples_count。alloydb.googleapis.com/Instance、cluster_id。instance_id - :实例中检测到的死锁数量。
alloydb.googleapis.com/instance/postgresql/deadlock_count。alloydb.googleapis.com/Instance、cluster_id。instance_id - :Postgres读取的不在缓冲区缓存中的块数。
alloydb.googleapis.com/instance/postgresql/blks_read。alloydb.googleapis.com/Instance、cluster_id。instance_id - :Postgres在缓冲区缓存中找到请求块的次数。
alloydb.googleapis.com/instance/postgresql/blks_hit。alloydb.googleapis.com/Instance、cluster_id。instance_id - :查询在执行连接、排序等内部算法时写入临时文件的总数据量(字节)。
alloydb.googleapis.com/instance/postgresql/temp_bytes_written_count。alloydb.googleapis.com/Instance、cluster_id。instance_id - :实例中查询在执行连接、排序等内部算法时使用的临时文件数量。
alloydb.googleapis.com/instance/postgresql/temp_files_written_count。alloydb.googleapis.com/Instance、cluster_id。instance_id - :新增到实例的连接数。
alloydb.googleapis.com/instance/postgresql/new_connections_count。alloydb.googleapis.com/Instance、cluster_id。instance_id - :实例中每个等待事件的进程等待总次数。
alloydb.googleapis.com/instance/postgresql/wait_count。alloydb.googleapis.com/Instance、cluster_id、instance_id、wait_event_type。wait_event_name - :实例中每个等待事件的累计等待时间。
alloydb.googleapis.com/instance/postgresql/wait_time。alloydb.googleapis.com/Instance、cluster_id、instance_id、wait_event_type。wait_event_name - :实例所有服务节点的已提交和回滚事务数。
alloydb.googleapis.com/instance/postgres/transaction_count。alloydb.googleapis.com/Instance、cluster_id。instance_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.
列出当前运行的前N个(默认50个)查询(state='active'),按运行时间从长到短排序。返回pid、用户、数据库、application_name、client_addr、状态、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。 | 否 | |