aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/postgres.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/postgres.nix')
-rw-r--r--nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/postgres.nix47
1 files changed, 47 insertions, 0 deletions
diff --git a/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/postgres.nix b/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/postgres.nix
new file mode 100644
index 00000000000..1ece73a1159
--- /dev/null
+++ b/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/postgres.nix
@@ -0,0 +1,47 @@
+{ 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 = {
+ DynamicUser = false;
+ 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}
+ '';
+ };
+ };
+}