Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metrics: add "wal.timeline" column to be able to detect failovers #488

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion pgwatch2/metrics/wal/10/metric.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@ select /* pgwatch2_generated */
end as xlog_location_b,
case when pg_is_in_recovery() then 1 else 0 end as in_recovery_int,
extract(epoch from (now() - pg_postmaster_start_time()))::int8 as postmaster_uptime_s,
system_identifier::text as tag_sys_id
system_identifier::text as tag_sys_id,
case
when pg_is_in_recovery() = false then
pashagolub marked this conversation as resolved.
Show resolved Hide resolved
ltrim(pg_walfile_name(pg_current_wal_lsn())::char(8), '0')::int
else
(select min_recovery_end_timeline::int from pg_control_recovery())
end as timeline
from pg_control_system();
8 changes: 7 additions & 1 deletion pgwatch2/metrics/wal/10/metric_su.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@ select /* pgwatch2_generated */
end as xlog_location_b,
case when pg_is_in_recovery() then 1 else 0 end as in_recovery_int,
extract(epoch from (now() - coalesce((pg_stat_file('postmaster.pid', true)).modification, pg_postmaster_start_time())))::int8 as postmaster_uptime_s,
system_identifier::text as tag_sys_id
system_identifier::text as tag_sys_id,
case
when pg_is_in_recovery() = false then
ltrim(pg_walfile_name(pg_current_wal_lsn())::char(8), '0')::int
else
(select min_recovery_end_timeline::int from pg_control_recovery())
end as timeline
from pg_control_system();
16 changes: 14 additions & 2 deletions pgwatch2/sql/config_store/metric_definitions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2638,7 +2638,13 @@ select
end as xlog_location_b,
case when pg_is_in_recovery() then 1 else 0 end as in_recovery_int,
extract(epoch from (now() - pg_postmaster_start_time()))::int8 as postmaster_uptime_s,
system_identifier::text as tag_sys_id
system_identifier::text as tag_sys_id,
case
when pg_is_in_recovery() = false then
ltrim(pg_walfile_name(pg_current_wal_lsn())::char(8), '0')::int
else
(select min_recovery_end_timeline::int from pg_control_recovery())
end as timeline
from pg_control_system();
$sql$,
$sql$
Expand All @@ -2652,7 +2658,13 @@ select
end as xlog_location_b,
case when pg_is_in_recovery() then 1 else 0 end as in_recovery_int,
extract(epoch from (now() - coalesce((pg_stat_file('postmaster.pid', true)).modification, pg_postmaster_start_time())))::int8 as postmaster_uptime_s,
system_identifier::text as tag_sys_id
system_identifier::text as tag_sys_id,
case
when pg_is_in_recovery() = false then
ltrim(pg_walfile_name(pg_current_wal_lsn())::char(8), '0')::int
else
(select min_recovery_end_timeline::int from pg_control_recovery())
end as timeline
from pg_control_system();
$sql$,
'{"prometheus_gauge_columns": ["in_recovery_int", "postmaster_uptime_s"]}'
Expand Down