diff options
author | azahi <azat@bahawi.net> | 2025-03-12 20:17:13 +0300 |
---|---|---|
committer | azahi <azat@bahawi.net> | 2025-03-12 20:17:13 +0300 |
commit | c81dc5a13b469c511fac6fa2390b70422d1b4da5 (patch) | |
tree | 4dab5909006ab5c25da6bd9fde6a714c7719ded7 /modules/postgresql.nix | |
parent | 2025-02-17 (diff) |
Diffstat (limited to 'modules/postgresql.nix')
-rw-r--r-- | modules/postgresql.nix | 61 |
1 files changed, 39 insertions, 22 deletions
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 = { |