2024-10-24 16:23:19 +00:00
|
|
|
metrics:
|
2025-06-17 06:23:45 +00:00
|
|
|
##
|
2024-10-24 16:23:19 +00:00
|
|
|
# Discovery metrics
|
2025-06-17 06:23:45 +00:00
|
|
|
##
|
2024-10-24 16:23:19 +00:00
|
|
|
discover_dbs:
|
|
|
|
|
type: set
|
|
|
|
|
query:
|
2025-06-18 07:03:34 +00:00
|
|
|
0: >
|
|
|
|
|
SELECT datname AS dbname
|
|
|
|
|
FROM pg_database
|
2024-10-24 16:23:19 +00:00
|
|
|
discover_rep:
|
|
|
|
|
type: set
|
|
|
|
|
query:
|
2025-06-18 07:03:34 +00:00
|
|
|
0: >
|
|
|
|
|
SELECT client_addr || '_' || regexp_replace(application_name, '[ ,]', '_', 'g') AS repid,
|
|
|
|
|
client_addr,
|
|
|
|
|
state
|
|
|
|
|
FROM pg_stat_replication
|
2025-04-19 06:33:48 +00:00
|
|
|
discover_slots:
|
|
|
|
|
type: set
|
|
|
|
|
query:
|
2025-06-18 07:03:34 +00:00
|
|
|
90400: >
|
|
|
|
|
SELECT slot_name,
|
|
|
|
|
plugin,
|
|
|
|
|
slot_type,
|
|
|
|
|
database,
|
|
|
|
|
false as temporary,
|
|
|
|
|
active
|
|
|
|
|
FROM pg_replication_slots
|
|
|
|
|
100000: >
|
|
|
|
|
SELECT slot_name,
|
|
|
|
|
plugin,
|
|
|
|
|
slot_type,
|
|
|
|
|
database,
|
|
|
|
|
temporary,
|
|
|
|
|
active
|
|
|
|
|
FROM pg_replication_slots
|
2024-10-24 16:23:19 +00:00
|
|
|
|
2025-06-17 06:23:45 +00:00
|
|
|
##
|
2024-10-24 16:23:19 +00:00
|
|
|
# cluster-wide metrics
|
2025-06-17 06:23:45 +00:00
|
|
|
##
|
2024-10-24 16:23:19 +00:00
|
|
|
version:
|
|
|
|
|
type: value
|
|
|
|
|
query:
|
|
|
|
|
0: SHOW server_version_num
|
2025-06-13 05:16:24 +00:00
|
|
|
|
2024-10-24 16:23:19 +00:00
|
|
|
max_frozen_age:
|
2025-06-01 04:11:44 +00:00
|
|
|
type: row
|
2024-10-24 16:23:19 +00:00
|
|
|
query:
|
2025-06-18 07:03:34 +00:00
|
|
|
0: >
|
|
|
|
|
SELECT max(age(datfrozenxid)) AS xid_age,
|
|
|
|
|
0 AS mxid_age
|
|
|
|
|
FROM pg_database
|
|
|
|
|
90600: >
|
|
|
|
|
SELECT max(age(datfrozenxid)) AS xid_age,
|
|
|
|
|
max(mxid_age(datminmxid)) AS mxid_age
|
|
|
|
|
FROM pg_database
|
2024-10-24 16:23:19 +00:00
|
|
|
|
2025-06-17 06:23:45 +00:00
|
|
|
bgwriter:
|
|
|
|
|
type: row
|
|
|
|
|
query:
|
2025-06-18 07:03:34 +00:00
|
|
|
0: >
|
|
|
|
|
SELECT checkpoints_timed,
|
|
|
|
|
checkpoints_req,
|
|
|
|
|
checkpoint_write_time,
|
|
|
|
|
checkpoint_sync_time,
|
|
|
|
|
buffers_checkpoint,
|
|
|
|
|
buffers_clean,
|
|
|
|
|
maxwritten_clean,
|
|
|
|
|
buffers_backend,
|
|
|
|
|
buffers_backend_fsync,
|
|
|
|
|
buffers_alloc
|
|
|
|
|
FROM pg_stat_bgwriter
|
|
|
|
|
170000: >
|
|
|
|
|
SELECT cp.num_timed AS checkpoints_timed,
|
|
|
|
|
cp.num_requested AS checkpoints_req,
|
|
|
|
|
cp.write_time AS checkpoint_write_time,
|
|
|
|
|
cp.sync_time AS checkpoint_sync_time,
|
|
|
|
|
cp.buffers_written AS buffers_checkpoint,
|
|
|
|
|
bg.buffers_clean AS buffers_clean,
|
|
|
|
|
bg.maxwritten_clean AS maxwritten_clean,
|
|
|
|
|
NULL AS buffers_backend,
|
|
|
|
|
NULL AS buffers_backend_fsync,
|
|
|
|
|
bg.buffers_alloc AS buffers_alloc
|
|
|
|
|
FROM pg_stat_bgwriter bg
|
|
|
|
|
CROSS JOIN pg_stat_checkpointer cp
|
2025-06-17 06:23:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
##
|
2024-10-24 16:23:19 +00:00
|
|
|
# Per-database metrics
|
2025-06-17 06:23:45 +00:00
|
|
|
##
|
2024-10-24 16:23:19 +00:00
|
|
|
db_stats:
|
|
|
|
|
type: row
|
|
|
|
|
query:
|
2025-06-18 07:03:34 +00:00
|
|
|
0: >
|
|
|
|
|
SELECT numbackends,
|
|
|
|
|
xact_commit,
|
|
|
|
|
xact_rollback,
|
|
|
|
|
blks_read,
|
|
|
|
|
blks_hit,
|
|
|
|
|
tup_returned,
|
|
|
|
|
tup_fetched,
|
|
|
|
|
tup_inserted,
|
|
|
|
|
tup_updated,
|
|
|
|
|
tup_deleted,
|
|
|
|
|
conflicts,
|
|
|
|
|
temp_files,
|
|
|
|
|
temp_bytes,
|
|
|
|
|
deadlocks,
|
|
|
|
|
0 AS checksum_failures,
|
|
|
|
|
blk_read_time,
|
|
|
|
|
blk_write_time,
|
|
|
|
|
0 AS session_time,
|
|
|
|
|
0 AS active_time,
|
|
|
|
|
0 AS idle_in_transaction_time,
|
|
|
|
|
0 AS sessions,
|
|
|
|
|
0 AS sessions_abandoned,
|
|
|
|
|
0 AS sessions_fatal,
|
|
|
|
|
0 AS sessions_killed,
|
|
|
|
|
extract('epoch' from stats_reset)::float AS stats_reset
|
|
|
|
|
FROM pg_stat_database WHERE datname = %(dbname)s
|
|
|
|
|
140000: >
|
|
|
|
|
SELECT numbackends,
|
|
|
|
|
xact_commit,
|
|
|
|
|
xact_rollback,
|
|
|
|
|
blks_read,
|
|
|
|
|
blks_hit,
|
|
|
|
|
tup_returned,
|
|
|
|
|
tup_fetched,
|
|
|
|
|
tup_inserted,
|
|
|
|
|
tup_updated,
|
|
|
|
|
tup_deleted,
|
|
|
|
|
conflicts,
|
|
|
|
|
temp_files,
|
|
|
|
|
temp_bytes,
|
|
|
|
|
deadlocks,
|
|
|
|
|
COALESCE(checksum_failures,
|
|
|
|
|
0) AS checksum_failures,
|
|
|
|
|
blk_read_time,
|
|
|
|
|
blk_write_time,
|
|
|
|
|
session_time,
|
|
|
|
|
active_time,
|
|
|
|
|
idle_in_transaction_time,
|
|
|
|
|
sessions,
|
|
|
|
|
sessions_abandoned,
|
|
|
|
|
sessions_fatal,
|
|
|
|
|
sessions_killed,
|
|
|
|
|
extract('epoch' from stats_reset)::float AS stats_reset
|
|
|
|
|
FROM pg_stat_database WHERE datname = %(dbname)s
|
2025-05-22 18:53:25 +00:00
|
|
|
test_args:
|
|
|
|
|
dbname: postgres
|
2024-10-29 06:51:57 +00:00
|
|
|
|
2025-06-13 05:16:24 +00:00
|
|
|
hit_ratios:
|
|
|
|
|
type: row
|
|
|
|
|
query:
|
2025-06-18 07:03:34 +00:00
|
|
|
0: >
|
|
|
|
|
SELECT sum(heap_blks_read)::float / NULLIF(sum(heap_blks_read + heap_blks_hit), 0) AS avg_heap_hit_ratio,
|
|
|
|
|
sum(idx_blks_hit)::float / NULLIF(sum(idx_blks_read + idx_blks_hit), 0) AS avg_idx_hit_ratio,
|
|
|
|
|
sum(toast_blks_hit)::float / NULLIF(sum(toast_blks_read + toast_blks_hit), 0) AS avg_toast_hit_ratio,
|
|
|
|
|
sum(tidx_blks_hit)::float / NULLIF(sum(tidx_blks_read + tidx_blks_hit), 0) AS avg_tidx_hit_ratio
|
|
|
|
|
FROM pg_statio_all_tables
|
|
|
|
|
test_args:
|
|
|
|
|
dbname: postgres
|
2025-06-13 05:16:24 +00:00
|
|
|
|
2025-06-17 06:23:45 +00:00
|
|
|
activity:
|
2025-06-18 07:03:34 +00:00
|
|
|
type: set
|
2024-10-29 06:51:57 +00:00
|
|
|
query:
|
2025-06-17 06:23:45 +00:00
|
|
|
0: >
|
2025-06-18 07:03:34 +00:00
|
|
|
SELECT state,
|
|
|
|
|
count(*) AS backend_count,
|
|
|
|
|
COALESCE(EXTRACT(EPOCH FROM max(now() - state_change))::float, 0) AS max_state_time
|
2025-06-17 06:23:45 +00:00
|
|
|
FROM pg_stat_activity
|
|
|
|
|
WHERE datname = %(dbname)s
|
2025-06-18 07:03:34 +00:00
|
|
|
GROUP BY state
|
|
|
|
|
test_args:
|
|
|
|
|
dbname: postgres
|
|
|
|
|
|
2024-10-24 16:23:19 +00:00
|
|
|
|
2025-06-17 06:23:45 +00:00
|
|
|
##
|
2024-10-24 16:23:19 +00:00
|
|
|
# Per-replication metrics
|
2025-06-17 06:23:45 +00:00
|
|
|
##
|
2024-10-24 16:23:19 +00:00
|
|
|
rep_stats:
|
|
|
|
|
type: row
|
|
|
|
|
query:
|
2025-06-18 07:03:34 +00:00
|
|
|
90400: >
|
|
|
|
|
SELECT pid, usename,
|
|
|
|
|
EXTRACT(EPOCH FROM backend_start)::integer AS backend_start,
|
|
|
|
|
state,
|
|
|
|
|
pg_xlog_location_diff(pg_current_xlog_location(), sent_location) AS sent_lsn,
|
|
|
|
|
pg_xlog_location_diff(pg_current_xlog_location(), write_location) AS write_lsn,
|
|
|
|
|
pg_xlog_location_diff(pg_current_xlog_location(), flush_location) AS flush_lsn,
|
|
|
|
|
pg_xlog_location_diff(pg_current_xlog_location(), replay_location) AS replay_lsn,
|
|
|
|
|
NULL AS write_lag,
|
|
|
|
|
NULL AS flush_lag,
|
|
|
|
|
NULL AS replay_lag,
|
|
|
|
|
sync_state
|
|
|
|
|
FROM pg_stat_replication
|
|
|
|
|
WHERE client_addr || '_' || regexp_replace(application_name, '[ ,]', '_', 'g') = %(repid)s
|
|
|
|
|
100000: >
|
|
|
|
|
SELECT pid, usename,
|
|
|
|
|
EXTRACT(EPOCH FROM backend_start)::integer AS backend_start,
|
|
|
|
|
state,
|
|
|
|
|
pg_wal_lsn_diff(pg_current_wal_lsn(), sent_lsn) AS sent_lsn,
|
|
|
|
|
pg_wal_lsn_diff(pg_current_wal_lsn(), write_lsn) AS write_lsn,
|
|
|
|
|
pg_wal_lsn_diff(pg_current_wal_lsn(), flush_lsn) AS flush_lsn,
|
|
|
|
|
pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lsn) AS replay_lsn,
|
|
|
|
|
COALESCE(EXTRACT(EPOCH FROM write_lag), 0)::integer AS write_lag,
|
|
|
|
|
COALESCE(EXTRACT(EPOCH FROM flush_lag), 0)::integer AS flush_lag,
|
|
|
|
|
COALESCE(EXTRACT(EPOCH FROM replay_lag), 0)::integer AS replay_lag,
|
|
|
|
|
sync_state
|
|
|
|
|
FROM pg_stat_replication WHERE client_addr || '_' || regexp_replace(application_name, '[ ,]', '_', 'g') = %(repid)s
|
2025-05-22 18:53:25 +00:00
|
|
|
test_args:
|
|
|
|
|
repid: 127.0.0.1_test_rep
|
2024-10-24 16:23:19 +00:00
|
|
|
|
2025-06-17 06:23:45 +00:00
|
|
|
|
|
|
|
|
##
|
2025-04-19 06:33:48 +00:00
|
|
|
# Per-slot metrics
|
2025-06-17 06:23:45 +00:00
|
|
|
##
|
2025-04-19 06:33:48 +00:00
|
|
|
slot_stats:
|
|
|
|
|
type: row
|
|
|
|
|
query:
|
2025-06-18 07:03:34 +00:00
|
|
|
90400: >
|
|
|
|
|
SELECT NULL as active_pid,
|
|
|
|
|
xmin,
|
|
|
|
|
pg_xlog_location_diff(pg_current_xlog_location(), restart_lsn) AS restart_bytes,
|
|
|
|
|
NULL AS confirmed_flush_bytes
|
|
|
|
|
FROM pg_replication_slots WHERE slot_name = %(slot)s
|
|
|
|
|
90600: >
|
|
|
|
|
SELECT active_pid,
|
|
|
|
|
xmin,
|
|
|
|
|
pg_xlog_location_diff(pg_current_xlog_location(), restart_lsn) AS restart_bytes,
|
|
|
|
|
pg_xlog_location_diff(pg_current_xlog_location(), confirmed_flush_lsn) AS confirmed_flush_bytes
|
|
|
|
|
FROM pg_replication_slots WHERE slot_name = %(slot)s
|
|
|
|
|
100000: >
|
|
|
|
|
SELECT active_pid,
|
|
|
|
|
xmin,
|
|
|
|
|
pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) AS restart_bytes,
|
|
|
|
|
pg_wal_lsn_diff(pg_current_wal_lsn(), confirmed_flush_lsn) AS confirmed_flush_bytes
|
|
|
|
|
FROM pg_replication_slots WHERE slot_name = %(slot)s
|
2025-05-22 18:53:25 +00:00
|
|
|
test_args:
|
|
|
|
|
slot: test_slot
|
2025-06-17 06:23:45 +00:00
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Debugging
|
|
|
|
|
##
|
|
|
|
|
ntables:
|
|
|
|
|
type: value
|
|
|
|
|
query:
|
|
|
|
|
0: SELECT count(*) AS ntables FROM pg_stat_user_tables
|