about summary refs log tree commit diff
path: root/nixos/modules
diff options
context:
space:
mode:
authorWilliButz <WilliButz@users.noreply.github.com>2019-08-02 18:45:32 +0200
committerGitHub <noreply@github.com>2019-08-02 18:45:32 +0200
commitc221f9fdf2775010384c995ff26bf2da683aaa43 (patch)
treeb94d08b6a0a72686e611411d8f422f2205867054 /nixos/modules
parent3aed444d5711cd1ef6e656652d3d2de1bc6fdeeb (diff)
parente4c60a1e423d540b685b9decaaa3ce06bc7b4a9c (diff)
downloadnixlib-c221f9fdf2775010384c995ff26bf2da683aaa43.tar
nixlib-c221f9fdf2775010384c995ff26bf2da683aaa43.tar.gz
nixlib-c221f9fdf2775010384c995ff26bf2da683aaa43.tar.bz2
nixlib-c221f9fdf2775010384c995ff26bf2da683aaa43.tar.lz
nixlib-c221f9fdf2775010384c995ff26bf2da683aaa43.tar.xz
nixlib-c221f9fdf2775010384c995ff26bf2da683aaa43.tar.zst
nixlib-c221f9fdf2775010384c995ff26bf2da683aaa43.zip
Merge pull request #65751 from mayflower/pkgs/prometheus-postgres-exporter
prometheus-postgres-exporter: init at 0.5.1
Diffstat (limited to 'nixos/modules')
-rw-r--r--nixos/modules/services/monitoring/prometheus/exporters.nix1
-rw-r--r--nixos/modules/services/monitoring/prometheus/exporters/postgres.nix46
2 files changed, 47 insertions, 0 deletions
diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix
index 03f3da75b148..15ec2e868b89 100644
--- a/nixos/modules/services/monitoring/prometheus/exporters.nix
+++ b/nixos/modules/services/monitoring/prometheus/exporters.nix
@@ -33,6 +33,7 @@ let
     "nginx"
     "node"
     "postfix"
+    "postgres"
     "snmp"
     "surfboard"
     "tor"
diff --git a/nixos/modules/services/monitoring/prometheus/exporters/postgres.nix b/nixos/modules/services/monitoring/prometheus/exporters/postgres.nix
new file mode 100644
index 000000000000..e595d63ba32d
--- /dev/null
+++ b/nixos/modules/services/monitoring/prometheus/exporters/postgres.nix
@@ -0,0 +1,46 @@
+{ config, lib, pkgs, options }:
+
+with lib;
+
+let
+  cfg = config.services.prometheus.exporters.postgres;
+in
+{
+  port = 9187;
+  extraOpts = {
+    telemetryPath = mkOption {
+      type = types.str;
+      default = "/metrics";
+      description = ''
+        Path under which to expose metrics.
+      '';
+    };
+    dataSourceName = mkOption {
+      type = types.str;
+      default = "user=postgres database=postgres host=/run/postgresql sslmode=disable";
+      example = "postgresql://username:password@localhost:5432/postgres?sslmode=disable";
+      description = ''
+        Accepts PostgreSQL URI form and key=value form arguments.
+      '';
+    };
+    runAsLocalSuperUser = mkOption {
+      type = types.bool;
+      default = false;
+      description = ''
+        Whether to run the exporter as the local 'postgres' super user.
+      '';
+    };
+  };
+  serviceOpts = {
+    environment.DATA_SOURCE_NAME = cfg.dataSourceName;
+    serviceConfig = {
+      User = mkIf cfg.runAsLocalSuperUser (mkForce "postgres");
+      ExecStart = ''
+        ${pkgs.prometheus-postgres-exporter}/bin/postgres_exporter \
+          --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
+          --web.telemetry-path ${cfg.telemetryPath} \
+          ${concatStringsSep " \\\n  " cfg.extraFlags}
+      '';
+    };
+  };
+}