Skip to content

Commit

Permalink
[+] add sent_lag and confirmed_flush_lsn_lag fields to replicatio…
Browse files Browse the repository at this point in the history
…n metrics (#700)

* Additional metrics based on stat_statements stats
* updating the files in the `metric` folder
---------
Co-authored-by: Mikhail.Balayan <mikhail.balayan@acronis.com>
  • Loading branch information
bukem authored Dec 28, 2023
1 parent af98e6d commit 61f5454
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions pgwatch2/metrics/replication/10/metric.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ select /* pgwatch2_generated */
(extract(epoch from now()) * 1e9)::int8 as epoch_ns,
application_name as tag_application_name,
concat(coalesce(client_addr::text, client_hostname), '_', client_port::text) as tag_client_info,
coalesce(pg_wal_lsn_diff(case when pg_is_in_recovery() then pg_last_wal_receive_lsn() else pg_current_wal_lsn() end, sent_lsn)::int8, 0) as sent_lag_b,
coalesce(pg_wal_lsn_diff(case when pg_is_in_recovery() then pg_last_wal_receive_lsn() else pg_current_wal_lsn() end, write_lsn)::int8, 0) as write_lag_b,
coalesce(pg_wal_lsn_diff(case when pg_is_in_recovery() then pg_last_wal_receive_lsn() else pg_current_wal_lsn() end, flush_lsn)::int8, 0) as flush_lag_b,
coalesce(pg_wal_lsn_diff(case when pg_is_in_recovery() then pg_last_wal_receive_lsn() else pg_current_wal_lsn() end, replay_lsn)::int8, 0) as replay_lag_b,
Expand Down
1 change: 1 addition & 0 deletions pgwatch2/metrics/replication_slots/10/metric_master.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ select /* pgwatch2_generated */
active,
case when active then 0 else 1 end as non_active_int,
pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)::int8 as restart_lsn_lag_b,
pg_wal_lsn_diff(pg_current_wal_lsn(), confirmed_flush_lsn)::int8 as confirmed_flush_lsn_lag_b,
greatest(age(xmin), age(catalog_xmin))::int8 as xmin_age_tx
from
pg_replication_slots;
2 changes: 2 additions & 0 deletions pgwatch2/sql/config_store/metric_definitions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1834,6 +1834,7 @@ SELECT
(extract(epoch from now()) * 1e9)::int8 as epoch_ns,
application_name as tag_application_name,
concat(coalesce(client_addr::text, client_hostname), '_', client_port::text) as tag_client_info,
coalesce(pg_wal_lsn_diff(case when pg_is_in_recovery() then pg_last_wal_receive_lsn() else pg_current_wal_lsn() end, sent_lsn)::int8, 0) as sent_lag_b,
coalesce(pg_wal_lsn_diff(case when pg_is_in_recovery() then pg_last_wal_receive_lsn() else pg_current_wal_lsn() end, write_lsn)::int8, 0) as write_lag_b,
coalesce(pg_wal_lsn_diff(case when pg_is_in_recovery() then pg_last_wal_receive_lsn() else pg_current_wal_lsn() end, flush_lsn)::int8, 0) as flush_lag_b,
coalesce(pg_wal_lsn_diff(case when pg_is_in_recovery() then pg_last_wal_receive_lsn() else pg_current_wal_lsn() end, replay_lsn)::int8, 0) as replay_lag_b,
Expand Down Expand Up @@ -6929,6 +6930,7 @@ select
active,
case when active then 0 else 1 end as non_active_int,
pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)::int8 as restart_lsn_lag_b,
pg_wal_lsn_diff(pg_current_wal_lsn(), confirmed_flush_lsn)::int8 as confirmed_flush_lsn_lag_b,
greatest(age(xmin), age(catalog_xmin))::int8 as xmin_age_tx
from
pg_replication_slots;
Expand Down

0 comments on commit 61f5454

Please sign in to comment.