2024-03-21 05:26:03 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
options,
|
|
|
|
...
|
|
|
|
}:
|
2023-06-30 19:03:12 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.prometheus.exporters.pgbouncer;
|
2024-04-24 14:41:17 -04:00
|
|
|
inherit (lib)
|
|
|
|
mkOption
|
2024-05-14 15:13:33 +03:00
|
|
|
mkPackageOption
|
2024-04-24 14:41:17 -04:00
|
|
|
types
|
|
|
|
optionals
|
2024-05-14 15:13:33 +03:00
|
|
|
getExe
|
2024-04-24 14:41:17 -04:00
|
|
|
escapeShellArg
|
|
|
|
concatStringsSep
|
|
|
|
;
|
2023-06-30 19:03:12 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
port = 9127;
|
|
|
|
extraOpts = {
|
2024-05-14 15:13:33 +03:00
|
|
|
package = mkPackageOption pkgs "prometheus-pgbouncer-exporter" { };
|
2023-06-30 19:03:12 +02:00
|
|
|
|
|
|
|
telemetryPath = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/metrics";
|
|
|
|
description = ''
|
|
|
|
Path under which to expose metrics.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
connectionString = mkOption {
|
2024-09-05 12:09:05 +02:00
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2023-06-30 19:03:12 +02:00
|
|
|
example = "postgres://admin:@localhost:6432/pgbouncer?sslmode=require";
|
|
|
|
description = ''
|
|
|
|
Connection string for accessing pgBouncer.
|
|
|
|
|
|
|
|
NOTE: You MUST keep pgbouncer as database name (special internal db)!!!
|
|
|
|
|
2024-05-14 14:41:28 +03:00
|
|
|
NOTE: ignore_startup_parameters MUST contain "extra_float_digits".
|
|
|
|
|
|
|
|
NOTE: Admin user (with password or passwordless) MUST exist in the
|
|
|
|
auth_file if auth_type other than "any" is used.
|
2023-06-30 19:03:12 +02:00
|
|
|
|
|
|
|
WARNING: this secret is stored in the world-readable Nix store!
|
2024-09-05 12:09:05 +02:00
|
|
|
Use [](#opt-services.prometheus.exporters.pgbouncer.connectionEnvFile) if the
|
|
|
|
URL contains a secret.
|
2023-06-30 19:03:12 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-05 12:09:05 +02:00
|
|
|
connectionEnvFile = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
2023-06-30 19:03:12 +02:00
|
|
|
default = null;
|
|
|
|
description = ''
|
2024-09-05 12:09:05 +02:00
|
|
|
File that must contain the environment variable
|
|
|
|
`PGBOUNCER_EXPORTER_CONNECTION_STRING` which is set to the connection
|
|
|
|
string used by pgbouncer. I.e. the format is supposed to look like this:
|
2023-06-30 19:03:12 +02:00
|
|
|
|
2024-09-05 12:09:05 +02:00
|
|
|
```
|
|
|
|
PGBOUNCER_EXPORTER_CONNECTION_STRING="postgres://admin@localhost:6432/pgbouncer?sslmode=require"
|
|
|
|
```
|
2023-06-30 19:03:12 +02:00
|
|
|
|
2024-09-05 12:09:05 +02:00
|
|
|
NOTE: You MUST keep pgbouncer as database name (special internal db)!
|
|
|
|
NOTE: `services.pgbouncer.settings.pgbouncer.ignore_startup_parameters`
|
|
|
|
MUST contain "extra_float_digits".
|
2024-05-14 14:41:28 +03:00
|
|
|
|
2024-09-05 12:09:05 +02:00
|
|
|
Mutually exclusive with [](#opt-services.prometheus.exporters.pgbouncer.connectionString).
|
2023-06-30 19:03:12 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
pidFile = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Path to PgBouncer pid file.
|
|
|
|
|
|
|
|
If provided, the standard process metrics get exported for the PgBouncer
|
|
|
|
process, prefixed with 'pgbouncer_process_...'. The pgbouncer_process exporter
|
|
|
|
needs to have read access to files owned by the PgBouncer process. Depends on
|
|
|
|
the availability of /proc.
|
|
|
|
|
|
|
|
https://prometheus.io/docs/instrumenting/writing_clientlibs/#process-metrics.
|
|
|
|
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
webSystemdSocket = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Use systemd socket activation listeners instead of port listeners (Linux only).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
logLevel = mkOption {
|
2024-05-14 15:13:33 +03:00
|
|
|
type = types.enum [
|
|
|
|
"debug"
|
|
|
|
"info"
|
|
|
|
"warn"
|
|
|
|
"error"
|
|
|
|
];
|
2023-06-30 19:03:12 +02:00
|
|
|
default = "info";
|
|
|
|
description = ''
|
|
|
|
Only log messages with the given severity or above.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
logFormat = mkOption {
|
2024-05-14 15:13:33 +03:00
|
|
|
type = types.enum [
|
|
|
|
"logfmt"
|
|
|
|
"json"
|
|
|
|
];
|
2023-06-30 19:03:12 +02:00
|
|
|
default = "logfmt";
|
|
|
|
description = ''
|
|
|
|
Output format of log messages. One of: [logfmt, json]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
webConfigFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Path to configuration file that can enable TLS or authentication.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraFlags = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
Extra commandline options when launching Prometheus.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
serviceOpts = {
|
|
|
|
after = [ "pgbouncer.service" ];
|
2024-09-05 12:09:05 +02:00
|
|
|
script = concatStringsSep " " (
|
|
|
|
[
|
2024-05-14 15:13:33 +03:00
|
|
|
"exec -- ${escapeShellArg (getExe cfg.package)}"
|
|
|
|
"--web.listen-address ${cfg.listenAddress}:${toString cfg.port}"
|
2024-09-05 12:09:05 +02:00
|
|
|
]
|
|
|
|
++ optionals (cfg.connectionString != null) [
|
|
|
|
"--pgBouncer.connectionString ${escapeShellArg cfg.connectionString}"
|
2024-05-14 15:13:33 +03:00
|
|
|
]
|
|
|
|
++ optionals (cfg.telemetryPath != null) [
|
|
|
|
"--web.telemetry-path ${escapeShellArg cfg.telemetryPath}"
|
|
|
|
]
|
|
|
|
++ optionals (cfg.pidFile != null) [
|
|
|
|
"--pgBouncer.pid-file ${escapeShellArg cfg.pidFile}"
|
|
|
|
]
|
|
|
|
++ optionals (cfg.logLevel != null) [
|
|
|
|
"--log.level ${escapeShellArg cfg.logLevel}"
|
|
|
|
]
|
|
|
|
++ optionals (cfg.logFormat != null) [
|
|
|
|
"--log.format ${escapeShellArg cfg.logFormat}"
|
|
|
|
]
|
|
|
|
++ optionals (cfg.webSystemdSocket != false) [
|
|
|
|
"--web.systemd-socket ${escapeShellArg cfg.webSystemdSocket}"
|
|
|
|
]
|
|
|
|
++ optionals (cfg.webConfigFile != null) [
|
|
|
|
"--web.config.file ${escapeShellArg cfg.webConfigFile}"
|
|
|
|
]
|
|
|
|
++ cfg.extraFlags
|
|
|
|
);
|
2024-12-10 20:29:24 +01:00
|
|
|
|
2024-05-14 15:13:33 +03:00
|
|
|
serviceConfig.RestrictAddressFamilies = [
|
|
|
|
"AF_INET"
|
|
|
|
"AF_INET6"
|
|
|
|
"AF_UNIX"
|
|
|
|
];
|
2024-09-05 12:09:05 +02:00
|
|
|
serviceConfig.EnvironmentFile = lib.mkIf (cfg.connectionEnvFile != null) [
|
|
|
|
cfg.connectionEnvFile
|
|
|
|
];
|
2023-06-30 19:03:12 +02:00
|
|
|
};
|
2024-09-05 12:09:05 +02:00
|
|
|
|
|
|
|
imports = [
|
|
|
|
(lib.mkRemovedOptionModule [ "connectionStringFile" ] ''
|
|
|
|
As replacement, the option `services.prometheus.exporters.pgbouncer.connectionEnvFile`
|
|
|
|
has been added. In contrast to `connectionStringFile` it must be an environment file
|
|
|
|
with the connection string being set to `PGBOUNCER_EXPORTER_CONNECTION_STRING`.
|
|
|
|
|
|
|
|
The change was necessary since the former option wrote the contents of the file
|
|
|
|
into the cmdline of the exporter making the connection string effectively
|
|
|
|
world-readable.
|
|
|
|
'')
|
|
|
|
({
|
|
|
|
options.warnings = options.warnings;
|
|
|
|
options.assertions = options.assertions;
|
|
|
|
})
|
|
|
|
];
|
2023-06-30 19:03:12 +02:00
|
|
|
}
|