2024-03-21 05:26:03 +01:00
|
|
|
{
|
|
|
|
|
config,
|
|
|
|
|
lib,
|
|
|
|
|
pkgs,
|
|
|
|
|
options,
|
|
|
|
|
...
|
|
|
|
|
}:
|
2023-11-22 09:42:27 +08:00
|
|
|
|
|
|
|
|
let
|
|
|
|
|
cfg = config.services.prometheus.exporters.mongodb;
|
2024-04-24 14:41:17 -04:00
|
|
|
inherit (lib)
|
|
|
|
|
mkOption
|
|
|
|
|
types
|
|
|
|
|
optionalString
|
|
|
|
|
getExe
|
|
|
|
|
length
|
|
|
|
|
concatStringsSep
|
|
|
|
|
concatMapStringsSep
|
|
|
|
|
escapeShellArgs
|
|
|
|
|
;
|
2023-11-22 09:42:27 +08:00
|
|
|
in
|
|
|
|
|
{
|
|
|
|
|
port = 9216;
|
|
|
|
|
extraOpts = {
|
|
|
|
|
uri = mkOption {
|
|
|
|
|
type = types.str;
|
|
|
|
|
default = "mongodb://localhost:27017/test";
|
|
|
|
|
example = "mongodb://localhost:27017/test";
|
|
|
|
|
description = "MongoDB URI to connect to.";
|
|
|
|
|
};
|
|
|
|
|
collStats = mkOption {
|
|
|
|
|
type = types.listOf types.str;
|
|
|
|
|
default = [ ];
|
|
|
|
|
example = [
|
|
|
|
|
"db1.coll1"
|
|
|
|
|
"db2"
|
|
|
|
|
];
|
|
|
|
|
description = ''
|
|
|
|
|
List of comma separared databases.collections to get $collStats
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
indexStats = mkOption {
|
|
|
|
|
type = types.listOf types.str;
|
|
|
|
|
default = [ ];
|
|
|
|
|
example = [
|
|
|
|
|
"db1.coll1"
|
|
|
|
|
"db2"
|
|
|
|
|
];
|
|
|
|
|
description = ''
|
|
|
|
|
List of comma separared databases.collections to get $indexStats
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
collector = mkOption {
|
|
|
|
|
type = types.listOf types.str;
|
|
|
|
|
default = [ ];
|
|
|
|
|
example = [
|
|
|
|
|
"diagnosticdata"
|
|
|
|
|
"replicasetstatus"
|
|
|
|
|
"dbstats"
|
|
|
|
|
"topmetrics"
|
|
|
|
|
"currentopmetrics"
|
|
|
|
|
"indexstats"
|
|
|
|
|
"dbstats"
|
|
|
|
|
"profile"
|
|
|
|
|
];
|
|
|
|
|
description = "Enabled collectors";
|
|
|
|
|
};
|
|
|
|
|
collectAll = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = false;
|
|
|
|
|
description = ''
|
|
|
|
|
Enable all collectors. Same as specifying all --collector.<name>
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
telemetryPath = mkOption {
|
|
|
|
|
type = types.str;
|
|
|
|
|
default = "/metrics";
|
|
|
|
|
example = "/metrics";
|
|
|
|
|
description = "Metrics expose path";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
serviceOpts = {
|
|
|
|
|
serviceConfig = {
|
|
|
|
|
RuntimeDirectory = "prometheus-mongodb-exporter";
|
|
|
|
|
ExecStart = ''
|
|
|
|
|
${getExe pkgs.prometheus-mongodb-exporter} \
|
2023-12-03 17:54:21 +08:00
|
|
|
--mongodb.uri="${cfg.uri}" \
|
2023-11-22 09:42:27 +08:00
|
|
|
${
|
|
|
|
|
if cfg.collectAll then
|
|
|
|
|
"--collect-all"
|
|
|
|
|
else
|
|
|
|
|
concatMapStringsSep " " (x: "--collect.${x}") cfg.collector
|
2023-12-03 17:54:21 +08:00
|
|
|
} \
|
|
|
|
|
${
|
|
|
|
|
optionalString (
|
|
|
|
|
length cfg.collStats > 0
|
|
|
|
|
) "--mongodb.collstats-colls=${concatStringsSep "," cfg.collStats}"
|
|
|
|
|
} \
|
|
|
|
|
${
|
|
|
|
|
optionalString (
|
|
|
|
|
length cfg.indexStats > 0
|
|
|
|
|
) "--mongodb.indexstats-colls=${concatStringsSep "," cfg.indexStats}"
|
2024-12-10 20:26:33 +01:00
|
|
|
} \
|
2023-12-03 17:54:21 +08:00
|
|
|
--web.listen-address="${cfg.listenAddress}:${toString cfg.port}" \
|
|
|
|
|
--web.telemetry-path="${cfg.telemetryPath}" \
|
2023-11-22 09:42:27 +08:00
|
|
|
${escapeShellArgs cfg.extraFlags}
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
}
|