Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Metrics: "kpi" fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kmoppel committed Sep 26, 2019
1 parent 0d7f1fc commit fc9f975
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 16 deletions.
8 changes: 7 additions & 1 deletion pgwatch2/metrics/kpi/10/metric.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ q_stat_activity AS (
)
SELECT
(extract(epoch from now()) * 1e9)::int8 as epoch_ns,
(select pg_wal_lsn_diff(pg_current_wal_lsn(), '0/0'))::int8 AS wal_location_b,
case
when pg_is_in_recovery() = false then
pg_wal_lsn_diff(pg_current_wal_lsn(), '0/0')::int8
else
pg_wal_lsn_diff(pg_last_wal_replay_lsn(), '0/0')::int8
end as wal_location_b,
numbackends - 1 as numbackends,
(select count(*) from q_stat_activity where state in ('active', 'idle in transaction')) AS active_backends,
(select count(*) from q_stat_activity where wait_event_type in ('LWLock', 'Lock', 'BufferPin')) AS blocked_backends,
Expand All @@ -29,6 +34,7 @@ SELECT
blk_read_time,
blk_write_time,
deadlocks,
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
FROM
pg_stat_database d
Expand Down
8 changes: 7 additions & 1 deletion pgwatch2/metrics/kpi/10/metric_su.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ q_stat_activity AS (
)
SELECT
(extract(epoch from now()) * 1e9)::int8 as epoch_ns,
(select pg_wal_lsn_diff(pg_current_wal_lsn(), '0/0'))::int8 AS wal_location_b,
case
when pg_is_in_recovery() = false then
pg_wal_lsn_diff(pg_current_wal_lsn(), '0/0')::int8
else
pg_wal_lsn_diff(pg_last_wal_replay_lsn(), '0/0')::int8
end as wal_location_b,
numbackends - 1 as numbackends,
(select count(*) from q_stat_activity where state in ('active', 'idle in transaction')) AS active_backends,
(select count(*) from q_stat_activity where wait_event_type in ('LWLock', 'Lock', 'BufferPin')) AS blocked_backends,
Expand All @@ -30,6 +35,7 @@ SELECT
blk_read_time,
blk_write_time,
deadlocks,
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
FROM
pg_stat_database d
Expand Down
10 changes: 9 additions & 1 deletion pgwatch2/metrics/kpi/9.2/metric.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ q_stat_activity AS (
)
SELECT
(extract(epoch from now()) * 1e9)::int8 as epoch_ns,
case
when pg_is_in_recovery() = false then
pg_xlog_location_diff(pg_current_xlog_location(), '0/0')::int8
else
pg_xlog_location_diff(pg_last_xlog_replay_location(), '0/0')::int8
end as wal_location_b,
numbackends - 1 as numbackends,
(select count(1) from q_stat_activity where state = 'active') AS active_backends,
(select count(1) from q_stat_activity where waiting) AS blocked_backends,
Expand All @@ -27,7 +33,9 @@ SELECT
(select sum(calls) from pg_stat_user_functions where not schemaname like any(array[E'pg\\_%', 'information_schema']))::int8 AS sproc_calls,
blk_read_time,
blk_write_time,
deadlocks
deadlocks,
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
FROM
pg_stat_database d
WHERE
Expand Down
11 changes: 9 additions & 2 deletions pgwatch2/metrics/kpi/9.2/metric_su.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ WITH q_stat_tables AS (
)
SELECT
(extract(epoch from now()) * 1e9)::int8 as epoch_ns,
(select pg_xlog_location_diff(pg_current_xlog_location(), '0/0'))::int8 AS wal_location_b,
case
when pg_is_in_recovery() = false then
pg_xlog_location_diff(pg_current_xlog_location(), '0/0')::int8
else
pg_xlog_location_diff(pg_last_xlog_replay_location(), '0/0')::int8
end as wal_location_b,
numbackends - 1 as numbackends,
(select count(1) from q_stat_activity where state = 'active') AS active_backends,
(select count(1) from q_stat_activity where waiting) AS blocked_backends,
Expand All @@ -29,7 +34,9 @@ SELECT
(select sum(calls) from pg_stat_user_functions where not schemaname like any(array[E'pg\\_%', 'information_schema']))::int8 AS sproc_calls,
blk_read_time,
blk_write_time,
deadlocks
deadlocks,
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
FROM
pg_stat_database d
WHERE
Expand Down
8 changes: 7 additions & 1 deletion pgwatch2/metrics/kpi/9.6/metric.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ q_stat_activity AS (
)
SELECT
(extract(epoch from now()) * 1e9)::int8 as epoch_ns,
(select pg_xlog_location_diff(pg_current_xlog_location(), '0/0'))::int8 AS wal_location_b,
case
when pg_is_in_recovery() = false then
pg_xlog_location_diff(pg_current_xlog_location(), '0/0')::int8
else
pg_xlog_location_diff(pg_last_xlog_replay_location(), '0/0')::int8
end as wal_location_b,
numbackends - 1 as numbackends,
(select count(*) from q_stat_activity where state in ('active', 'idle in transaction')) AS active_backends,
(select count(*) from q_stat_activity where wait_event_type in ('LWLockNamed', 'Lock', 'BufferPin')) AS blocked_backends,
Expand All @@ -29,6 +34,7 @@ SELECT
blk_read_time,
blk_write_time,
deadlocks,
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
FROM
pg_stat_database d
Expand Down
8 changes: 7 additions & 1 deletion pgwatch2/metrics/kpi/9.6/metric_su.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ q_stat_activity AS (
)
SELECT
(extract(epoch from now()) * 1e9)::int8 as epoch_ns,
(select pg_xlog_location_diff(pg_current_xlog_location(), '0/0'))::int8 AS wal_location_b,
case
when pg_is_in_recovery() = false then
pg_xlog_location_diff(pg_current_xlog_location(), '0/0')::int8
else
pg_xlog_location_diff(pg_last_xlog_replay_location(), '0/0')::int8
end as wal_location_b,
numbackends - 1 as numbackends,
(select count(*) from q_stat_activity where state in ('active', 'idle in transaction')) AS active_backends,
(select count(*) from q_stat_activity where wait_event_type in ('LWLockNamed', 'Lock', 'BufferPin')) AS blocked_backends,
Expand All @@ -30,6 +35,7 @@ SELECT
blk_read_time,
blk_write_time,
deadlocks,
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
FROM
pg_stat_database d
Expand Down
59 changes: 50 additions & 9 deletions pgwatch2/sql/config_store/metric_definitions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,12 @@ q_stat_activity AS (
)
SELECT
(extract(epoch from now()) * 1e9)::int8 as epoch_ns,
case
when pg_is_in_recovery() = false then
pg_xlog_location_diff(pg_current_xlog_location(), '0/0')::int8
else
pg_xlog_location_diff(pg_last_xlog_replay_location(), '0/0')::int8
end as wal_location_b,
numbackends - 1 as numbackends,
(select count(1) from q_stat_activity where state = 'active') AS active_backends,
(select count(1) from q_stat_activity where waiting) AS blocked_backends,
Expand All @@ -567,7 +573,9 @@ SELECT
(select sum(calls) from pg_stat_user_functions where not schemaname like any(array[E'pg\\_%', 'information_schema']))::int8 AS sproc_calls,
blk_read_time,
blk_write_time,
deadlocks
deadlocks,
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
FROM
pg_stat_database d
WHERE
Expand All @@ -587,7 +595,12 @@ WITH q_stat_tables AS (
)
SELECT
(extract(epoch from now()) * 1e9)::int8 as epoch_ns,
(select pg_xlog_location_diff(pg_current_xlog_location(), '0/0'))::int8 AS wal_location_b,
case
when pg_is_in_recovery() = false then
pg_xlog_location_diff(pg_current_xlog_location(), '0/0')::int8
else
pg_xlog_location_diff(pg_last_xlog_replay_location(), '0/0')::int8
end as wal_location_b,
numbackends - 1 as numbackends,
(select count(1) from q_stat_activity where state = 'active') AS active_backends,
(select count(1) from q_stat_activity where waiting) AS blocked_backends,
Expand All @@ -606,7 +619,9 @@ SELECT
(select sum(calls) from pg_stat_user_functions where not schemaname like any(array[E'pg\\_%', 'information_schema']))::int8 AS sproc_calls,
blk_read_time,
blk_write_time,
deadlocks
deadlocks,
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
FROM
pg_stat_database d
WHERE
Expand All @@ -630,7 +645,12 @@ q_stat_activity AS (
)
SELECT
(extract(epoch from now()) * 1e9)::int8 as epoch_ns,
(select pg_xlog_location_diff(pg_current_xlog_location(), '0/0'))::int8 AS wal_location_b,
case
when pg_is_in_recovery() = false then
pg_xlog_location_diff(pg_current_xlog_location(), '0/0')::int8
else
pg_xlog_location_diff(pg_last_xlog_replay_location(), '0/0')::int8
end as wal_location_b,
numbackends - 1 as numbackends,
(select count(1) from q_stat_activity where state = 'active') AS active_backends,
(select count(1) from q_stat_activity where wait_event_type is not null) AS blocked_backends,
Expand All @@ -649,7 +669,9 @@ SELECT
(select sum(calls) from pg_stat_user_functions where not schemaname like any(array[E'pg\\_%', 'information_schema']))::int8 AS sproc_calls,
blk_read_time,
blk_write_time,
deadlocks
deadlocks,
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
FROM
pg_stat_database d
WHERE
Expand All @@ -669,7 +691,12 @@ q_stat_activity AS (
)
SELECT
(extract(epoch from now()) * 1e9)::int8 as epoch_ns,
(select pg_xlog_location_diff(pg_current_xlog_location(), '0/0'))::int8 AS wal_location_b,
case
when pg_is_in_recovery() = false then
pg_xlog_location_diff(pg_current_xlog_location(), '0/0')::int8
else
pg_xlog_location_diff(pg_last_xlog_replay_location(), '0/0')::int8
end as xlog_location_b,
numbackends - 1 as numbackends,
(select count(*) from q_stat_activity where state in ('active', 'idle in transaction')) AS active_backends,
(select count(*) from q_stat_activity where wait_event_type in ('LWLockNamed', 'Lock', 'BufferPin')) AS blocked_backends,
Expand All @@ -689,6 +716,7 @@ SELECT
blk_read_time,
blk_write_time,
deadlocks,
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
FROM
pg_stat_database d
Expand All @@ -715,7 +743,12 @@ q_stat_activity AS (
)
SELECT
(extract(epoch from now()) * 1e9)::int8 as epoch_ns,
(select pg_wal_lsn_diff(pg_current_wal_lsn(), '0/0'))::int8 AS wal_location_b,
case
when pg_is_in_recovery() = false then
pg_wal_lsn_diff(pg_current_wal_lsn(), '0/0')::int8
else
pg_wal_lsn_diff(pg_last_wal_replay_lsn(), '0/0')::int8
end as wal_location_b,
numbackends - 1 as numbackends,
(select count(1) from q_stat_activity where state = 'active') AS active_backends,
(select count(1) from q_stat_activity where wait_event_type is not null) AS blocked_backends,
Expand All @@ -734,7 +767,9 @@ SELECT
(select sum(calls) from pg_stat_user_functions where not schemaname like any(array[E'pg\\_%', 'information_schema']))::int8 AS sproc_calls,
blk_read_time,
blk_write_time,
deadlocks
deadlocks,
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
FROM
pg_stat_database d
WHERE
Expand All @@ -754,7 +789,12 @@ q_stat_activity AS (
)
SELECT
(extract(epoch from now()) * 1e9)::int8 as epoch_ns,
(select pg_wal_lsn_diff(pg_current_wal_lsn(), '0/0'))::int8 AS wal_location_b,
case
when pg_is_in_recovery() = false then
pg_wal_lsn_diff(pg_current_wal_lsn(), '0/0')::int8
else
pg_wal_lsn_diff(pg_last_wal_replay_lsn(), '0/0')::int8
end as wal_location_b,
numbackends - 1 as numbackends,
(select count(*) from q_stat_activity where state in ('active', 'idle in transaction')) AS active_backends,
(select count(*) from q_stat_activity where wait_event_type in ('LWLock', 'Lock', 'BufferPin')) AS blocked_backends,
Expand All @@ -774,6 +814,7 @@ SELECT
blk_read_time,
blk_write_time,
deadlocks,
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
FROM
pg_stat_database d
Expand Down

0 comments on commit fc9f975

Please sign in to comment.