Skip to content

Commit 17cd381

Browse files
author
tony-landreth
committed
Adds replacements for postgres-exporter queries
1 parent 37eb711 commit 17cd381

File tree

6 files changed

+84
-4
lines changed

6 files changed

+84
-4
lines changed

internal/collector/generated/gte_pg17_metrics.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/collector/generated/lt_pg17_metrics.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/collector/generated/postgres_5s_metrics.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/collector/gte_pg17_metrics.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,36 @@
44
# https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/-/receiver/sqlqueryreceiver#metrics-queries
55
# https://github.com/CrunchyData/pgmonitor/blob/development/sql_exporter/common/crunchy_global_collector.yml
66

7+
- sql: >
8+
SELECT c.buffers_written
9+
FROM pg_catalog.pg_stat_checkpointer c;
10+
metrics:
11+
- metric_name: ccp_stat_bgwriter_buffers_checkpoint
12+
data_type: sum
13+
description: Number of buffers written during checkpoints and restartpoints
14+
static_attributes:
15+
server: "localhost:5432"
16+
17+
- sql: >
18+
SELECT
19+
s.writes
20+
, s.fsyncs
21+
FROM pg_catalog.pg_stat_io s
22+
WHERE backend_type = 'background writer';
23+
metrics:
24+
- metric_name: ccp_stat_bgwriter_buffers_backend
25+
value_column: writes
26+
data_type: sum
27+
description: Number of write operations, each of the size specified in op_bytes.
28+
static_attributes:
29+
server: "localhost:5432"
30+
- metric_name: ccp_stat_bgwriter_buffers_backend_fsync
31+
value_column: fsyncs
32+
data_type: sum
33+
description: Number of fsync calls. These are only tracked in context normal.
34+
static_attributes:
35+
server: "localhost:5432"
36+
737
- sql: >
838
SELECT
939
c.num_timed

internal/collector/lt_pg17_metrics.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,36 @@
44
# https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/-/receiver/sqlqueryreceiver#metrics-queries
55
# https://github.com/CrunchyData/pgmonitor/blob/development/sql_exporter/common/crunchy_global_collector.yml
66

7+
- sql: >
8+
SELECT c.buffers_checkpoint AS buffers_written
9+
FROM pg_catalog.pg_stat_bgwriter c;
10+
metrics:
11+
- metric_name: ccp_stat_bgwriter_buffers_checkpoint
12+
value_column: buffers_written
13+
data_type: sum
14+
description: Number of buffers written during checkpoints and restartpoints
15+
static_attributes:
16+
server: "localhost:5432"
17+
18+
- sql: >
19+
SELECT
20+
s.buffers_backend AS writes
21+
, s.buffers_backend_fsync AS fsyncs
22+
FROM pg_catalog.pg_stat_bgwriter s;
23+
metrics:
24+
- metric_name: ccp_stat_bgwriter_buffers_backend
25+
value_column: writes
26+
data_type: sum
27+
description: Number of write operations, each of the size specified in op_bytes.
28+
static_attributes:
29+
server: "localhost:5432"
30+
- metric_name: ccp_stat_bgwriter_buffers_backend_fsync
31+
value_column: fsyncs
32+
data_type: sum
33+
description: Number of fsync calls. These are only tracked in context normal.
34+
static_attributes:
35+
server: "localhost:5432"
36+
737
- sql: >
838
SELECT
939
c.checkpoints_timed AS num_timed

internal/collector/postgres_5s_metrics.yaml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,18 @@
589589
static_attributes:
590590
server: "localhost:5432"
591591
592+
# ccp_replication_lag_size_bytes will return NULL on a replica
593+
- sql: >
594+
SELECT pg_wal_lsn_diff(sent_lsn, replay_lsn) AS bytes
595+
FROM pg_catalog.pg_stat_replication;
596+
metrics:
597+
- metric_name: ccp_replication_lag_size_bytes
598+
value_column: bytes
599+
value_type: double
600+
description: Time interval in seconds since PostgreSQL database was last restarted.
601+
static_attributes:
602+
server: "localhost:5432"
603+
592604
- sql: >
593605
SELECT
594606
CASE
@@ -600,7 +612,12 @@
600612
WHEN pg_is_in_recovery() = false THEN 0
601613
ELSE EXTRACT (EPOCH FROM clock_timestamp() - pg_last_xact_replay_timestamp())::INTEGER
602614
END
603-
AS received_time;
615+
AS received_time
616+
, CASE
617+
WHEN pg_is_in_recovery() = true THEN 'replica'
618+
ELSE 'primary'
619+
END
620+
AS role;
604621
metrics:
605622
- metric_name: ccp_replication_lag_received_time
606623
value_column: received_time
@@ -609,6 +626,7 @@
609626
Length of time since the last WAL file was received and replayed on replica.
610627
Always increases, possibly causing false positives if the primary stops writing.
611628
Monitors for replicas that stop receiving WAL all together.
629+
attribute_columns: ["role"]
612630
static_attributes:
613631
server: "localhost:5432"
614632
- metric_name: ccp_replication_lag_replay_time
@@ -619,6 +637,7 @@
619637
Returns zero if last WAL received equals last WAL replayed. Avoids
620638
false positives when primary stops writing. Monitors for replicas that
621639
cannot keep up with primary WAL generation.
640+
attribute_columns: ["role"]
622641
static_attributes:
623642
server: "localhost:5432"
624643
@@ -645,6 +664,7 @@
645664
server: "localhost:5432"
646665
- metric_name: ccp_stat_bgwriter_buffers_clean
647666
value_column: buffers_clean
667+
data_type: sum
648668
description: Number of buffers written by the background writer
649669
static_attributes:
650670
server: "localhost:5432"

0 commit comments

Comments
 (0)