Skip to content

Commit 4821d93

Browse files
author
Dementii Priadko
committed
feat(metrics): add Aurora support to multixact_size and remove pg_backup_start_time
1 parent 6a7563b commit 4821d93

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

config/pgwatch-prometheus/metrics.yml

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ metrics:
127127
blk_read_time,
128128
blk_write_time,
129129
extract(epoch from (now() - pg_postmaster_start_time()))::int8 as postmaster_uptime_s,
130-
extract(epoch from (now() - pg_backup_start_time()))::int8 as backup_duration_s,
131130
case when pg_is_in_recovery() then 1 else 0 end as in_recovery_int,
132131
system_identifier::text as tag_sys_id,
133132
(select count(*) from pg_index i
@@ -2286,12 +2285,43 @@ metrics:
22862285
join pg_namespace n on n.oid = p.pronamespace
22872286
where p.proname = 'pg_ls_multixactdir' and n.nspname = 'rds_tools'
22882287
) as has_rds_fn,
2288+
exists (
2289+
select
2290+
from pg_proc p
2291+
join pg_namespace n on n.oid = p.pronamespace
2292+
where p.proname = 'aurora_stat_file' and n.nspname = 'pg_catalog'
2293+
) as has_aurora_fn,
22892294
exists (select from pg_proc where proname = 'pg_ls_dir') as has_pg_ls_dir_func,
22902295
exists (select from pg_proc where proname = 'pg_stat_file') as has_pg_stat_file_func
22912296
),
22922297
can_local as (
22932298
select (has_pg_ls_dir_func and has_pg_stat_file_func) as ok from env
22942299
),
2300+
-- Use query_to_xml to safely execute Aurora-specific multixact query.
2301+
-- Aurora uses aurora_stat_file() function instead of rds_tools.pg_ls_multixactdir().
2302+
aurora_probe_xml as (
2303+
select query_to_xml($q$
2304+
with files as (
2305+
select filename, allocated_bytes, used_bytes
2306+
from aurora_stat_file()
2307+
where filename like 'pg_multixact/%'
2308+
),
2309+
members as (
2310+
select sum(used_bytes)::bigint as sz from files where filename like 'pg_multixact/members%'
2311+
),
2312+
offsets as (
2313+
select sum(used_bytes)::bigint as sz from files where filename like 'pg_multixact/offsets%'
2314+
),
2315+
has_rows as (
2316+
select exists(select 1 from files) as any_rows
2317+
)
2318+
select
2319+
case when (select any_rows from has_rows) then coalesce((select sz from members), 0) end as members_bytes,
2320+
case when (select any_rows from has_rows) then coalesce((select sz from offsets), 0) end as offsets_bytes,
2321+
case when (select any_rows from has_rows) then 0 else 1 end as status_code
2322+
$q$, true, true, '') as x
2323+
where (select has_aurora_fn from env)
2324+
),
22952325
-- Use query_to_xml to safely execute RDS-specific multixact directory listing query.
22962326
-- The XML wrapper allows the query to fail gracefully if rds_tools.pg_ls_multixactdir()
22972327
-- is unavailable or returns errors, preventing the entire metric from failing.
@@ -2315,7 +2345,7 @@ metrics:
23152345
case when (select any_rows from has_rows) then coalesce((select sz from offsets), 0) end as offsets_bytes,
23162346
case when (select any_rows from has_rows) then 0 else 1 end as status_code
23172347
$q$, true, true, '') as x
2318-
where (select has_rds_fn from env)
2348+
where (select has_rds_fn from env) and not (select has_aurora_fn from env)
23192349
),
23202350
-- Use query_to_xml to safely execute standard Postgres multixact directory listing query.
23212351
-- The XML wrapper allows the query to fail gracefully if pg_stat_file() or pg_ls_dir()
@@ -2345,9 +2375,11 @@ metrics:
23452375
case when (select has_any from flags) then coalesce((select sz from offsets), 0) end as offsets_bytes,
23462376
case when (select has_any from flags) then 0 else 1 end as status_code
23472377
$q$, true, true, '') as x
2348-
where not (select has_rds_fn from env) and (select ok from can_local)
2378+
where not (select has_rds_fn from env) and not (select has_aurora_fn from env) and (select ok from can_local)
23492379
),
23502380
picked as (
2381+
select * from aurora_probe_xml
2382+
union all
23512383
select * from rds_probe_xml
23522384
union all
23532385
select * from local_probe_xml

0 commit comments

Comments
 (0)