From c81dc5a13b469c511fac6fa2390b70422d1b4da5 Mon Sep 17 00:00:00 2001 From: azahi Date: Wed, 12 Mar 2025 20:17:13 +0300 Subject: 2025-03-12 --- modules/postgresql.nix | 61 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 22 deletions(-) (limited to 'modules/postgresql.nix') diff --git a/modules/postgresql.nix b/modules/postgresql.nix index d5b712c..211d078 100644 --- a/modules/postgresql.nix +++ b/modules/postgresql.nix @@ -69,31 +69,48 @@ in prometheus.exporters.postgres = { enable = true; - listenAddress = lib.mkDefault this.wireguard.ipv4.address; - port = lib.mkDefault 9187; + listenAddress = "127.0.0.1"; + port = 9187; }; }; - systemd.services.postgresql.postStart = lib.optionalString ( - cfg.extraPostStart != [ ] - ) lib.concatLines cfg.extraPostStart; - - environment.variables.PSQLRC = toString ( - pkgs.writeText "psqlrc" '' - \set QUIET 1 - - \timing - \x auto - \pset null '[NULL]' - \set PROMPT1 '%[%033[1m%]%M %n@%/%R%[%033[0m%]% λ ' - \set PROMPT2 ' … > ' - \set VERBOSITY verbose - \set HISTCONTROL ignoredups - \set HISTFILE /dev/null - - \unset QUIET - '' - ); + systemd.services = { + postgresql.postStart = + lib.optionalString (cfg.extraPostStart != [ ]) cfg.extraPostStart |> lib.concatLines; + + alloy.reloadTriggers = [ config.environment.etc."alloy/postgres.alloy".source ]; + }; + + environment = { + etc."alloy/postgres.alloy".text = with config.services.prometheus.exporters.postgres; '' + prometheus.scrape "postgres" { + targets = [ + { + __address__ = "${listenAddress}:${toString port}", + instance = "${config.networking.hostName}", + }, + ] + forward_to = [prometheus.relabel.default.receiver] + } + ''; + + variables.PSQLRC = toString ( + pkgs.writeText "psqlrc" '' + \set QUIET 1 + + \timing + \x auto + \pset null '[NULL]' + \set PROMPT1 '%[%033[1m%]%M %n@%/%R%[%033[0m%]% λ ' + \set PROMPT2 ' … > ' + \set VERBOSITY verbose + \set HISTCONTROL ignoredups + \set HISTFILE /dev/null + + \unset QUIET + '' + ); + }; topology = { nodes.${this.hostname}.services.postgresql = { -- cgit 1.4.1