summary refs log tree commit diff
path: root/nixos/modules/services/monitoring/prometheus
diff options
context:
space:
mode:
authorFranz Pletz <fpletz@fnordicwalking.de>2019-08-01 23:10:08 +0200
committerFranz Pletz <fpletz@fnordicwalking.de>2019-08-02 15:59:29 +0200
commite4c60a1e423d540b685b9decaaa3ce06bc7b4a9c (patch)
tree642fec882e230589ad722dab54816ff44ec9f38c /nixos/modules/services/monitoring/prometheus
parenta8d45e7fc3656895fc26ff334055a8a27327f96f (diff)
downloadnixpkgs-e4c60a1e423d540b685b9decaaa3ce06bc7b4a9c.tar
nixpkgs-e4c60a1e423d540b685b9decaaa3ce06bc7b4a9c.tar.gz
nixpkgs-e4c60a1e423d540b685b9decaaa3ce06bc7b4a9c.tar.bz2
nixpkgs-e4c60a1e423d540b685b9decaaa3ce06bc7b4a9c.tar.lz
nixpkgs-e4c60a1e423d540b685b9decaaa3ce06bc7b4a9c.tar.xz
nixpkgs-e4c60a1e423d540b685b9decaaa3ce06bc7b4a9c.tar.zst
nixpkgs-e4c60a1e423d540b685b9decaaa3ce06bc7b4a9c.zip
prometheus-postgres-exporter: init at 0.5.1
Diffstat (limited to 'nixos/modules/services/monitoring/prometheus')
-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 802281e7164..dc847fb8745 100644
--- a/nixos/modules/services/monitoring/prometheus/exporters.nix
+++ b/nixos/modules/services/monitoring/prometheus/exporters.nix
@@ -32,6 +32,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 00000000000..e595d63ba32
--- /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}
+      '';
+    };
+  };
+}