Files
seon bc8a8fbc97 fix(postgres): compute replication lag without the idle-primary artifact
upstream replication 컬렉터는 수신 LSN != 재생 LSN이면 now()-마지막 트랜잭션 재생 시각을 지연으로
보고한다. replica 재시작 직후에는 수신 LSN이 세그먼트 시작점(재생 LSN보다 작음)에 머물러 유휴
프라이머리에서 지연이 무한히 커진다(실측 116초→281초, 트랜잭션 1건 뒤 0). DbReplicationLag가
pending으로 올라갔다. 수신 LSN <= 재생 LSN이면 0으로 보는 custom query로 교체하고 upstream
replication 컬렉터를 끈다. pg_replication_is_replica도 같은 쿼리에서 낸다.
2026-10-08 02:01:56 +09:00

42 lines
1.5 KiB
Plaintext

// Alloy on db-primary / db-replica (design 4.1 / 4.3): postgres exporter (built-in collectors: pg_replication_lag_seconds,
// pg_up, pg_stat_*) + custom pg_is_wal_replay_paused -> Mimir; PostgreSQL logs -> Loki. instance = VM name.
prometheus.exporter.postgres "db" {
data_source_names = [sys.env("PG_DSN")]
custom_queries_config_path = "/etc/alloy/queries.yaml"
disable_settings_metrics = true
// defaults minus "replication": pg_replication_* come from queries.yaml (idle-primary artifact, see there)
enabled_collectors = ["database", "locks", "replication_slot", "roles", "stat_bgwriter", "stat_database", "stat_progress_vacuum", "stat_user_tables", "statio_user_tables", "wal"]
}
prometheus.scrape "db" {
job_name = "postgres"
scrape_interval = "15s"
targets = prometheus.exporter.postgres.db.targets
forward_to = [prometheus.relabel.instance.receiver]
}
prometheus.relabel "instance" {
forward_to = [prometheus.remote_write.mimir.receiver]
rule {
target_label = "instance"
replacement = sys.env("INSTANCE")
}
}
prometheus.remote_write "mimir" {
endpoint { url = "http://10.20.0.10:9009/api/v1/push" }
}
local.file_match "pglogs" {
path_targets = [{ "__path__" = "/var/log/postgresql/*.log", "job" = "postgres", "instance" = sys.env("INSTANCE") }]
}
loki.source.file "pglogs" {
targets = local.file_match.pglogs.targets
forward_to = [loki.write.loki.receiver]
}
loki.write "loki" {
endpoint { url = "http://10.20.0.10:3100/loki/api/v1/push" }
}