Skip to content

Commit 7caffdb

Browse files
authored
PG: Add recovery prefetch metrics (#20464)
1 parent 9ba71ee commit 7caffdb

File tree

8 files changed

+281
-226
lines changed

8 files changed

+281
-226
lines changed

postgres/changelog.d/20464.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PG: Add recovery prefetch metrics

postgres/datadog_checks/postgres/postgres.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
QUERY_PG_REPLICATION_STATS_METRICS,
5656
QUERY_PG_STAT_DATABASE,
5757
QUERY_PG_STAT_DATABASE_CONFLICTS,
58+
QUERY_PG_STAT_RECOVERY_PREFETCH,
5859
QUERY_PG_STAT_WAL_RECEIVER,
5960
QUERY_PG_UPTIME,
6061
REPLICATION_METRICS,
@@ -363,6 +364,7 @@ def dynamic_queries(self):
363364
queries.append(SUBSCRIPTION_STATE_METRICS)
364365
if self.version >= V15:
365366
queries.append(STAT_SUBSCRIPTION_STATS_METRICS)
367+
queries.append(QUERY_PG_STAT_RECOVERY_PREFETCH)
366368
if self.version >= V16:
367369
if self._config.dbm_enabled:
368370
queries.append(STAT_IO_METRICS)

postgres/datadog_checks/postgres/util.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,34 @@ def trim_leading_set_stmts(sql):
249249
],
250250
}
251251

252+
QUERY_PG_STAT_RECOVERY_PREFETCH = {
253+
'name': 'pg_stat_recovery_prefetch',
254+
'query': """
255+
SELECT
256+
prefetch,
257+
hit,
258+
skip_init,
259+
skip_new,
260+
skip_fpw,
261+
skip_rep,
262+
wal_distance,
263+
block_distance,
264+
io_depth
265+
FROM pg_stat_recovery_prefetch
266+
""".strip(),
267+
'columns': [
268+
{'name': 'recovery_prefetch.prefetch', 'type': 'monotonic_count'},
269+
{'name': 'recovery_prefetch.hit', 'type': 'monotonic_count'},
270+
{'name': 'recovery_prefetch.skip_init', 'type': 'monotonic_count'},
271+
{'name': 'recovery_prefetch.skip_new', 'type': 'monotonic_count'},
272+
{'name': 'recovery_prefetch.skip_fpw', 'type': 'monotonic_count'},
273+
{'name': 'recovery_prefetch.skip_rep', 'type': 'monotonic_count'},
274+
{'name': 'recovery_prefetch.wal_distance', 'type': 'gauge'},
275+
{'name': 'recovery_prefetch.block_distance', 'type': 'gauge'},
276+
{'name': 'recovery_prefetch.io_depth', 'type': 'gauge'},
277+
],
278+
}
279+
252280
QUERY_PG_UPTIME = {
253281
'name': 'pg_uptime',
254282
'query': "SELECT FLOOR(EXTRACT(EPOCH FROM current_timestamp - pg_postmaster_start_time()))",

postgres/metadata.csv

Lines changed: 235 additions & 226 deletions
Large diffs are not rendered by default.

postgres/tests/common.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
QUERY_PG_REPLICATION_SLOTS,
1818
QUERY_PG_REPLICATION_SLOTS_STATS,
1919
QUERY_PG_REPLICATION_STATS_METRICS,
20+
QUERY_PG_STAT_RECOVERY_PREFETCH,
2021
QUERY_PG_STAT_WAL_RECEIVER,
2122
QUERY_PG_UPTIME,
2223
SLRU_METRICS,
@@ -478,6 +479,14 @@ def check_subscription_state_metrics(aggregator, expected_tags, count=1):
478479
aggregator.assert_metric(metric_name, count=count, tags=expected_tags)
479480

480481

482+
def check_recovery_prefetch_metrics(aggregator, expected_tags, count=1):
483+
if float(POSTGRES_VERSION) < 15.0:
484+
return
485+
486+
for metric_name in _iterate_metric_name(QUERY_PG_STAT_RECOVERY_PREFETCH):
487+
aggregator.assert_metric(metric_name, count=count, tags=expected_tags)
488+
489+
481490
def check_subscription_stats_metrics(aggregator, expected_tags, count=1):
482491
if float(POSTGRES_VERSION) < 15:
483492
return

postgres/tests/test_logical_replication.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
check_db_count,
1818
check_file_wal_metrics,
1919
check_performance_metrics,
20+
check_recovery_prefetch_metrics,
2021
check_slru_metrics,
2122
check_snapshot_txid_metrics,
2223
check_stat_wal_metrics,
@@ -51,6 +52,7 @@ def test_common_logical_replica_metrics(aggregator, integration_check, pg_replic
5152
check_snapshot_txid_metrics(aggregator, expected_tags=expected_tags)
5253
check_stat_wal_metrics(aggregator, expected_tags=expected_tags)
5354
check_file_wal_metrics(aggregator, expected_tags=expected_tags)
55+
check_recovery_prefetch_metrics(aggregator, expected_tags=expected_tags)
5456

5557
check_wal_receiver_metrics(aggregator, connected=False, expected_tags=expected_tags)
5658
check_subscription_metrics(aggregator, expected_tags=expected_tags + ['subscription_name:subscription_cities'])

postgres/tests/test_pg_integration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
check_metrics_metadata,
3838
check_performance_metrics,
3939
check_physical_replication_slots,
40+
check_recovery_prefetch_metrics,
4041
check_slru_metrics,
4142
check_snapshot_txid_metrics,
4243
check_stat_io_metrics,
@@ -94,6 +95,7 @@ def test_common_metrics(aggregator, integration_check, pg_instance, is_aurora):
9495
check_logical_replication_slots(aggregator, expected_tags)
9596
check_physical_replication_slots(aggregator, expected_tags)
9697
check_snapshot_txid_metrics(aggregator, expected_tags=expected_tags)
98+
check_recovery_prefetch_metrics(aggregator, expected_tags=expected_tags)
9799

98100
check_performance_metrics(aggregator, expected_tags=check.debug_stats_kwargs()['tags'], is_aurora=is_aurora)
99101

postgres/tests/test_pg_replication.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
check_file_wal_metrics,
2020
check_metrics_metadata,
2121
check_performance_metrics,
22+
check_recovery_prefetch_metrics,
2223
check_replication_delay,
2324
check_slru_metrics,
2425
check_snapshot_txid_metrics,
@@ -53,6 +54,7 @@ def test_common_replica_metrics(aggregator, integration_check, metrics_cache_rep
5354
check_snapshot_txid_metrics(aggregator, expected_tags=expected_tags)
5455
check_stat_wal_metrics(aggregator, expected_tags=expected_tags)
5556
check_file_wal_metrics(aggregator, expected_tags=expected_tags)
57+
check_recovery_prefetch_metrics(aggregator, expected_tags=expected_tags)
5658

5759
check_performance_metrics(aggregator, expected_tags=check.debug_stats_kwargs()['tags'])
5860

0 commit comments

Comments
 (0)