2024-06-10 02:58:07 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
utils,
|
|
|
|
...
|
2024-02-09 02:08:02 +01:00
|
|
|
}:
|
2021-08-12 03:30:27 -04:00
|
|
|
|
2024-02-09 02:08:02 +01:00
|
|
|
let
|
|
|
|
inherit (lib)
|
2024-06-10 02:58:07 +02:00
|
|
|
getExe
|
2024-02-09 02:08:02 +01:00
|
|
|
mkOption
|
|
|
|
optionals
|
|
|
|
types
|
2024-06-10 02:58:07 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
inherit (utils) escapeSystemdExecArgs;
|
2021-08-12 03:30:27 -04:00
|
|
|
|
2024-02-09 02:08:02 +01:00
|
|
|
cfg = config.services.prometheus.exporters.fastly;
|
2021-08-12 03:30:27 -04:00
|
|
|
in
|
|
|
|
{
|
|
|
|
port = 9118;
|
2024-02-09 02:08:02 +01:00
|
|
|
extraOpts = with types; {
|
2021-08-12 03:30:27 -04:00
|
|
|
configFile = mkOption {
|
2024-02-09 02:08:02 +01:00
|
|
|
type = nullOr path;
|
2021-08-12 03:30:27 -04:00
|
|
|
default = null;
|
2024-02-09 02:08:02 +01:00
|
|
|
example = "./fastly-exporter-config.txt";
|
|
|
|
description = ''
|
2021-08-12 03:30:27 -04:00
|
|
|
Path to a fastly-exporter configuration file.
|
|
|
|
Example one can be generated with `fastly-exporter --config-file-example`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
tokenPath = mkOption {
|
2024-02-09 02:08:02 +01:00
|
|
|
type = path;
|
|
|
|
description = ''
|
2021-08-12 03:30:27 -04:00
|
|
|
A run-time path to the token file, which is supposed to be provisioned
|
|
|
|
outside of Nix store.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
serviceOpts = {
|
2024-02-09 02:08:02 +01:00
|
|
|
serviceConfig = {
|
|
|
|
LoadCredential = "fastly-api-token:${cfg.tokenPath}";
|
2024-06-10 02:58:07 +02:00
|
|
|
Environment = [ "FASTLY_API_TOKEN=%d/fastly-api-token" ];
|
|
|
|
ExecStart = escapeSystemdExecArgs (
|
|
|
|
[
|
|
|
|
(getExe pkgs.prometheus-fastly-exporter)
|
|
|
|
"-listen"
|
|
|
|
"${cfg.listenAddress}:${toString cfg.port}"
|
|
|
|
]
|
|
|
|
++ optionals (cfg.configFile != null) [
|
|
|
|
"--config-file"
|
|
|
|
cfg.configFile
|
|
|
|
]
|
|
|
|
++ cfg.extraFlags
|
|
|
|
);
|
2024-02-09 02:08:02 +01:00
|
|
|
};
|
2021-08-12 03:30:27 -04:00
|
|
|
};
|
|
|
|
}
|