From 4738b6a5daf28944c7fb293d2c12db733195d2d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charlotte=20=F0=9F=A6=9D=20Delenk?= Date: Sat, 13 Apr 2024 18:24:03 +0100 Subject: [PATCH] Add postgresql metrics exporter --- new-infra/containers/postgresql/default.nix | 12 ++++++++++-- new-infra/containers/postgresql/test.nix | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/new-infra/containers/postgresql/default.nix b/new-infra/containers/postgresql/default.nix index 6699b520..bb9f04b2 100644 --- a/new-infra/containers/postgresql/default.nix +++ b/new-infra/containers/postgresql/default.nix @@ -1,5 +1,5 @@ {pkgs, ...}: { - containers.postgresql = { + containers.postgresql = rec { autoStart = true; privateNetwork = true; hostAddress6 = "fc00::1"; @@ -18,7 +18,11 @@ }; }; - config = {pkgs, ...}: { + config = { + config, + pkgs, + ... + }: { services.postgresql = { enable = true; package = pkgs.postgresql_16; @@ -39,6 +43,10 @@ "d /persist - postgres postgres - -" "d /backup - postgres postgres - -" ]; + services.prometheus.exporters.postgres.enable = true; + networking.firewall.extraCommands = '' + ip6tables -A nixos-fw -p tcp -s _gateway -m tcp --dport ${toString config.services.prometheus.exporters.postgres.port} -m comment --comment postgres-exporter -j nixos-fw-accept + ''; }; }; systemd.tmpfiles.rules = [ diff --git a/new-infra/containers/postgresql/test.nix b/new-infra/containers/postgresql/test.nix index 202266f7..c7113f16 100644 --- a/new-infra/containers/postgresql/test.nix +++ b/new-infra/containers/postgresql/test.nix @@ -16,5 +16,7 @@ pkgs.testers.runNixOSTest { postgresql.wait_for_unit("container@postgresql.service") postgresql.succeed("nixos-container run postgresql -- systemctl start postgresqlBackup.service") postgresql.succeed("stat /persist/backup/postgresql/all.sql.zstd") + postgresql.succeed("sleep 5") + postgresql.succeed("curl -v 'http://postgresql:9187/metrics'") ''; }