Skip to content

Commit

Permalink
Merge pull request #488 from cognitedata/add-timeline-to-wal-metric
Browse files Browse the repository at this point in the history
Metrics: add "wal.timeline" column to be able to detect failovers
  • Loading branch information
kmoppel-cognite authored Jun 7, 2022
2 parents d37d637 + 6471637 commit d6b0df9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
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
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

0 comments on commit d6b0df9

Please sign in to comment.